summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehdi Abaakouk <sileht@sileht.net>2015-08-04 09:48:50 +0200
committerMehdi Abaakouk <sileht@sileht.net>2015-08-07 12:47:18 +0200
commit1dc4421b4faeae2474eb982b7603cb0999e5bae3 (patch)
treeb68b9d1452d55c67abca9b46af2802fc818511a2
parent7784cc73b1905f8038249b071d3c766ef6180b1f (diff)
downloadwsme-1dc4421b4faeae2474eb982b7603cb0999e5bae3.tar.gz
Return 400, if the query string is not a dict0.8.0
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
-rw-r--r--wsme/rest/json.py2
-rw-r--r--wsme/tests/test_restjson.py8
2 files changed, 10 insertions, 0 deletions
diff --git a/wsme/rest/json.py b/wsme/rest/json.py
index 594916c..48bd082 100644
--- a/wsme/rest/json.py
+++ b/wsme/rest/json.py
@@ -274,6 +274,8 @@ def parse(s, datatypes, bodyarg, encoding='utf8'):
else:
kw = {}
extra_args = []
+ if not isinstance(jdata, dict):
+ raise wsme.exc.ClientSideError("Request must be a JSON dict")
for key in jdata:
if key not in datatypes:
extra_args.append(key)
diff --git a/wsme/tests/test_restjson.py b/wsme/tests/test_restjson.py
index 3368703..d7c8110 100644
--- a/wsme/tests/test_restjson.py
+++ b/wsme/tests/test_restjson.py
@@ -339,6 +339,14 @@ class TestRestJson(wsme.tests.protocol.RestOnlyProtocolTestCase):
j = parse('{"a": "2011-01-01"}', {'a': datetime.date}, False)
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):
jlist = "invalid"
try: