[tor-commits] [bridgedb/develop] Assert that crypto keys are bytes

phw at torproject.org phw at torproject.org
Wed Feb 19 18:27:18 UTC 2020


commit 28b3fb3d396c31fe905bd5881f2dfff1fa9d12f6
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Jan 20 18:18:20 2020 -0800

    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)
---
 bridgedb/test/test_captcha.py | 10 +++++-----
 bridgedb/test/test_crypto.py  | 12 ++++++------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/bridgedb/test/test_captcha.py b/bridgedb/test/test_captcha.py
index cc0c99c..d504761 100644
--- a/bridgedb/test/test_captcha.py
+++ b/bridgedb/test/test_captcha.py
@@ -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."""
diff --git a/bridgedb/test/test_crypto.py b/bridgedb/test/test_crypto.py
index 9911686..45c06ae 100644
--- a/bridgedb/test/test_crypto.py
+++ b/bridgedb/test/test_crypto.py
@@ -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





More information about the tor-commits mailing list