Unverified Commit 6e0fe683 authored by Damian Johnson's avatar Damian Johnson Committed by Philipp Winter
Browse files

Fix crypto tests

This corrects the following...

  Traceback (most recent call last):
    File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_crypto.py", line 226, in test_crypto_initializeGnuPG_nonexistent_default_key
      gpg, signfunc = crypto.initializeGnuPG(self.config)
    File "/home/atagar/Desktop/tor/bridgedb/bridgedb/crypto.py", line 318, in initializeGnuPG
      for sub in list(primaryPK)[0]['subkeys']:
  builtins.IndexError: list index out of range

  Traceback (most recent call last):
    File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_crypto.py", line 218, in test_crypto_initializeGnuPG_signingFunc
      self.assertTrue(sig.startswith('-----BEGIN PGP SIGNED MESSAGE-----'))
  builtins.TypeError: startswith first arg must be bytes or a tuple of bytes, not str

Test results changed as follows...

  before: FAILED (skips=114, failures=21, errors=55, successes=794)
  after:  FAILED (skips=114, failures=21, errors=52, successes=797)
parent 37464528
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -310,12 +310,13 @@ def initializeGnuPG(config):
        logging.warn("No secret keys found in %s!" % gpg.secring)
        return ret

    primarySK = filter(lambda key: key['fingerprint'] == primary, secrets)
    primaryPK = filter(lambda key: key['fingerprint'] == primary, publics)
    primarySK = list(filter(lambda key: key['fingerprint'] == primary, secrets))
    primaryPK = list(filter(lambda key: key['fingerprint'] == primary, publics))

    if primarySK and primaryPK:
        logging.info("Found GnuPG primary key with fingerprint: %s" % primary)
        for sub in list(primaryPK)[0]['subkeys']:

        for sub in primaryPK[0]['subkeys']:
            logging.info("  Subkey: %s  Usage: %s" % (sub[0], sub[1].upper()))
    else:
        logging.warn("GnuPG key %s could not be found in %s!" % (primary, gpg.secring))
+1 −1
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ class InitializeGnuPGTests(unittest.TestCase):
        sig = signfunc("This is a test of the public broadcasting system.")
        print(sig)
        self.assertIsNotNone(sig)
        self.assertTrue(sig.startswith('-----BEGIN PGP SIGNED MESSAGE-----'))
        self.assertTrue(sig.startswith(b'-----BEGIN PGP SIGNED MESSAGE-----'))

    def test_crypto_initializeGnuPG_nonexistent_default_key(self):
        """When the key specified by EMAIL_GPG_PRIMARY_KEY_FINGERPRINT doesn't