Beispiel #1
0
def test_cli__encrypt_decrypt_directory_flow(tmpdir, cmk_arn):
    plaintext = tmpdir.mkdir('plaintext')
    ciphertext = tmpdir.mkdir('ciphertext')
    decrypted = tmpdir.mkdir('decrypted')

    secrets_file_one = plaintext.join('secrets-1.txt')
    secrets_file_one.write_binary(SECRET)
    encrypted_file_one = ciphertext.join('secrets-1.txt.encrypted')
    decrypted_file_one = decrypted.join('secrets-1.txt.encrypted.decrypted')

    secrets_file_two = plaintext.join('secrets-2.txt')
    secrets_file_two.write_binary(SECRET)
    encrypted_file_two = ciphertext.join('secrets-2.txt.encrypted')
    decrypted_file_two = decrypted.join('secrets-2.txt.encrypted.decrypted')

    encrypt_args = ENCRYPT_TEMPLATE.format(outfile=str(ciphertext),
                                           arn=cmk_arn,
                                           input=str(plaintext))
    decrypt_args = DECRYPT_TEMPLATE.format(outfile=str(decrypted),
                                           input=str(ciphertext))

    encrypt_results = parser.parse(
        shlex.split(encrypt_args, posix=not is_windows()))
    assert encrypt_results is None
    assert encrypted_file_one.isfile()
    assert encrypted_file_two.isfile()

    decrypt_results = parser.parse(
        shlex.split(decrypt_args, posix=not is_windows()))
    assert decrypt_results is None

    assert decrypted_file_one.read_binary() == SECRET
    assert decrypted_file_two.read_binary() == SECRET
Beispiel #2
0
def test_cli__encrypt_decrypt_flow(setup_files_tuple, cmk_arn):
    secrets_file, encrypted_file, decrypted_file = setup_files_tuple

    encrypt_args = ENCRYPT_TEMPLATE.format(outfile=str(encrypted_file),
                                           arn=cmk_arn,
                                           input=str(secrets_file))
    decrypt_args = DECRYPT_TEMPLATE.format(input=str(encrypted_file),
                                           outfile=str(decrypted_file))

    encrypt_result = parser.parse(
        shlex.split(encrypt_args, posix=not is_windows()))
    assert encrypt_result is None
    decrypt_result = parser.parse(
        shlex.split(decrypt_args, posix=not is_windows()))
    assert decrypt_result is None

    assert decrypted_file.read_binary() == SECRET
Beispiel #3
0
def test_cli__encrypt__stdin_decrypt_flow(setup_files_tuple, cmk_arn):
    _, encrypted_file, decrypted_file = setup_files_tuple

    encrypt_args = 'mrcrypt ' + ENCRYPT_TEMPLATE.format(
        outfile=str(encrypted_file), arn=cmk_arn, input='-')
    decrypt_args = DECRYPT_TEMPLATE.format(outfile=str(decrypted_file),
                                           input=str(encrypted_file))

    proc = Popen(shlex.split(encrypt_args, posix=not is_windows()),
                 stdout=PIPE,
                 stdin=PIPE,
                 stderr=PIPE)
    _stdout, stderr = proc.communicate(input=SECRET)
    assert not stderr

    decrypt_results = parser.parse(
        shlex.split(decrypt_args, posix=not is_windows()))
    assert decrypt_results is None
    assert decrypted_file.read_binary() == SECRET
Beispiel #4
0
def test_cli__encrypt__stdin_no_output(cmk_arn):
    encrypt_args = 'encrypt {} -'.format(cmk_arn)
    encrypt_result = parser.parse(
        shlex.split(encrypt_args, posix=not is_windows()))
    assert encrypt_result == 'Destination may not be a directory when source is stdin'
Beispiel #5
0
def main():
    from mrcrypt.cli import parser
    parser.parse()
Beispiel #6
0
def test_unexpected_error(patch_setup_logger):
    patch_setup_logger.side_effect = Exception('Unknown Error!')
    test = parser.parse(shlex.split('--outfile - decrypt -'))
    assert test.startswith(
        'Encountered unexpected error: increase verbosity to see details.')
Beispiel #7
0
def test_no_command_selected_py3():
    test = parser.parse([])
    assert test.startswith('usage: ')
Beispiel #8
0
def test_invalid_encryption_context(value):
    test = parser.parse(
        shlex.split(
            'encrypt --encryption_context \'{}\' key_id input_filename'.format(
                value)))
    assert test == 'Invalid dictionary in encryption context argument'