summaryrefslogtreecommitdiff
path: root/passlib/tests/test_totp.py
diff options
context:
space:
mode:
Diffstat (limited to 'passlib/tests/test_totp.py')
-rw-r--r--passlib/tests/test_totp.py41
1 files changed, 15 insertions, 26 deletions
diff --git a/passlib/tests/test_totp.py b/passlib/tests/test_totp.py
index 604d2e9..e9c6dd9 100644
--- a/passlib/tests/test_totp.py
+++ b/passlib/tests/test_totp.py
@@ -3,6 +3,7 @@
# imports
#=============================================================================
# core
+from binascii import Error as DecodeError
import datetime
from functools import partial
import logging; log = logging.getLogger(__name__)
@@ -11,7 +12,6 @@ import time as _time
# site
# pkg
from passlib import exc
-from passlib.utils.compat import unicode, u
from passlib.tests.utils import TestCase, time_call
# subject
from passlib import totp as totp_module
@@ -25,16 +25,6 @@ __all__ = [
# helpers
#=============================================================================
-# XXX: python 3 changed what error base64.b16decode() throws, from TypeError to base64.Error().
-# it wasn't until 3.3 that base32decode() also got changed.
-# really should normalize this in the code to a single BinaryDecodeError,
-# predicting this cross-version is getting unmanagable.
-Base32DecodeError = Base16DecodeError = TypeError
-if sys.version_info >= (3,0):
- from binascii import Error as Base16DecodeError
-if sys.version_info >= (3,3):
- from binascii import Error as Base32DecodeError
-
PASS1 = "abcdef"
PASS2 = b"\x00\xFF"
KEY1 = '4AOGGDBBQSYHNTUZ'
@@ -174,7 +164,7 @@ class AppWalletTest(TestCase):
self.assertEqual(wallet._secrets, ref)
# accept unicode
- wallet = AppWallet({u("1"): b"aaa", u("02"): b"bbb", u("C"): b"ccc"})
+ wallet = AppWallet({u"1": b"aaa", u"02": b"bbb", u"C": b"ccc"})
self.assertEqual(wallet._secrets, ref)
# normalize int tags
@@ -192,7 +182,7 @@ class AppWalletTest(TestCase):
self.assertRaises(ValueError, AppWallet, {"ab*$": "aaa"})
# coerce value to bytes
- wallet = AppWallet({"1": u("aaa"), "02": "bbb", "C": b"ccc"})
+ wallet = AppWallet({"1": u"aaa", "02": "bbb", "C": b"ccc"})
self.assertEqual(wallet._secrets, ref)
# forbid invalid value types
@@ -406,7 +396,7 @@ class TotpTest(TestCase):
# setup
#=============================================================================
def setUp(self):
- super(TotpTest, self).setUp()
+ super().setUp()
# clear norm_hash_name() cache so 'unknown hash' warnings get emitted each time
from passlib.crypto.digest import lookup_hash
@@ -629,13 +619,13 @@ class TotpTest(TestCase):
self.assertEqual(TOTP(' 4aog gdbb qsyh ntuz ').key, KEY1_RAW)
# .. w/ invalid char
- self.assertRaises(Base32DecodeError, TOTP, 'ao!ggdbbqsyhntuz')
+ self.assertRaises(DecodeError, TOTP, 'ao!ggdbbqsyhntuz')
# handle hex encoding
self.assertEqual(TOTP('e01c630c2184b076ce99', 'hex').key, KEY1_RAW)
# .. w/ invalid char
- self.assertRaises(Base16DecodeError, TOTP, 'X01c630c2184b076ce99', 'hex')
+ self.assertRaises(DecodeError, TOTP, 'X01c630c2184b076ce99', 'hex')
# handle raw bytes
self.assertEqual(TOTP(KEY1_RAW, "raw").key, KEY1_RAW)
@@ -749,7 +739,7 @@ class TotpTest(TestCase):
otp = self.randotp(digits=7)
# unicode & bytes
- self.assertEqual(otp.normalize_token(u('1234567')), '1234567')
+ self.assertEqual(otp.normalize_token(u'1234567'), '1234567')
self.assertEqual(otp.normalize_token(b'1234567'), '1234567')
# int
@@ -880,7 +870,7 @@ class TotpTest(TestCase):
time = self.randtime()
result = otp.generate(time)
token = result.token
- self.assertIsInstance(token, unicode)
+ self.assertIsInstance(token, str)
start_time = result.counter * 30
# should generate same token for next 29s
@@ -1204,8 +1194,8 @@ class TotpTest(TestCase):
from_source = TOTP.from_source
# uri (unicode)
- otp = from_source(u("otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&"
- "issuer=Example"))
+ otp = from_source(u"otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&"
+ "issuer=Example")
self.assertEqual(otp.key, KEY4_RAW)
# uri (bytes)
@@ -1218,7 +1208,7 @@ class TotpTest(TestCase):
self.assertEqual(otp.key, KEY4_RAW)
# json (unicode)
- otp = from_source(u('{"v": 1, "type": "totp", "key": "JBSWY3DPEHPK3PXP"}'))
+ otp = from_source(u'{"v": 1, "type": "totp", "key": "JBSWY3DPEHPK3PXP"}')
self.assertEqual(otp.key, KEY4_RAW)
# json (bytes)
@@ -1239,7 +1229,7 @@ class TotpTest(TestCase):
self.assertIs(otp2, otp1)
# random string
- self.assertRaises(ValueError, from_source, u("foo"))
+ self.assertRaises(ValueError, from_source, u"foo")
self.assertRaises(ValueError, from_source, b"foo")
#=============================================================================
@@ -1278,8 +1268,8 @@ class TotpTest(TestCase):
self.assertRaises(ValueError, from_uri, "otpauth://totp/Example:alice@google.com?digits=6")
# undecodable secret
- self.assertRaises(Base32DecodeError, from_uri, "otpauth://totp/Example:alice@google.com?"
- "secret=JBSWY3DPEHP@3PXP")
+ self.assertRaises(DecodeError, from_uri, "otpauth://totp/Example:alice@google.com?"
+ "secret=JBSWY3DPEHP@3PXP")
#--------------------------------------------------------------------------------
# label param
@@ -1468,8 +1458,7 @@ class TotpTest(TestCase):
self.assertRaises(ValueError, from_dict, dict(v=1, type="totp"))
# undecodable secret
- self.assertRaises(Base32DecodeError, from_dict,
- dict(v=1, type="totp", key="JBSWY3DPEHP@3PXP"))
+ self.assertRaises(DecodeError, from_dict, dict(v=1, type="totp", key="JBSWY3DPEHP@3PXP"))
#--------------------------------------------------------------------------------
# label & issuer params