def test_decrypt_key_unknown(): with TemporaryDirectory() as tmpdirname: with open(file=path.join(tmpdirname, 'secret.gpg'), mode='bw') as gpg_file: gpg_file.write(b64decode(encrypted_file)) with raises(ValueError): decrypt(path.join(tmpdirname, 'secret.gpg'))
def test_decrypt_file_not_gpg(): with TemporaryDirectory() as tmpdirname: with open(file=path.join(tmpdirname, 'not.gpg'), mode='bw') as gpg_file: gpg_file.write(b'''test''') with raises(ValueError): decrypt(path.join(tmpdirname, 'not.gpg'))
def test_decrypt(): with TemporaryDirectory() as tmpdirname: with open(file=path.join(tmpdirname, 'sec_key.asc'), mode='bw') as asc_file: asc_file.write(b64decode(private_key)) run([ get_binary(), '--homedir', tmpdirname, '--batch', '--passphrase', 'test', '--import', path.join(tmpdirname, 'sec_key.asc') ]) with open(file=path.join(tmpdirname, 'encrypted.gpg'), mode='bw') as encrypted_gpg_file: encrypted_gpg_file.write(b64decode(encrypted_file)) cleartext = decrypt(path_to_file=path.join(tmpdirname, 'encrypted.gpg'), gpg_home=tmpdirname, additional_parameter=[ '--pinentry-mode', 'loopback', '--passphrase', 'test' ]) assert cleartext == 'test'
def test_decrypt_file_is_dir(): with TemporaryDirectory() as tmpdirname: with raises(ValueError): decrypt(path_to_file=tmpdirname)
def test_decrypt_file_not_found(): with TemporaryDirectory() as tmpdirname: with raises(FileNotFoundError): decrypt(path_to_file=path.join(tmpdirname, 'file_that_doesnt_exist.gpg'))