本文整理汇总了Python中h.auth.policy.TokenAuthenticationPolicy.unauthenticated_userid方法的典型用法代码示例。如果您正苦于以下问题:Python TokenAuthenticationPolicy.unauthenticated_userid方法的具体用法?Python TokenAuthenticationPolicy.unauthenticated_userid怎么用?Python TokenAuthenticationPolicy.unauthenticated_userid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类h.auth.policy.TokenAuthenticationPolicy
的用法示例。
在下文中一共展示了TokenAuthenticationPolicy.unauthenticated_userid方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unauthenticated_userid_passes_token_to_extractor_functions
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
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)
示例2: test_unauthenticated_userid_returns_userid_from_token
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
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]"
示例3: test_unauthenticated_userid_returns_none_if_token_invalid
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
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
示例4: test_unauthenticated_userid_returns_none_if_token_invalid
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
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
示例5: test_unauthenticated_userid_returns_none_if_neither_token_valid
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
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
示例6: test_unauthenticated_userid_returns_userid_from_jwt_as_fallback
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
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]'
示例7: test_unauthenticated_userid_returns_userid_from_api_token_if_present
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
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]'
示例8: test_unauthenticated_userid_returns_none_for_invalid_query_param_token
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
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
示例9: test_unauthenticated_userid_returns_userid_from_query_params_token
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
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]'
示例10: test_unauthenticated_userid_skips_query_param_for_non_ws_requests
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
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
示例11: test_unauthenticated_userid_is_none_if_no_token
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
def test_unauthenticated_userid_is_none_if_no_token(self, pyramid_request):
policy = TokenAuthenticationPolicy()
assert policy.unauthenticated_userid(pyramid_request) is None
示例12: test_unauthenticated_userid_is_none_if_header_incorrectly_formatted
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
def test_unauthenticated_userid_is_none_if_header_incorrectly_formatted(self, value):
policy = TokenAuthenticationPolicy()
request = DummyRequest(headers={'Authorization': value})
assert policy.unauthenticated_userid(request) is None
示例13: test_unauthenticated_userid_is_none_if_header_missing
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
def test_unauthenticated_userid_is_none_if_header_missing(self):
policy = TokenAuthenticationPolicy()
request = DummyRequest()
assert policy.unauthenticated_userid(request) is None
示例14: test_unauthenticated_userid_is_none_if_header_incorrectly_formatted
# 需要导入模块: from h.auth.policy import TokenAuthenticationPolicy [as 别名]
# 或者: from h.auth.policy.TokenAuthenticationPolicy import unauthenticated_userid [as 别名]
def test_unauthenticated_userid_is_none_if_header_incorrectly_formatted(self, pyramid_request, value):
policy = TokenAuthenticationPolicy()
pyramid_request.headers = {'Authorization': value}
assert policy.unauthenticated_userid(pyramid_request) is None