From 4008e75d2b5a631e0e13875049e26f85da91e750 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Sat, 16 Jan 2016 14:39:44 +1100 Subject: [PATCH] Remove except Exception handler Our except Exception handler catches any passing exception and turns it into a webob 500 error. However the default behaviour of uncaught exceptions is to be rendered as 500 errors with actual debug output so all we are doing is masking useful failure stack traces. Removed the only exception that triggered this case. For offline token validation we really should know all the types of exception that can be raised and handle them. Change-Id: I89d84a60b76c7a7e08e3eb453b1880b064983fbf --- keystonemiddleware/auth_token/__init__.py | 3 --- .../tests/unit/auth_token/test_auth_token_middleware.py | 9 --------- 2 files changed, 12 deletions(-) diff --git a/keystonemiddleware/auth_token/__init__.py b/keystonemiddleware/auth_token/__init__.py index cac5990..0c8e043 100644 --- a/keystonemiddleware/auth_token/__init__.py +++ b/keystonemiddleware/auth_token/__init__.py @@ -844,9 +844,6 @@ class AuthProtocol(BaseAuthProtocol): self._token_cache.store_invalid(token_hashes[0]) self.log.warning(_LW('Authorization failed for token')) raise - except Exception: - self.log.critical(_LC('Unable to validate token'), exc_info=True) - raise webob.exc.HTTPInternalServerError() def _validate_offline(self, token, token_hashes): try: diff --git a/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py b/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py index 51c93fa..ccd5bdb 100644 --- a/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py +++ b/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py @@ -682,15 +682,6 @@ class CommonAuthTokenMiddlewareTest(object): self.call_middleware(headers={'X-Auth-Token': token}, expected_status=503) - def test_unexpected_exception_in_validate_offline(self): - # When an unexpected exception is hit during _validate_offline, - # 500 is returned - token = self.token_dict['uuid_token_default'] - with mock.patch.object(self.middleware, '_validate_offline', - side_effect=Exception): - self.call_middleware(headers={'X-Auth-Token': token}, - expected_status=500) - def test_cached_revoked_uuid(self): # When the UUID token is cached and revoked, 401 is returned. self._test_cache_revoked(self.token_dict['uuid_token_default'])