From 54cba09855fd366875391cbd25c3b3c346ff7a1b Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Thu, 10 Dec 2015 17:20:28 +1100 Subject: [PATCH] Make BaseAuthProtocol public BaseAuthProtocol is the basic validation middleware logic without all the extra hacks, caching, CONF handling etc that has built up around auth_token middleware. It is the basic class that should be reusable with keystone and any newer implementations of middleware. It was private whilst the interfaces stabilized however it has not cheanged in recent releases and should now be available for use. Change-Id: I1e935f5736847941b11495ae086694092baf8b3f --- keystonemiddleware/auth_token/__init__.py | 10 +++++----- keystonemiddleware/fixture.py | 8 ++++---- .../tests/unit/auth_token/test_base_middleware.py | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/keystonemiddleware/auth_token/__init__.py b/keystonemiddleware/auth_token/__init__.py index 3dd746e7..e3e17956 100644 --- a/keystonemiddleware/auth_token/__init__.py +++ b/keystonemiddleware/auth_token/__init__.py @@ -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' @@ -814,7 +814,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 diff --git a/keystonemiddleware/fixture.py b/keystonemiddleware/fixture.py index 7f106a5f..b7d16152 100644 --- a/keystonemiddleware/fixture.py +++ b/keystonemiddleware/fixture.py @@ -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) diff --git a/keystonemiddleware/tests/unit/auth_token/test_base_middleware.py b/keystonemiddleware/tests/unit/auth_token/test_base_middleware.py index 8a791b63..c8aa7422 100644 --- a/keystonemiddleware/tests/unit/auth_token/test_base_middleware.py +++ b/keystonemiddleware/tests/unit/auth_token/test_base_middleware.py @@ -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