Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
 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')
Ejemplo n.º 3
0
 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')
Ejemplo n.º 4
0
    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)))
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
 def test_special_authenticator(self):
     self.assertDictEqual(urls_dict(winauth.get_authenticators()),
                          urls_dict({'auth_1': winauth.MyTOTP('Auth 1', *SPECIAL_SECRET_DATA)}))
Ejemplo n.º 8
0
 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)}))