Skip to content

Commit b64d92d

Browse files
committed
Invalid REST item spec returns 404 rather than 400.
A GET to /rest/data/issue/issue4 now returns a 404 rather than a 400 status code.
1 parent b3bf1b8 commit b64d92d

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ Fixed:
9696
8-). Also supports shell and admin mode (John Rouillard)
9797
- Multiple fixes/updates for installation documentation.
9898
Including docker shell/admin/demo mdoes. (John Rouillard)
99+
- Invalid item identifiers passed to REST endpoint return a 404
100+
rather than a 400 error. E.G. /rest/data/issue/issue4 (rather
101+
than .../issue/4). (John Rouillard)
99102

100103
Features:
101104

roundup/rest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,11 @@ def get_element(self, class_name, item_id, input):
10021002
'Permission to view %s%s.%s denied'
10031003
% (class_name, item_id, keyprop)
10041004
)
1005-
itemid = class_obj.lookup(v)
1005+
try:
1006+
itemid = class_obj.lookup(v)
1007+
except TypeError:
1008+
raise NotFound("Item '%s' not found" % v)
1009+
10061010
if not self.db.security.hasPermission(
10071011
'View', uid, class_name, itemid=itemid
10081012
):

test/rest_common.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,27 @@ def testBinaryFieldStorage(self):
13541354
json_dict = json.loads(b2s(results))
13551355
self.assertEqual(json_dict,expected)
13561356

1357+
1358+
def testDispatchGet(self):
1359+
self.create_sampledata()
1360+
1361+
form = cgi.FieldStorage()
1362+
self.server.client.request.headers.get=self.get_header
1363+
1364+
for item in [ "55", "issue1", "1" ]:
1365+
print("test item: '%s'" % item)
1366+
results = self.server.dispatch("GET",
1367+
"/rest/data/issue/%s" % item,
1368+
form)
1369+
json_dict = json.loads(b2s(results))
1370+
try:
1371+
self.assertEqual(json_dict['error']['status'], 404)
1372+
except KeyError as e:
1373+
if e.args[0] == "error" and item == "1":
1374+
pass
1375+
else:
1376+
self.assertTrue(False)
1377+
13571378
def testDispatchPost(self):
13581379
"""
13591380
run POST through rest dispatch(). This also tests

0 commit comments

Comments
 (0)