def test_digest(self): auth = winauth.MyTOTP('test', SECRET_HEX, digest='sha256') self.assertEqual(auth.digest, sha256) digest = 'bad_digest_algo_asdf' with self.assertRaisesRegex(AttributeError, "module 'hashlib' has no attribute '{}'".format(digest)): winauth.MyTOTP('test', SECRET_HEX, digest=digest)
def test_interval(self): auth = winauth.MyTOTP('test', SECRET_HEX, interval=60) self.assertEqual(auth.interval, 60) auth = winauth.MyTOTP('test', SECRET_HEX, interval='60') self.assertEqual(auth.interval, 60) with self.assertRaises(ValueError): winauth.MyTOTP('test', SECRET_HEX, interval='x')
def test_digits(self): auth = winauth.MyTOTP('test', SECRET_HEX, 8) self.assertEqual(auth.digits, 8) auth = winauth.MyTOTP('test', SECRET_HEX, '8') self.assertEqual(auth.digits, 8) with self.assertRaises(ValueError): winauth.MyTOTP('test', SECRET_HEX, 'x')
def test_url(self): self.assertDictEqual(url2dict(winauth.MyTOTP('test34', SECRET_HEX).url()), url2dict('otpauth://totp/test34?secret={}'.format(SECRET_ENCODED))) self.assertDictEqual(url2dict(winauth.MyTOTP('test', SECRET_HEX, digits=8).url()), url2dict('otpauth://totp/test?secret={}&digits=8'.format(SECRET_ENCODED))) self.assertDictEqual(url2dict(winauth.MyTOTP('test', SECRET_HEX, digest='sha256').url()), url2dict('otpauth://totp/test?secret={}&algorithm=SHA256'.format(SECRET_ENCODED))) self.assertDictEqual(url2dict(winauth.MyTOTP('test', SECRET_HEX, interval=32).url()), url2dict('otpauth://totp/test?secret={}&period=32'.format(SECRET_ENCODED))) self.assertDictEqual(url2dict(winauth.MyTOTP('test', SECRET_HEX, 14, 'sha256', 32).url()), url2dict('otpauth://totp/test?secret={}&algorithm=SHA256&digits=14&period=32'.format(SECRET_ENCODED)))
def test_args_order(self): auth = winauth.MyTOTP('test', SECRET_HEX, 14, 'sha256', 32) self.assertEqual(auth.name, 'test') self.assertEqual(auth.byte_secret(), SECRET_BYTES) self.assertEqual(auth.digits, 14) self.assertEqual(auth.digest, sha256) self.assertEqual(auth.interval, 32)
def test_regular(self): auth = winauth.MyTOTP('test', SECRET_HEX) self.assertEqual(auth.name, 'test') self.assertEqual(auth.byte_secret(), SECRET_BYTES) self.assertEqual(auth.digits, 6) self.assertEqual(auth.digest, sha1) self.assertEqual(auth.interval, 30)
def test_special_authenticator(self): self.assertDictEqual(urls_dict(winauth.get_authenticators()), urls_dict({'auth_1': winauth.MyTOTP('Auth 1', *SPECIAL_SECRET_DATA)}))
def test_multiple_valid_authenticators(self): self.assertDictEqual(urls_dict(winauth.get_authenticators()), urls_dict({'auth_1': winauth.MyTOTP('Auth 1', *REGULAR_SECRET_DATA), 'auth_2': winauth.MyTOTP('Auth 2', *REGULAR_SECRET_DATA), 'auth_3': winauth.MyTOTP('Auth 3', *REGULAR_SECRET_DATA)}))