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)
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)
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()
def test_ex1(): f = JSONTokenFile(token=securid.Token(serial=t1.serial, exp_date=t1.exp_date)) f.export_token()