Skip to content

Commit

Permalink
Merge pull request GamesDoneQuick#252 from GamesDoneQuick/174583704-n…
Browse files Browse the repository at this point in the history
…egative-limit

negative limit on search returns a 400 instead of throwing [#174583704]
  • Loading branch information
uraniumanchor authored Aug 31, 2020
2 parents c54a483 + 68aea91 commit 2a2933b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def test_search_with_offset_and_limit(self):
# bad request if limit is set above server config
self.parseJSON(tracker.views.api.search(request), status_code=400)

request = self.factory.get('/api/v1/search', dict(type='donation', limit=-1),)
request.user = self.anonymous_user
# bad request if limit is negative
self.parseJSON(tracker.views.api.search(request), status_code=400)

def test_add_log(self):
request = self.factory.post(
'/api/v1/add',
Expand Down
2 changes: 2 additions & 0 deletions views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ def search(request):
limit_param = int(single(search_params, 'limit', limit))
if limit_param > limit:
raise ValueError('limit can not be above %d' % limit)
if limit_param < 1:
raise ValueError('limit must be at least 1')
limit = min(limit, limit_param)

qs = search_filters.run_model_query(search_type, search_params, request.user,)
Expand Down

0 comments on commit 2a2933b

Please sign in to comment.