Beispiel #1
0
    def test_export(self):
        t1 = securid.Token().random(exp_date=date(2000, 1, 1))
        f1 = JSONTokenFile(token=t1)
        data = f1.export_token()
        f2 = JSONTokenFile(data=data)
        t2 = f2.get_token()
        self.assertEqual(t1, t2)

        def test_ex1():
            f = JSONTokenFile(
                token=securid.Token(serial=t1.serial, exp_date=t1.exp_date))
            f.export_token()

        self.assertRaises(InvalidSeed, test_ex1)

        def test_ex2():
            f = JSONTokenFile(token=securid.Token(
                serial=t1.serial, seed=t1.seed, exp_date=t1.exp_date))
            f.get_token().serial = None
            f.export_token()

        self.assertRaises(InvalidSerial, test_ex2)

        def test_ex3():
            f = JSONTokenFile(token=securid.Token(
                serial=t1.serial, seed=t1.seed, exp_date=t1.exp_date))
            f.get_token().serial = 'x'
            f.export_token()

        self.assertRaises(InvalidSerial, test_ex3)
Beispiel #2
0
 def test_file(self):
     with NamedTemporaryFile() as f:
         t1 = securid.Token().random(exp_date=date(2000,1,1))
         f1 = JSONTokenFile(token=t1)
         f.write(f1.export_token())
         f.flush()
         f2 = JSONTokenFile(filename=f.name)
         t2 = f2.get_token()
         self.assertEqual(t1, t2)
Beispiel #3
0
 def test_parse(self):
     j = """
     {
         "digits": 6,
         "exp_date": "2099-12-31",
         "period": 60,
         "secret": [185, 175, 88, 111, 163, 93, 249, 121, 123, 142, 90, 135, 236, 223, 13, 137],
         "serial": "125966947139",
         "type": "SecurID"
     }
     """
     f = JSONTokenFile(data=j)
     self.assertEqual(f.get_token().exp_date, date(2099,12,31))
     self.assertEqual(f.get_token().seed, b'\xb9\xafXo\xa3]\xf9y{\x8eZ\x87\xec\xdf\r\x89')
     self.assertEqual(f.get_token().serial, '125966947139')
     self.assertEqual(f.get_token().digits, 6)
     self.assertEqual(f.get_token().interval, 60)
     d = json.loads(j)
     f2 = JSONTokenFile(data=d)
     self.assertEqual(f.get_token(), f2.get_token())
Beispiel #4
0
 def test_file():
     JSONTokenFile(filename=f.name)
Beispiel #5
0
 def test_ex3():
     f = JSONTokenFile(token=securid.Token(serial=t1.serial, seed=t1.seed, exp_date=t1.exp_date))
     f.get_token().serial = 'x'
     f.export_token()
Beispiel #6
0
 def test_ex1():
     f = JSONTokenFile(token=securid.Token(serial=t1.serial, exp_date=t1.exp_date))
     f.export_token()