Use request helpers for token_info/token_auth

There is already a request setter for token_auth that we aren't using
and should be. Also add a setter for token_info rather than set the
environment directly.

This makes it much easier to consume these values later in objects that
subclass BaseAuthProtocol.

Change-Id: I7f4bf2950f783e4dc85a5671def6a02322cd7f8a
This commit is contained in:
Jamie Lennox 2015-09-30 07:57:06 +10:00
parent 4e47c4a8da
commit b453a8f577
3 changed files with 21 additions and 3 deletions

View File

@ -486,7 +486,7 @@ class _BaseAuthProtocol(object):
request.user_token_valid = False
else:
request.user_token_valid = True
request.environ['keystone.token_info'] = data
request.token_info = data
if request.service_token:
self.log.debug('Authenticating service token')
@ -500,8 +500,8 @@ class _BaseAuthProtocol(object):
else:
request.service_token_valid = True
p = _user_plugin.UserAuthPlugin(user_auth_ref, serv_auth_ref)
request.environ['keystone.token_auth'] = p
request.token_auth = _user_plugin.UserAuthPlugin(user_auth_ref,
serv_auth_ref)
def _validate_token(self, auth_ref):
"""Perform the validation steps on the token.

View File

@ -87,6 +87,7 @@ class _AuthTokenRequest(webob.Request):
_SERVICE_CATALOG_HEADER = 'X-Service-Catalog'
_TOKEN_AUTH = 'keystone.token_auth'
_TOKEN_INFO = 'keystone.token_info'
_CONFIRMED = 'Confirmed'
_INVALID = 'Invalid'
@ -222,3 +223,12 @@ class _AuthTokenRequest(webob.Request):
@token_auth.setter
def token_auth(self, v):
self.environ[self._TOKEN_AUTH] = v
@property
def token_info(self):
"""The raw token dictionary retrieved by the middleware"""
return self.environ.get(self._TOKEN_INFO)
@token_info.setter
def token_info(self, v):
self.environ[self._TOKEN_INFO] = v

View File

@ -189,6 +189,14 @@ class RequestObjectTests(utils.TestCase):
self.assertIs(plugin, self.request.environ['keystone.token_auth'])
self.assertIs(plugin, self.request.token_auth)
def test_token_info(self):
info = fixture.V3Token()
self.assertNotIn('keystone.token_info', self.request.environ)
self.request.token_info = info
self.assertIs(info, self.request.environ['keystone.token_info'])
self.assertIs(info, self.request.token_info)
class CatalogConversionTests(utils.TestCase):