Example #1
0
 def test_00_create_token(self):
     otpkey = "1234567890"
     t1 = Token(serial="serial1",
                otpkey=otpkey,
                tokentype="hmac")
     t1.set_description("myfirsttoken")
     t1.set_hashed_pin("1234")
     t1.otplen = 6
     tid = t1.save()
     
     userpin = "HalloDuda"
     t1.set_user_pin(userpin)
     t1.save()
     
     pin_object = t1.get_user_pin()
     self.assertTrue(pin_object.getPin() == userpin)
     
     t = Token.query.filter_by(id=tid).first()
     self.assertTrue(len(t.pin_hash) > 0)
     self.assertTrue(len(t.user_pin) > 0)
     
     otpObj = t.get_otpkey()
     self.assertTrue(otpObj.getKey() == otpkey)
     count = t.count
     self.assertTrue(count == 0)
     
     up = t.get_user_pin()
     self.assertTrue(up.getPin() == userpin)
     
     self.assertTrue(t.check_hashed_pin("1234"))
     
     # Delete the token
     t1.delete()
     t = Token.query.filter_by(id=tid).first()
     self.assertTrue(t is None)
Example #2
0
 def test_00_create_token(self):
     otpkey = "1234567890"
     t1 = Token(serial="serial1",
                otpkey=otpkey,
                tokentype="hmac")
     t1.set_description("myfirsttoken")
     t1.set_hashed_pin("1234")
     t1.otplen = 6
     tid = t1.save()
     
     userpin = "HalloDuda"
     t1.set_user_pin(userpin)
     t1.save()
     
     pin_object = t1.get_user_pin()
     self.assertTrue(pin_object.getPin() == userpin)
     
     t = Token.query.filter_by(id=tid).first()
     self.assertTrue(len(t.pin_hash) > 0)
     self.assertTrue(len(t.user_pin) > 0)
     
     otpObj = t.get_otpkey()
     self.assertTrue(otpObj.getKey() == otpkey)
     count = t.count
     self.assertTrue(count == 0)
     
     up = t.get_user_pin()
     self.assertTrue(up.getPin() == userpin)
     
     self.assertTrue(t.check_hashed_pin("1234"))
     
     # Delete the token
     t1.delete()
     t = Token.query.filter_by(id=tid).first()
     self.assertTrue(t is None)
Example #3
0
    def test_00_create_token(self):
        otpkey = "1234567890"
        t1 = Token(serial="serial1", otpkey=otpkey, tokentype="hmac")
        t1.set_description("myfirsttoken")
        t1.set_hashed_pin("1234")
        t1.otplen = 6
        tid = t1.save()

        userpin = "HalloDuda"
        t1.set_user_pin(userpin)
        t1.save()

        pin_object = t1.get_user_pin()
        self.assertTrue(pin_object.getPin() == userpin.encode('utf8'))

        t = Token.query.filter_by(id=tid).first()
        self.assertTrue(len(t.pin_hash) > 0)
        self.assertTrue(len(t.user_pin) > 0)

        otpObj = t.get_otpkey()
        self.assertTrue(otpObj.getKey() == otpkey.encode('utf8'))
        count = t.count
        self.assertTrue(count == 0)

        up = t.get_user_pin()
        self.assertTrue(up.getPin() == userpin.encode('utf8'))

        self.assertTrue(t.check_pin("1234"))

        t.set_user_pin(b'HalloDuDa')
        self.assertTrue(t.get_user_pin().getPin() == b'HalloDuDa')

        t.set_user_pin(u'HelloWörld')
        self.assertTrue(
            t.get_user_pin().getPin().decode('utf8') == u'HelloWörld')

        t.set_hashed_pin(b'1234')
        self.assertTrue(t.check_pin(b'1234'))

        t.set_hashed_pin(u'HelloWörld')
        self.assertTrue(t.check_pin(u'HelloWörld'))

        t.pin_hash = None
        self.assertTrue(t.check_pin(''))
        self.assertFalse(t.check_pin(None))
        self.assertFalse(t.check_pin('1234'))

        t.pin_hash = ''
        self.assertTrue(t.check_pin(''))
        self.assertFalse(t.check_pin('1234'))

        t.set_hashed_pin('')
        self.assertTrue(len(t.pin_hash) > 0)
        self.assertTrue(t.check_pin(''))
        self.assertFalse(t.check_pin('1234'))

        # Delete the token
        t1.delete()
        t = Token.query.filter_by(id=tid).first()
        self.assertTrue(t is None)