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


Python policy.TokenAuthenticationPolicy类代码示例

本文整理汇总了Python中h.auth.policy.TokenAuthenticationPolicy的典型用法代码示例。如果您正苦于以下问题:Python TokenAuthenticationPolicy类的具体用法?Python TokenAuthenticationPolicy怎么用?Python TokenAuthenticationPolicy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_unauthenticated_userid_returns_userid_from_token

    def test_unauthenticated_userid_returns_userid_from_token(self, fake_token, pyramid_request):
        policy = TokenAuthenticationPolicy()
        pyramid_request.auth_token = fake_token

        result = policy.unauthenticated_userid(pyramid_request)

        assert result == "acct:[email protected]"
开发者ID:hypothesis,项目名称:h,代码行数:7,代码来源:policy_test.py

示例2: test_unauthenticated_userid_returns_none_if_token_invalid

    def test_unauthenticated_userid_returns_none_if_token_invalid(self, pyramid_request):
        policy = TokenAuthenticationPolicy()
        token = DummyToken(valid=False)
        pyramid_request.auth_token = token

        result = policy.unauthenticated_userid(pyramid_request)

        assert result is None
开发者ID:hypothesis,项目名称:h,代码行数:8,代码来源:policy_test.py

示例3: test_unauthenticated_userid_returns_none_if_token_invalid

    def test_unauthenticated_userid_returns_none_if_token_invalid(self, pyramid_request, token_service):
        policy = TokenAuthenticationPolicy()
        token_service.validate.return_value = None
        pyramid_request.auth_token = 'abcd123'

        result = policy.unauthenticated_userid(pyramid_request)

        assert result is None
开发者ID:chinmaygghag,项目名称:h,代码行数:8,代码来源:policy_test.py

示例4: test_unauthenticated_userid_returns_userid_from_jwt_as_fallback

    def test_unauthenticated_userid_returns_userid_from_jwt_as_fallback(self, jwt, api_token):
        policy = TokenAuthenticationPolicy()
        api_token.return_value = None
        jwt.return_value = 'acct:[email protected]'
        request = DummyRequest(headers={'Authorization': 'Bearer f00ba12'})

        result = policy.unauthenticated_userid(request)

        assert result == 'acct:[email protected]'
开发者ID:ficolo,项目名称:h,代码行数:9,代码来源:policy_test.py

示例5: test_unauthenticated_userid_returns_userid_from_api_token_if_present

    def test_unauthenticated_userid_returns_userid_from_api_token_if_present(self, jwt, api_token, pyramid_request):
        policy = TokenAuthenticationPolicy()
        api_token.return_value = 'acct:[email protected]'
        jwt.return_value = 'acct:[email protected]'
        pyramid_request.headers = {'Authorization': 'Bearer f00ba12'}

        result = policy.unauthenticated_userid(pyramid_request)

        assert result == 'acct:[email protected]'
开发者ID:djcun95,项目名称:h,代码行数:9,代码来源:policy_test.py

示例6: test_authenticated_userid_uses_callback

    def test_authenticated_userid_uses_callback(self, pyramid_request):
        def callback(userid, request):
            return None
        policy = TokenAuthenticationPolicy(callback=callback)
        pyramid_request.auth_token = 'valid123'

        result = policy.authenticated_userid(pyramid_request)

        assert result is None
开发者ID:chinmaygghag,项目名称:h,代码行数:9,代码来源:policy_test.py

示例7: test_unauthenticated_userid_returns_none_if_neither_token_valid

    def test_unauthenticated_userid_returns_none_if_neither_token_valid(self, jwt, api_token):
        policy = TokenAuthenticationPolicy()
        api_token.return_value = None
        jwt.return_value = None
        request = DummyRequest(headers={'Authorization': 'Bearer f00ba12'})

        result = policy.unauthenticated_userid(request)

        assert result is None
开发者ID:ficolo,项目名称:h,代码行数:9,代码来源:policy_test.py

示例8: test_unauthenticated_userid_passes_token_to_extractor_functions

    def test_unauthenticated_userid_passes_token_to_extractor_functions(self, jwt, api_token):
        policy = TokenAuthenticationPolicy()
        api_token.return_value = None
        jwt.return_value = None
        request = DummyRequest(headers={'Authorization': 'Bearer f00ba12'})

        policy.unauthenticated_userid(request)

        api_token.assert_called_once_with('f00ba12')
        jwt.assert_called_once_with('f00ba12', request)
