Fix 500 error if request body is not JSON object

In `JsonBodyMiddleware` we expect POST body to be a JSON dictionary,
and failed with 500 error if body was a valid JSON, but not a
dictionary.  Additional check was added along with a test for described
case.

Change-Id: I08ae3c8fa4eb53b67604d8b8791ca19d9c1682e6
Closes-Bug: #1316657
This commit is contained in:
Roman Bodnarchuk 2014-05-08 06:48:05 -04:00
parent 26fdb88ef2
commit 91b27cc213

View File

@ -131,6 +131,11 @@ class JsonBodyMiddleware(wsgi.Middleware):
if not params_parsed:
params_parsed = {}
if not isinstance(params_parsed, dict):
e = exception.ValidationError(attribute='valid JSON object',
target='request body')
return wsgi.render_exception(e, request=request)
params = {}
for k, v in six.iteritems(params_parsed):
if k in ('self', 'context'):