当前位置: 首页>>代码示例>>Python>>正文


Python DaplugTokenClass.update方法代码示例

本文整理汇总了Python中privacyidea.lib.tokens.daplugtoken.DaplugTokenClass.update方法的典型用法代码示例。如果您正苦于以下问题:Python DaplugTokenClass.update方法的具体用法?Python DaplugTokenClass.update怎么用?Python DaplugTokenClass.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在privacyidea.lib.tokens.daplugtoken.DaplugTokenClass的用法示例。


在下文中一共展示了DaplugTokenClass.update方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_19_pin_otp_functions

# 需要导入模块: from privacyidea.lib.tokens.daplugtoken import DaplugTokenClass [as 别名]
# 或者: from privacyidea.lib.tokens.daplugtoken.DaplugTokenClass import update [as 别名]
    def test_19_pin_otp_functions(self):
        db_token = Token.query.filter_by(serial=self.serial1).first()
        db_token.set_pin("test")
        token = DaplugTokenClass(db_token)
        # check OTP according to RFC 4226
        """
                             Truncated
           Count    Hexadecimal    Decimal        HOTP
           0        4c93cf18       1284755224     755224
           1        41397eea       1094287082     287082
           2         82fef30        137359152     359152
           3        66ef7655       1726969429     969429
           4        61c5938a       1640338314     338314
           5        33c083d4        868254676     254676
           6        7256c032       1918287922     287922
           7         4e5b397         82162583     162583
           8        2823443f        673399871     399871
           9        2679dc69        645520489     520489
        """
        token.update({"otpkey": self.otpkey})
        self.assertTrue(db_token.otplen == 6, 6)
        set_prepend_pin()
        res, pin, otp = token.split_pin_pass("test" + _digi2daplug("123456"))
        self.assertTrue(pin == "test", pin)
        self.assertTrue(otp == _digi2daplug("123456"), otp)
        self.assertTrue(token.check_pin(pin), pin)
        check = token.check_otp(_digi2daplug("755224"), counter=0, window=10)
        self.assertTrue(check == 0, check)
        self.assertTrue(token.check_otp(_digi2daplug("287082"), counter=1, window=10) == 1)
        # The 6th counter:
        self.assertTrue(token.check_otp(_digi2daplug("287922"), counter=2, window=10) == 6)
        # The tokenclass itself saves the counter to the database
        self.assertTrue(token.token.count == 7, token.token.count)

        # successful authentication
        res = token.authenticate("test" + _digi2daplug("399871"))
        # This is the OTP value of the counter=8
        self.assertTrue(res == (True, 8, None), res)

        token.set_otp_count(0)
        # get the OTP value for counter 0
        res = token.get_otp()
        self.assertTrue(res[0] == 1, res)
        self.assertTrue(res[1] == -1, res)
        self.assertTrue(res[2] == _digi2daplug("755224"), res)
        res = token.get_multi_otp()
        self.assertTrue(res[0] is False, res)
        token.update({"otpkey": self.otpkey, "otplen": 6})
        token.token.count = 0
        res = token.get_multi_otp(count=5)
        self.assertTrue(res[0], res)
        self.assertTrue(res[1] == "OK", res)
        self.assertTrue(res[2].get("otp").get(1) == _digi2daplug("287082"), res[2])
        self.assertTrue(res[2].get("type") == "daplug", res)

        # do some failing otp checks
        token.token.otplen = "invalid otp counter"
        self.assertRaises(Exception, token.check_otp, _digi2daplug("123456"))
        token.token.otplen = 0
开发者ID:tongwen-it,项目名称:privacyidea,代码行数:61,代码来源:test_lib_tokens_daplug.py

示例2: test_24_challenges

# 需要导入模块: from privacyidea.lib.tokens.daplugtoken import DaplugTokenClass [as 别名]
# 或者: from privacyidea.lib.tokens.daplugtoken.DaplugTokenClass import update [as 别名]
 def test_24_challenges(self):
     db_token = Token.query.filter_by(serial=self.serial1).first()
     token = DaplugTokenClass(db_token)
     token.update({"otpkey": self.otpkey, "otplen": 6})
     token.set_pin("test")
     token.token.count = 0
     token.set_sync_window(10)
     token.set_count_window(5)
     self.assertTrue(token.is_challenge_request("test"))
开发者ID:tongwen-it,项目名称:privacyidea,代码行数:11,代码来源:test_lib_tokens_daplug.py

示例3: test_13_check_otp

# 需要导入模块: from privacyidea.lib.tokens.daplugtoken import DaplugTokenClass [as 别名]
# 或者: from privacyidea.lib.tokens.daplugtoken.DaplugTokenClass import update [as 别名]
 def test_13_check_otp(self):
     db_token = Token.query.filter_by(serial=self.serial1).first()
     token = DaplugTokenClass(db_token)
     token.update({"otpkey": self.otpkey, "pin": "test", "otplen": 6})
     # OTP does not exist
     self.assertTrue(token.check_otp_exist(_digi2daplug("222333")) == -1)
     # OTP does exist
     res = token.check_otp_exist(_digi2daplug("969429"))
     self.assertTrue(res == 3, res)
