diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2016-05-27 01:27:22 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2016-06-14 06:45:44 +0200 |
commit | 38bb3393e15d7d45382624c77cd1a3ad05d36aba (patch) | |
tree | 4ad097ca05614a096668019e56152cf7b73904ff /tests/test_authcookie.py | |
parent | 8bbd0ece4a34b3067aeef680aca07794c747375e (diff) | |
download | m2crypto-38bb3393e15d7d45382624c77cd1a3ad05d36aba.tar.gz |
M2Crypto/AuthCookie.py: Add PEP-484 type hints in comments.
Diffstat (limited to 'tests/test_authcookie.py')
-rw-r--r-- | tests/test_authcookie.py | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/tests/test_authcookie.py b/tests/test_authcookie.py index 5e89add..260dced 100644 --- a/tests/test_authcookie.py +++ b/tests/test_authcookie.py @@ -4,14 +4,19 @@ Copyright (c) 1999-2002 Ng Pheng Siong. All rights reserved.""" -import Cookie, binascii, time +import logging +import time try: import unittest2 as unittest except ImportError: import unittest +from M2Crypto import EVP, Rand, util from M2Crypto.AuthCookie import AuthCookie, AuthCookieJar, mix, unmix, unmix3 -from M2Crypto import Rand, EVP +from M2Crypto.six.moves.http_cookies import SimpleCookie + +log = logging.getLogger(__name__) + class AuthCookieTestCase(unittest.TestCase): @@ -39,7 +44,8 @@ class AuthCookieTestCase(unittest.TestCase): self.assertEqual(c.data(), self.data) # Peek inside the cookie jar... key = self.jar._key - mac = binascii.b2a_base64(EVP.hmac(key, mix(self.exp, self.data), 'sha1'))[:-1] + mac = util.bin_to_hex( + EVP.hmac(key, util.py3bytes(mix(self.exp, self.data)), 'sha1')) self.assertEqual(c.mac(), mac) # Ok, stop peeking now. cookie_str = self._format % (repr(self.exp), self.data, mac) @@ -80,13 +86,14 @@ class AuthCookieTestCase(unittest.TestCase): def test_mix_unmix3(self): c = self.jar.makeCookie(self.exp, self.data) - s = Cookie.SmartCookie() + s = SimpleCookie() s.load(c.output()) exp, data, digest = unmix3(s[self._token].value) self.assertEqual(data, self.data) self.assertEqual(float(exp), self.exp) key = self.jar._key # Peeking... - mac = binascii.b2a_base64(EVP.hmac(key, mix(self.exp, self.data), 'sha1'))[:-1] + mac = util.bin_to_hex( + EVP.hmac(key, util.py3bytes(mix(self.exp, self.data)), 'sha1')) self.assertEqual(digest, mac) def test_cookie_str(self): @@ -95,47 +102,47 @@ class AuthCookieTestCase(unittest.TestCase): def test_cookie_str2(self): c = self.jar.makeCookie(self.exp, self.data) - s = Cookie.SmartCookie() + s = SimpleCookie() s.load(c.output()) self.assertTrue(self.jar.isGoodCookieString(s.output())) def test_cookie_str_expired(self): t = self.exp - 7200 c = self.jar.makeCookie(t, self.data) - s = Cookie.SmartCookie() + s = SimpleCookie() s.load(c.output()) self.assertFalse(self.jar.isGoodCookieString(s.output())) def test_cookie_str_arbitrary_change(self): c = self.jar.makeCookie(self.exp, self.data) cout = c.output() - str = cout[:32] + 'this is bad' + cout[32:] - s = Cookie.SmartCookie() - s.load(str) + cout_str = cout[:32] + 'this is bad' + cout[32:] + s = SimpleCookie() + s.load(cout_str) self.assertFalse(self.jar.isGoodCookieString(s.output())) def test_cookie_str_changed_exp(self): c = self.jar.makeCookie(self.exp, self.data) cout = c.output() - str = cout[:26] + chr(ord(cout[26]) ^ 1) + cout[27:] - s = Cookie.SmartCookie() - s.load(str) + cout_str = cout[:26] + '2' + cout[27:] + s = SimpleCookie() + s.load(cout_str) self.assertFalse(self.jar.isGoodCookieString(s.output())) def test_cookie_str_changed_data(self): c = self.jar.makeCookie(self.exp, self.data) cout = c.output() - str = cout[:36] + chr(ord(cout[36]) ^ 1) + cout[37:] - s = Cookie.SmartCookie() - s.load(str) + cout_str = cout[:36] + 'X' + cout[37:] + s = SimpleCookie() + s.load(cout_str) self.assertFalse(self.jar.isGoodCookieString(s.output())) def test_cookie_str_changed_mac(self): c = self.jar.makeCookie(self.exp, self.data) cout = c.output() - str = cout[:76] + chr(ord(cout[76]) ^ 1) + cout[77:] - s = Cookie.SmartCookie() - s.load(str) + cout_str = cout[:76] + 'X' + cout[77:] + s = SimpleCookie() + s.load(cout_str) self.assertFalse(self.jar.isGoodCookieString(s.output())) |