Example #1
0
 def test_invalid_period(self):
     config = self.get_config()
     config['key1'] = {
         'Secret':
         b32encode(unhexlify(
             '3132333435363738393031323334353637383930')).decode('utf-8'),
         'Period':
         '45'
     }
     with self.assertRaises(Exception):
         totp_client.parse_config(config)
Example #2
0
 def test_empty_algorithm(self):
     config = self.get_config()
     config['key1'] = {
         'Secret':
         b32encode(unhexlify(
             '3132333435363738393031323334353637383930')).decode('utf-8'),
         'Algorithm':
         ''
     }
     with self.assertRaises(Exception):
         totp_client.parse_config(config)
Example #3
0
 def test_digits_out_of_range_lower(self):
     config = self.get_config()
     config['key1'] = {
         'Secret':
         b32encode(unhexlify(
             '3132333435363738393031323334353637383930')).decode('utf-8'),
         'Digits':
         '5'
     }
     with self.assertRaises(Exception):
         totp_client.parse_config(config)
Example #4
0
 def test_period_60(self):
     config = self.get_config()
     config['key1'] = {
         'Secret':
         b32encode(unhexlify(
             '3132333435363738393031323334353637383930')).decode('utf-8'),
         'Period':
         '60'
     }
     totps = totp_client.parse_config(config)
     self.assertEqual(60, totps[0][1].period)
Example #5
0
    def test_parse(self):
        totps = totp_client.parse_config(self.config)

        self.assertEqual(1, len(totps))
        self.assertEqual('key1', totps[0][0])

        totp = totps[0][1]

        expected = [(0, '755224'), (1 * 30, '287082'), (2 * 30, '359152'),
                    (3 * 30, '969429'), (4 * 30, '338314'), (5 * 30, '254676'),
                    (6 * 30, '287922'), (7 * 30, '162583'), (8 * 30, '399871'),
                    (9 * 30, '520489')]

        for i, v in expected:
            self.assertEqual(
                v,
                totp.at(i)[0],
                msg='Failed otp comparison with i={}, code={}'.format(i, v))
Example #6
0
    def test_parse(self):

        totps = totp_client.parse_config(self.config)
        self.assertEqual(3, len(totps))

        totp_map = {}
        for key_name, totp in totps:
            totp_map[key_name] = totp

        expected = {
            59: [('key1', '94287082'), ('key256', '46119246'),
                 ('key512', '90693936')],
            1111111109: [('key1', '07081804'), ('key256', '68084774'),
                         ('key512', '25091201')],
            1111111111: [('key1', '14050471'), ('key256', '67062674'),
                         ('key512', '99943326')],
            1234567890: [('key1', '89005924'), ('key256', '91819424'),
                         ('key512', '93441116')],
            2000000000: [('key1', '69279037'), ('key256', '90698825'),
                         ('key512', '38618901')],
            20000000000: [('key1', '65353130'), ('key256', '77737706'),
                          ('key512', '47863826')]
        }

        for t, v in expected.items():
            for key_name, code in v:
                otp_test, remaining_test, t_test = totp_map[key_name].at(t)
                self.assertEqual(
                    code,
                    otp_test,
                    msg='Failed otp comparison with t={}, key name={}, code={}'
                    .format(t, key_name, code))
                self.assertEqual(
                    t,
                    t_test,
                    msg='Failed time comparison with t={}, key name={}, code={}'
                    .format(t, key_name, code))
                self.assertEqual(
                    30 - (t % 30),
                    remaining_test,
                    msg=
                    'Failed remaining time comparison with t={}, key name={}, code={}'
                    .format(t, key_name, code))
Example #7
0
 def test_key_lowercase_spaces(self):
     config = self.get_config()
     config['key1'] = {'Secret': 'abcd efgh ijkl mnop qrst uvwx'}
     totps = totp_client.parse_config(config)
     self.assertEqual(1, len(totps))
Example #8
0
 def test_empty(self):
     config = self.get_config()
     totps = totp_client.parse_config(config)
     self.assertEqual(0, len(totps))
Example #9
0
 def test_bad_secret(self):
     config = self.get_config()
     config['key1'] = {'Secret': '9afu9a0d'}
     with self.assertRaises(Exception):
         totp_client.parse_config(config)
Example #10
0
 def test_missing_secret(self):
     config = self.get_config()
     config['key1'] = {}
     with self.assertRaises(Exception):
         totp_client.parse_config(config)