Return 400, if the query string is not a dict
When we parse the json object that come in query string, we expect to find a dict, but not bail out if that not the case. So this will raise a 500. This changes this and return 400, because the input is invalid. Change-Id: I1a3b927cdfb3b554026306d65a46ed91635d073c Closes-bug: #1423634
This commit is contained in:
parent
7784cc73b1
commit
1dc4421b4f
@ -274,6 +274,8 @@ def parse(s, datatypes, bodyarg, encoding='utf8'):
|
|||||||
else:
|
else:
|
||||||
kw = {}
|
kw = {}
|
||||||
extra_args = []
|
extra_args = []
|
||||||
|
if not isinstance(jdata, dict):
|
||||||
|
raise wsme.exc.ClientSideError("Request must be a JSON dict")
|
||||||
for key in jdata:
|
for key in jdata:
|
||||||
if key not in datatypes:
|
if key not in datatypes:
|
||||||
extra_args.append(key)
|
extra_args.append(key)
|
||||||
|
@ -339,6 +339,14 @@ class TestRestJson(wsme.tests.protocol.RestOnlyProtocolTestCase):
|
|||||||
j = parse('{"a": "2011-01-01"}', {'a': datetime.date}, False)
|
j = parse('{"a": "2011-01-01"}', {'a': datetime.date}, False)
|
||||||
assert isinstance(j['a'], datetime.date)
|
assert isinstance(j['a'], datetime.date)
|
||||||
|
|
||||||
|
def test_invalid_root_dict_fromjson(self):
|
||||||
|
try:
|
||||||
|
parse('["invalid"]', {'a': ArrayType(str)}, False)
|
||||||
|
assert False
|
||||||
|
except Exception as e:
|
||||||
|
assert isinstance(e, ClientSideError)
|
||||||
|
assert e.msg == "Request must be a JSON dict"
|
||||||
|
|
||||||
def test_invalid_list_fromjson(self):
|
def test_invalid_list_fromjson(self):
|
||||||
jlist = "invalid"
|
jlist = "invalid"
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user