本文整理汇总了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]"
示例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
示例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
示例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]'
示例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]'
示例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
示例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
示例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)
示例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"])
示例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
示例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]'
示例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'])
示例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
示例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
示例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'])