diff options
| -rw-r--r-- | nova/api/auth.py | 7 | ||||
| -rw-r--r-- | nova/tests/api/test_auth.py | 6 |
2 files changed, 12 insertions, 1 deletions
diff --git a/nova/api/auth.py b/nova/api/auth.py index 5191189f2..a118b271e 100644 --- a/nova/api/auth.py +++ b/nova/api/auth.py @@ -99,7 +99,12 @@ class NovaKeystoneContext(wsgi.Middleware): service_catalog = None if req.headers.get('X_SERVICE_CATALOG') is not None: - service_catalog = json.loads(req.headers.get('X_SERVICE_CATALOG')) + try: + catalog_header = req.headers.get('X_SERVICE_CATALOG') + service_catalog = json.loads(catalog_header) + except ValueError: + raise webob.exc.HTTPInternalServerError( + _('Invalid service catalog json.')) ctx = context.RequestContext(user_id, project_id, diff --git a/nova/tests/api/test_auth.py b/nova/tests/api/test_auth.py index e937da541..c77bcfa55 100644 --- a/nova/tests/api/test_auth.py +++ b/nova/tests/api/test_auth.py @@ -58,3 +58,9 @@ class TestNovaKeystoneContextMiddleware(test.TestCase): response = self.request.get_response(self.middleware) self.assertEqual(response.status, '200 OK') self.assertEqual(self.context.user_id, 'testuserid') + + def test_invalid_service_catalog(self): + self.request.headers['X_USER'] = 'testuser' + self.request.headers['X_SERVICE_CATALOG'] = "bad json" + response = self.request.get_response(self.middleware) + self.assertEqual(response.status, '500 Internal Server Error') |
