Unverified Commit 28b3fb3d authored by Damian Johnson's avatar Damian Johnson Committed by Philipp Winter
Browse files

Assert that crypto keys are bytes

Simple update to these assertions...

  Traceback (most recent call last):
    File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_crypto.py", line 75, in test_getKey_tmpfile
      "key isn't a string! type=%r" % type(key))
    File "/usr/local/lib/python3.5/dist-packages/twisted/trial/_synctest.py", line 649, in assertIsInstance
      instance, classOrTuple, suffix))
  twisted.trial.unittest.FailTest: b'#\x1e\xe1\xef\x93\x1c\xdf\x1c\x81\xdd\x02\xc3\xd1$\x07\xfb\xac\x00qSG\xb1\x84\xd6\xe32N,\xa9\xfe\xc8\xa0' is not an instance of <class 'str'>: key isn't a string! type=<class 'bytes'>

Test results changed as follows...

  before: FAILED (skips=115, failures=9, successes=860)
  after:  FAILED (skips=115, failures=3, successes=866)
parent 8523cae6
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -77,8 +77,8 @@ class ReCaptchaTests(unittest.TestCase):
            reason += "connection.\nThis test failed with: %s" % error
            raise unittest.SkipTest(reason)
        else:
            self.assertIsInstance(self.c.image, str)
            self.assertIsInstance(self.c.challenge, str)
            self.assertIsInstance(self.c.image, bytes)
            self.assertIsInstance(self.c.challenge, bytes)
        finally:
            # Replace the original environment variable if there was one:
            if oldkey:
@@ -146,7 +146,7 @@ class GimpCaptchaTests(unittest.TestCase):
        c = captcha.GimpCaptcha(self.publik, self.sekrit, self.hmacKey,
                                self.cacheDir)
        challenge = c.createChallenge('w00t')
        self.assertIsInstance(challenge, str)
        self.assertIsInstance(challenge, bytes)

    def test_createChallenge_base64(self):
        """createChallenge() return value should be urlsafe base64-encoded."""
@@ -189,8 +189,8 @@ class GimpCaptchaTests(unittest.TestCase):
        c = captcha.GimpCaptcha(self.publik, self.sekrit, self.hmacKey,
                                self.cacheDir)
        image, challenge = c.get()
        self.assertIsInstance(image, str)
        self.assertIsInstance(challenge, str)
        self.assertIsInstance(image, bytes)
        self.assertIsInstance(challenge, bytes)

    def test_get_emptyCacheDir(self):
        """An empty cacheDir should raise GimpCaptchaError."""
+6 −6
Original line number Diff line number Diff line
@@ -64,15 +64,15 @@ class GetKeyTests(unittest.TestCase):
        """Test retrieving the secret_key from an empty file."""
        filename = os.path.join(os.getcwd(), 'sekrit')
        key = crypto.getKey(filename)
        self.failUnlessIsInstance(key, str,
                                  "key isn't a string! type=%r" % type(key))
        self.failUnlessIsInstance(key, bytes,
                                  "key isn't bytes! type=%r" % type(key))

    def test_getKey_tmpfile(self):
        """Test retrieving the secret_key from a new tmpfile."""
        filename = self.mktemp()
        key = crypto.getKey(filename)
        self.failUnlessIsInstance(key, str,
                                  "key isn't a string! type=%r" % type(key))
        self.failUnlessIsInstance(key, bytes,
                                  "key isn't bytes! type=%r" % type(key))

    def test_getKey_keyexists(self):
        """Write the example key to a file and test reading it back."""
@@ -82,8 +82,8 @@ class GetKeyTests(unittest.TestCase):
            fh.flush()

        key = crypto.getKey(filename)
        self.failUnlessIsInstance(key, str,
                                  "key isn't a string! type=%r" % type(key))
        self.failUnlessIsInstance(key, bytes,
                                  "key isn't bytes! type=%r" % type(key))
        self.assertEqual(SEKRIT_KEY, key,
                         """The example key and the one read from file differ!
                         key (in hex): %s