Add input type check

zaqar raises 500 erro when create message with integer format body.
Because that json.loads() doesn't check the "integer like" string.

Change-Id: Icafa829fa5f5ce3afcafc40f46c39ea8adcc836d
Cloese-bug: 1731170
This commit is contained in:
wangxiyuan 2017-11-09 16:03:03 +08:00
parent 696933ab76
commit bf6d42b2e9
2 changed files with 5 additions and 2 deletions

View File

@ -325,7 +325,7 @@ class TestMessagesMongoDB(base.V2Base):
self.assertEqual(falcon.HTTP_400, self.srmock.status)
@ddt.data(None, '[', '[]', '{}', '.')
@ddt.data(None, '[', '[]', '{}', '.', '123')
def test_post_bad_message(self, document):
self.simulate_post(self.queue_path + '/messages',
body=document,

View File

@ -45,7 +45,10 @@ def read_json(stream, len):
"""
try:
content = encodeutils.safe_decode(stream.read(len), 'utf-8')
return json.loads(content, parse_int=_json_int)
result = json.loads(content, parse_int=_json_int)
if not isinstance(result, dict) and not isinstance(result, list):
raise MalformedJSON()
return result
except UnicodeDecodeError as ex:
raise MalformedJSON(ex)
except ValueError as ex: