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


Python AuthenticatorView.verify方法代码示例

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


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

示例1: VerifyTests

# 需要导入模块: from plone.protect.authenticator import AuthenticatorView [as 别名]
# 或者: from plone.protect.authenticator.AuthenticatorView import verify [as 别名]
class VerifyTests(KeyringTestCase):

    key_size = 2

    def setUp(self):
        self.request = MockRequest()
        super(VerifyTests, self).setUp()
        self.view = AuthenticatorView(None, self.request)

    def setAuthenticator(self, key, extra='', name="_authenticator"):
        user = getSecurityManager().getUser().getUserName()
        if six.PY3:
            user = user.encode('utf-8')
            extra = extra.encode('utf-8')
        auth = hmac.new(key.encode('utf-8'), user + extra, sha).hexdigest()
        self.request[name] = auth

    def testCorrectAuthenticator(self):
        self.manager['_forms'].data[0] = "secret"
        self.setAuthenticator("secret")
        self.assertEqual(self.view.verify(), True)

    def testCustomAuthenticatorKeyName(self):
        self.manager['_forms'].data[0] = "secret"
        self.setAuthenticator("secret", name="_my_authenticator")
        self.assertEqual(self.view.verify(name="_my_authenticator"), True)

    def testOlderSecretVerifies(self):
        self.manager['_forms'].data[1] = "backup"
        self.setAuthenticator("backup")
        self.assertEqual(self.view.verify(), True)

    def testMissingAuthenticator(self):
        self.assertEqual(self.view.verify(), False)

    def testIncorrectAuthenticator(self):
        self.request["_authenticator"] = "incorrect"
        self.assertEqual(self.view.verify(), False)

    def testAuthenticatorWrongType(self):
        self.request["_authenticator"] = 123
        self.assertEqual(self.view.verify(), False)

    def testExtraArgumentCanBeVerified(self):
        self.manager['_forms'].data[0] = "secret"
        self.setAuthenticator("secret", 'some-extra-value')
        self.assertEqual(self.view.verify('some-extra-value'), True)
开发者ID:plone,项目名称:plone.protect,代码行数:49,代码来源:testAuthenticator.py

示例2: VerifyTests

# 需要导入模块: from plone.protect.authenticator import AuthenticatorView [as 别名]
# 或者: from plone.protect.authenticator.AuthenticatorView import verify [as 别名]
class VerifyTests(KeyringTestCase):

    def setUp(self):
        self.request = MockRequest()
        KeyringTestCase.setUp(self)
        self.view = AuthenticatorView(None, self.request)

    def setAuthenticator(self, key, extra='', name="_authenticator"):
        user = getSecurityManager().getUser().getUserName()
        auth = hmac.new(key, user + extra, sha).hexdigest()
        self.request[name] = auth

    def testCorrectAuthenticator(self):
        self.manager.keys[0] = ("secret")
        self.setAuthenticator("secret")
        self.assertEqual(self.view.verify(), True)

    def testCustomAuthenticatorKeyName(self):
        self.manager.keys[0] = ("secret")
        self.setAuthenticator("secret", name="_my_authenticator")
        self.assertEqual(self.view.verify(name="_my_authenticator"), True)

    def testOlderSecretVerifies(self):
        self.manager.keys[3] = "backup"
        self.setAuthenticator("backup")
        self.assertEqual(self.view.verify(), True)

    def testMissingAuthenticator(self):
        self.assertEqual(self.view.verify(), False)

    def testIncorrectAuthenticator(self):
        self.request["_authenticator"] = "incorrect"
        self.assertEqual(self.view.verify(), False)

    def testAuthenticatorWrongType(self):
        self.request["_authenticator"] = 123
        self.assertEqual(self.view.verify(), False)

    def testExtraArgumentCanBeVerified(self):
        self.manager.keys[0] = ("secret")
        self.setAuthenticator("secret", 'some-extra-value')
        self.assertEqual(self.view.verify('some-extra-value'), True)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:44,代码来源:testAuthenticator.py


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