From e90ae547387d39aa96215f47344c7d7816a04c31 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Wed, 18 Mar 2015 05:47:40 +0000 Subject: [PATCH] Add two signature passphrase tests for reproducing Issue #82. --- gnupg/test/test_gnupg.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gnupg/test/test_gnupg.py b/gnupg/test/test_gnupg.py index e8be11a..f2ac931 100755 --- a/gnupg/test/test_gnupg.py +++ b/gnupg/test/test_gnupg.py @@ -626,6 +626,36 @@ class GPGTestCase(unittest.TestCase): passphrase='wrong horse battery staple') self.assertFalse(sig, "Bad passphrase should fail") + def test_signature_string_passphrase_empty_string(self): + """Test that a signing attempt with passphrase='' creates a valid + signature. + + See Issue #82: https://github.com/isislovecruft/python-gnupg/issues/82 + """ + with open(os.path.join(_files, 'test_key_1.sec')) as fh1: + res1 = self.gpg.import_keys(fh1.read()) + key1 = res1.fingerprints[0] + + message = 'abc\ndef\n' + sig = self.gpg.sign(message, default_key=key1, passphrase='') + self.assertTrue(sig) + self.assertTrue(message in str(sig)) + + def test_signature_string_passphrase_None(self): + """Test that a signing attempt with passphrase=None fails creates a + valid signature. + + See Issue #82: https://github.com/isislovecruft/python-gnupg/issues/82 + """ + with open(os.path.join(_files, 'test_key_1.sec')) as fh1: + res1 = self.gpg.import_keys(fh1.read()) + key1 = res1.fingerprints[0] + + message = 'abc\ndef\n' + sig = self.gpg.sign(message, default_key=key1, passphrase=None) + self.assertTrue(sig) + self.assertTrue(message in str(sig)) + def test_signature_file(self): """Test that signing a message file works.""" key = self.generate_key("Leonard Adleman", "rsa.com") @@ -1339,6 +1369,8 @@ suites = { 'parsers': set(['test_parsers_fix_unsafe', 'test_signature_verification_detached', 'test_signature_verification_detached_binary', 'test_signature_file', + 'test_signature_string_passphrase_empty_string', + 'test_signature_string_passphrase_None', 'test_signature_string_bad_passphrase', 'test_signature_string_verification', 'test_signature_string_algorithm_encoding']),