开发者ID:tongwen-it,项目名称:privacyidea,代码行数:11,代码来源:test_lib_tokens_daplug.py

示例4: test_17_update_token

# 需要导入模块: from privacyidea.lib.tokens.daplugtoken import DaplugTokenClass [as 别名]
# 或者: from privacyidea.lib.tokens.daplugtoken.DaplugTokenClass import update [as 别名]
    def test_17_update_token(self):
        db_token = Token.query.filter_by(serial=self.serial1).first()
        token = DaplugTokenClass(db_token)
        # Failed update: genkey wrong
        self.assertRaises(Exception,
                          token.update,
                          {"description": "new desc",
                           "genkey": "17"})
        # genkey and otpkey used at the same time
        token.update({"otpkey": self.otpkey,
                      "genkey": "1"})
        self.assertTrue(token.token.otplen == 6)

        token.update({"otpkey": self.otpkey,
                      "pin": "654321",
                      "otplen": 6})
        self.assertTrue(token.check_pin("654321"))
        self.assertTrue(token.token.otplen == 6)
        # update hashlib
        token.update({"otpkey": self.otpkey,
                      "hashlib": "sha1"})
        self.assertTrue(token.get_tokeninfo("hashlib") == "sha1",
                        token.get_tokeninfo())

        # save pin encrypted
        token.update({"genkey": 1,
                      "pin": "secret",
                      "encryptpin": "true"})
        # check if the PIN is encrypted
        self.assertTrue(token.token.pin_hash.startswith("@@"),
                        token.token.pin_hash)

        # update token without otpkey raises an error
        self.assertRaises(Exception, token.update, {"description": "test"})
开发者ID:STRML,项目名称:privacyidea,代码行数:36,代码来源:test_lib_tokens_daplug.py

示例5: test_22_autosync

# 需要导入模块: from privacyidea.lib.tokens.daplugtoken import DaplugTokenClass [as 别名]
# 或者: from privacyidea.lib.tokens.daplugtoken.DaplugTokenClass import update [as 别名]
    def test_22_autosync(self):
        db_token = Token.query.filter_by(serial=self.serial1).first()
        token = DaplugTokenClass(db_token)
        set_privacyidea_config("AutoResync", True)
        token.update({"otpkey": self.otpkey,
                      "otplen": 6})
        token.token.count = 0
        token.set_sync_window(10)
        token.set_count_window(5)
        # counter = 8, is out of sync
        r = token.check_otp(anOtpVal=_digi2daplug("399871"))
        self.assertTrue(r == -1, r)
        # counter = 9, will be autosynced.
        r = token.check_otp(anOtpVal=_digi2daplug("520489"))
        self.assertTrue(r == 9, r)

        # Autosync with a gap in the next otp value will fail
        token.token.count = 0
        # Just try some bullshit config value
        set_privacyidea_config("AutoResyncTimeout", "totally not a number")
        # counter = 7, is out of sync
        r = token.check_otp(anOtpVal=_digi2daplug("162583"))
        self.assertTrue(r == -1, r)
        # counter = 9, will NOT _autosync
        r = token.check_otp(anOtpVal=_digi2daplug("520489"))
        self.assertTrue(r == -1, r)

        # Autosync fails, if dueDate is over
        token.token.count = 0
        set_privacyidea_config("AutoResyncTimeout", 0)
        # counter = 8, is out of sync
        r = token.check_otp(anOtpVal=_digi2daplug("399871"))
        self.assertTrue(r == -1, r)
        # counter = 9, is the next value, but duedate is over.
        r = token.check_otp(anOtpVal=_digi2daplug("520489"))
        self.assertTrue(r == -1, r)

        # No _autosync
        set_privacyidea_config("AutoResync", False)
        token.token.count = 0
        # counter = 8, is out of sync
        r = token.check_otp(anOtpVal=_digi2daplug("399871"))
        self.assertTrue(r == -1, r)
        # counter = 9, will not be autosynced
        r = token.check_otp(anOtpVal=_digi2daplug("520489"))
        self.assertTrue(r == -1, r)
开发者ID:STRML,项目名称:privacyidea,代码行数:48,代码来源:test_lib_tokens_daplug.py

示例6: test_23_resync

# 需要导入模块: from privacyidea.lib.tokens.daplugtoken import DaplugTokenClass [as 别名]
# 或者: from privacyidea.lib.tokens.daplugtoken.DaplugTokenClass import update [as 别名]
 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")))
开发者ID:tongwen-it,项目名称:privacyidea,代码行数:22,代码来源:test_lib_tokens_daplug.py


注:本文中的privacyidea.lib.tokens.daplugtoken.DaplugTokenClass.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。