def test_23_resync(self):
     db_token = Token.query.filter_by(serial=self.serial1).first()
     token = DaplugTokenClass(db_token)
     token.update({"otpkey": self.otpkey, "otplen": 6})
     token.token.count = 0
     token.set_sync_window(10)
     token.set_count_window(5)
     # counter = 8: 399871
     # counter = 9: 520489
     # Successful resync
     r = token.resync(_digi2daplug("399871"), _digi2daplug("520489"))
     self.assertTrue(r is True, r)
     # resync fails
     token.token.count = 0
     self.assertFalse(token.resync(_digi2daplug("399871"), _digi2daplug("123456")))
     # resync fails, the two correct OTP values are outside of the sync
     # window
     token.token.count = 0
     token.set_sync_window(5)
     self.assertFalse(token.resync(_digi2daplug("399871"), _digi2daplug("520489")))
 def test_23_resync(self):
     db_token = Token.query.filter_by(serial=self.serial1).first()
     token = DaplugTokenClass(db_token)
     token.update({"otpkey": self.otpkey, "otplen": 6})
     token.token.count = 0
     token.set_sync_window(10)
     token.set_count_window(5)
     # counter = 8: 399871
     # counter = 9: 520489
     # Successful resync
     r = token.resync(_digi2daplug("399871"), _digi2daplug("520489"))
     self.assertTrue(r is True, r)
     # resync fails
     token.token.count = 0
     self.assertFalse(
         token.resync(_digi2daplug("399871"), _digi2daplug("123456")))
     # resync fails, the two correct OTP values are outside of the sync
     # window
     token.token.count = 0
     token.set_sync_window(5)
     self.assertFalse(
         token.resync(_digi2daplug("399871"), _digi2daplug("520489")))
    def test_04_base_methods(self):
        db_token = Token.query.filter_by(serial=self.serial1).first()
        token = DaplugTokenClass(db_token)
        self.assertTrue(token.check_otp(_digi2daplug("123456"), 1, 10) == -1)

        c = token.create_challenge("transactionid")
        self.assertTrue(c[0], c)
        self.assertTrue("transactionid" in c[2], c)

        # set the description
        token.set_description("something new")
        self.assertTrue(token.token.description == "something new",
                        token.token)

        # set defaults
        token.set_defaults()
        self.assertTrue(token.token.otplen == 6)
        self.assertTrue(token.token.sync_window == 1000)

        token.resync(_digi2daplug("1234"), _digi2daplug("3456"))

        token.token.count_window = 17
        self.assertTrue(token.get_otp_count_window() == 17)

        token.token.count = 18
        self.assertTrue(token.get_otp_count() == 18)

        token.token.active = False
        self.assertTrue(token.is_active() is False)

        token.token.failcount = 7
        self.assertTrue(token.get_failcount() == 7)
        token.set_failcount(8)
        self.assertTrue(token.token.failcount == 8)

        token.token.maxfail = 12
        self.assertTrue(token.get_max_failcount() == 12)

        self.assertTrue(token.get_user_id() == token.token.user_id)

        self.assertTrue(token.get_serial() == "SE123456", token.token.serial)
        self.assertTrue(token.get_tokentype() == "daplug",
                        token.token.tokentype)

        token.set_so_pin("sopin")
        token.set_user_pin("userpin")
        token.set_otpkey(self.otpkey)
        token.set_otplen(8)
        token.set_otp_count(1000)
        self.assertTrue(len(token.token.so_pin) == 32,
                        token.token.so_pin)
        self.assertTrue(len(token.token.user_pin) == 32,
                        token.token.user_pin)
        self.assertTrue(len(token.token.key_enc) == 192,
                        token.token.key_enc)
        self.assertTrue(token.get_otplen() == 8)
        self.assertTrue(token.token.count == 1000,
                        token.token.count)

        token.set_maxfail(1000)
        self.assertTrue(token.token.maxfail == 1000)

        token.set_count_window(52)
        self.assertTrue(token.get_count_window() == 52)

        token.set_sync_window(53)
        self.assertTrue(token.get_sync_window() == 53)
    def test_04_base_methods(self):
        db_token = Token.query.filter_by(serial=self.serial1).first()
        token = DaplugTokenClass(db_token)
        self.assertTrue(token.check_otp(_digi2daplug("123456"), 1, 10) == -1)

        c = token.create_challenge("transactionid")
        self.assertTrue(c[0], c)
        self.assertTrue("transactionid" in c[2], c)

        # set the description
        token.set_description("something new")
        self.assertTrue(token.token.description == "something new",
                        token.token)

        # set defaults
        token.set_defaults()
        self.assertTrue(token.token.otplen == 6)
        self.assertTrue(token.token.sync_window == 1000)

        token.resync(_digi2daplug("1234"), _digi2daplug("3456"))

        token.token.count_window = 17
        self.assertTrue(token.get_otp_count_window() == 17)

        token.token.count = 18
        self.assertTrue(token.get_otp_count() == 18)

        token.token.active = False
        self.assertTrue(token.is_active() is False)

        token.token.failcount = 7
        self.assertTrue(token.get_failcount() == 7)
        token.set_failcount(8)
        self.assertTrue(token.token.failcount == 8)

        token.token.maxfail = 12
        self.assertTrue(token.get_max_failcount() == 12)

        self.assertEqual(token.get_user_id(),
                         token.token.owners.first().user_id)

        self.assertTrue(token.get_serial() == "SE123456", token.token.serial)
        self.assertTrue(token.get_tokentype() == "daplug",
                        token.token.tokentype)

        token.set_so_pin("sopin")
        token.set_user_pin("userpin")
        token.set_otpkey(self.otpkey)
        token.set_otplen(8)
        token.set_otp_count(1000)
        self.assertTrue(len(token.token.so_pin) == 32, token.token.so_pin)
        self.assertTrue(len(token.token.user_pin) == 32, token.token.user_pin)
        self.assertTrue(len(token.token.key_enc) == 192, token.token.key_enc)
        self.assertTrue(token.get_otplen() == 8)
        self.assertTrue(token.token.count == 1000, token.token.count)

        token.set_maxfail(1000)
        self.assertTrue(token.token.maxfail == 1000)

        token.set_count_window(52)
        self.assertTrue(token.get_count_window() == 52)

        token.set_sync_window(53)
        self.assertTrue(token.get_sync_window() == 53)