Merge "Raise HTTP 500 if service catalog is not json."

This commit is contained in:
Jenkins 2012-07-13 23:32:53 +00:00 committed by Gerrit Code Review
commit b97460a62a
2 changed files with 12 additions and 1 deletions

View File

@ -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,

View File

@ -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')