當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。