Key comparison failure in the test with different gpg versions

Issue #57 resolved
Elena Grandi
created an issue

While running the tests under debian sid (using gpg1 as the gpg executable) I've had two tests failures:

======================================================================
FAIL: test_import_and_export (__main__.GPGTestCase)
Test that key import and export works
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_gnupg.py", line 364, in test_import_and_export
    self.assertEqual(0, match, "Keys must match")
AssertionError: Keys must match

======================================================================
FAIL: test_import_only (__main__.GPGTestCase)                         
Test that key import works                                            
----------------------------------------------------------------------
Traceback (most recent call last):                                    
  File "test_gnupg.py", line 391, in test_import_only                 
    self.assertEqual(0, match, "Keys must match")                     
AssertionError: Keys must match

In both cases, this was a false negative caused by a different number of lines at the start of the key; the attached patch fixes the failures by removing all of the start matter via a regex before doing the comparison.

My first idea was just to remove 'Version: .*\s+', but this fails in that case because one of the keys didn't have a Version string.

Would you think that this fix could work?

Comments (7)

  1. Vinay Sajip repo owner

    Could a key file have the BEGIN PGP PUBLIC KEY BLOCK line immediately followed by key data? In which case, wouldn't your code remove the first line of key data? If both keys had no version strings, mightn't the comparison (by removing the first line after that line) end up only comparing parts of the keys?

  2. Elena Grandi reporter

    You're right, it would work if there is at least one white line between the BEGIN PGP PUBLIC KEY BLOCK line and the data, but fail if both keys start right below that line (something which, however, it has in common with the original comparison).

    I don't think I've ever seen a key exported in that way, but I don't know if it is possible.

  3. Log in to comment