开发者ID:ficolo,项目名称:h,代码行数:10,代码来源:policy_test.py

示例9: test_effective_principals_uses_callback

    def test_effective_principals_uses_callback(self, fake_token, pyramid_request):
        def callback(userid, request):
            return [userid + ".foo", "group:donkeys"]

        policy = TokenAuthenticationPolicy(callback=callback)
        pyramid_request.auth_token = fake_token

        result = policy.effective_principals(pyramid_request)

        assert set(result) > set(["acct:[email protected]", "acct:[email protected]", "group:donkeys"])
开发者ID:hypothesis,项目名称:h,代码行数:10,代码来源:policy_test.py

示例10: test_unauthenticated_userid_returns_none_for_invalid_query_param_token

    def test_unauthenticated_userid_returns_none_for_invalid_query_param_token(self, pyramid_request):
        """When the path is `/ws` but the token is invalid, it should still return None."""

        policy = TokenAuthenticationPolicy()
        pyramid_request.GET['access_token'] = 'expired'
        pyramid_request.path = '/ws'

        result = policy.unauthenticated_userid(pyramid_request)

        assert result is None
开发者ID:chinmaygghag,项目名称:h,代码行数:10,代码来源:policy_test.py

示例11: test_unauthenticated_userid_returns_userid_from_query_params_token

    def test_unauthenticated_userid_returns_userid_from_query_params_token(self, pyramid_request):
        """When the path is `/ws` then we look into the query string parameters as well."""

        policy = TokenAuthenticationPolicy()
        pyramid_request.GET['access_token'] = 'valid123'
        pyramid_request.path = '/ws'

        result = policy.unauthenticated_userid(pyramid_request)

        assert result == 'acct:[email protected]'
开发者ID:chinmaygghag,项目名称:h,代码行数:10,代码来源:policy_test.py

示例12: test_effective_principals_uses_callback

    def test_effective_principals_uses_callback(self, pyramid_request):
        def callback(userid, request):
            return [userid + '.foo', 'group:donkeys']
        policy = TokenAuthenticationPolicy(callback=callback)
        pyramid_request.auth_token = 'valid123'

        result = policy.effective_principals(pyramid_request)

        assert set(result) > set(['acct:[email protected]',
                                  'acct:[email protected]',
                                  'group:donkeys'])
开发者ID:chinmaygghag,项目名称:h,代码行数:11,代码来源:policy_test.py

示例13: test_authenticated_userid_uses_callback

    def test_authenticated_userid_uses_callback(self, jwt, api_token):
        def callback(userid, request):
            return None
        policy = TokenAuthenticationPolicy(callback=callback)
        api_token.return_value = 'acct:[email protected]'
        jwt.return_value = None
        request = DummyRequest(headers={'Authorization': 'Bearer f00ba12'})

        result = policy.authenticated_userid(request)

        assert result is None
开发者ID:ficolo,项目名称:h,代码行数:11,代码来源:policy_test.py

示例14: test_unauthenticated_userid_skips_query_param_for_non_ws_requests

    def test_unauthenticated_userid_skips_query_param_for_non_ws_requests(self, pyramid_request):
        """
        When we have a valid token in the `access_token` query param, but it's
        not a request to /ws, then we should ignore this access token.
        """

        policy = TokenAuthenticationPolicy()
        pyramid_request.GET['access_token'] = 'valid123'
        pyramid_request.path = '/api'

        result = policy.unauthenticated_userid(pyramid_request)

        assert result is None
开发者ID:chinmaygghag,项目名称:h,代码行数:13,代码来源:policy_test.py

示例15: test_effective_principals_uses_callback

    def test_effective_principals_uses_callback(self, jwt, api_token):
        def callback(userid, request):
            return [userid + '.foo', 'group:donkeys']
        policy = TokenAuthenticationPolicy(callback=callback)
        api_token.return_value = 'acct:[email protected]'
        jwt.return_value = None
        request = DummyRequest(headers={'Authorization': 'Bearer f00ba12'})

        result = policy.effective_principals(request)

        assert set(result) > set(['acct:[email protected]',
                                  'acct:[email protected]',
                                  'group:donkeys'])
开发者ID:ficolo,项目名称:h,代码行数:13,代码来源:policy_test.py


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