Merge "Make BaseAuthProtocol public"

This commit is contained in:
Jenkins 2015-12-16 07:58:25 +00:00 committed by Gerrit Code Review
commit 1047cececf
3 changed files with 13 additions and 13 deletions

View File

@ -428,7 +428,7 @@ def _get_project_version(project):
return pkg_resources.get_distribution(project).version
class _BaseAuthProtocol(object):
class BaseAuthProtocol(object):
"""A base class for AuthProtocol token checking implementations.
:param Callable app: The next application to call after middleware.
@ -517,7 +517,7 @@ class _BaseAuthProtocol(object):
def _do_fetch_token(self, token):
"""Helper method to fetch a token and convert it into an AccessInfo"""
data = self._fetch_token(token)
data = self.fetch_token(token)
try:
return data, access.create(body=data, auth_token=token)
@ -525,7 +525,7 @@ class _BaseAuthProtocol(object):
self.log.warning(_LW('Invalid token contents.'), exc_info=True)
raise ksm_exceptions.InvalidToken(_('Token authorization failed'))
def _fetch_token(self, token):
def fetch_token(self, token):
"""Fetch the token data based on the value in the header.
Retrieve the data associated with the token value that was in the
@ -613,7 +613,7 @@ class _BaseAuthProtocol(object):
self._invalid_user_token()
class AuthProtocol(_BaseAuthProtocol):
class AuthProtocol(BaseAuthProtocol):
"""Middleware that handles authenticating client calls."""
_SIGNING_CERT_FILE_NAME = 'signing_cert.pem'
@ -817,7 +817,7 @@ class AuthProtocol(_BaseAuthProtocol):
if cached:
return cached
def _fetch_token(self, token):
def fetch_token(self, token):
"""Retrieve a token from either a PKI bundle or the identity server.
:param str token: token id

View File

@ -37,8 +37,8 @@ class AuthTokenFixture(fixtures.Fixture):
_LOG.info('Using Testing AuthTokenFixture...')
self.mockpatch = mock.patch.object(
auth_token.AuthProtocol,
'_fetch_token',
self._fetch_token)
'fetch_token',
self.fetch_token)
self.mockpatch.start()
# Make sure we stop patching when we do the cleanup.
self.addCleanup(self.mockpatch.stop)
@ -76,8 +76,8 @@ class AuthTokenFixture(fixtures.Fixture):
token.add_role(name=role)
self._token_data[token_id] = token
def _fetch_token(self, token):
"""Low level replacement of _fetch_token for AuthProtocol."""
def fetch_token(self, token):
"""Low level replacement of fetch_token for AuthProtocol."""
token_data = self._token_data.get(token, {})
if token_data:
self._assert_token_not_expired(token_data.expires)

View File

@ -30,13 +30,13 @@ class FakeApp(object):
return webob.Response()
class FetchingMiddleware(auth_token._BaseAuthProtocol):
class FetchingMiddleware(auth_token.BaseAuthProtocol):
def __init__(self, app, token_dict={}, **kwargs):
super(FetchingMiddleware, self).__init__(app, **kwargs)
self.token_dict = token_dict
def _fetch_token(self, token):
def fetch_token(self, token):
try:
return self.token_dict[token]
except KeyError:
@ -45,11 +45,11 @@ class FetchingMiddleware(auth_token._BaseAuthProtocol):
class BaseAuthProtocolTests(testtools.TestCase):
@mock.patch.multiple(auth_token._BaseAuthProtocol,
@mock.patch.multiple(auth_token.BaseAuthProtocol,
process_request=mock.DEFAULT,
process_response=mock.DEFAULT)
def test_process_flow(self, process_request, process_response):
m = auth_token._BaseAuthProtocol(FakeApp())
m = auth_token.BaseAuthProtocol(FakeApp())
process_request.return_value = None
process_response.side_effect = lambda x: x