Add test for #102 based on @doktorstick's example, with armor=False.

This test is currently failing on Python3, meaning that decryption of binary
GnuPG files is broken for Python3.

 * ADD a test to reproduce Issue #102:
   https://github.com/isislovecruft/python-gnupg/issues/102
fix/102-py3k-decrypt-bytes-literal
Isis Lovecruft 2015-03-18 22:45:28 +00:00
parent 76d70c68aa
commit 8738ea47bb
No known key found for this signature in database
GPG Key ID: 18C16EC5F9F1D673
1 changed files with 29 additions and 0 deletions

View File

@ -1105,6 +1105,34 @@ authentication."""
decoded = message.decode(self.gpg._encoding, self.gpg._decode_errors)
self.assertEqual(str(decrypted), decoded)
def test_decryption_noarmor_with_bytes_literal(self):
"""Test that ``decrypt(encrypt(b'foo', armor=False), ...)`` is successful."""
with open(os.path.join(_files, 'kat.sec')) as katsec:
self.gpg.import_keys(katsec.read())
kat = self.gpg.list_keys('kat')[0]['fingerprint']
message_filename = os.path.join(_files, 'cypherpunk_manifesto')
with open(message_filename, 'rb') as f:
kwargs = dict(armor=False)
message = b'Dance like a psycho'
encrypted = self.gpg.encrypt(message, kat, **kwargs)
self.assertTrue(encrypted.ok)
self.assertGreater(len(encrypted.data), 0)
debugfh = os.path.join(os.getcwd(), 'debug-noarmor.gpg')
with open(debugfh, 'wb') as fh:
fh.write(encrypted.data)
fh.flush()
decrypted = self.gpg.decrypt(encrypted.data, passphrase='overalls', armor=False)
print(decrypted.stderr)
self.assertTrue(decrypted.ok)
self.assertGreater(len(decrypted.data), 0)
# Decode the message so that we can easily compare it with the
# decrypted version in both Python2 and Python3:
decoded = message.decode(self.gpg._encoding, self.gpg._decode_errors)
self.assertEqual(str(decrypted), decoded)
def test_encryption_one_hidden_recipient_one_not(self):
"""Test to ensure hidden recipient isn't detailed in packet info"""
@ -1418,6 +1446,7 @@ suites = { 'parsers': set(['test_parsers_fix_unsafe',
'test_encryption_throw_keyids',
'test_decryption',
'test_decryption_with_bytes_literal',
'test_decryption_noarmor_with_bytes_literal',
'test_symmetric_encryption_and_decryption',
'test_file_encryption_and_decryption',
'test_encryption_to_filename',