Skip to content

Commit

Permalink
Make throttle key more specific with get_ident
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankApiyo committed Aug 30, 2024
1 parent ecf661b commit e7db607
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion onadata/libs/tests/test_throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def test_anonymous_users_get_throttled_based_on_uri_path(self):
request.user = AnonymousUser()
self.throttle.scope = "submission"
cache_key = self.throttle.get_cache_key(request, None)
self.assertEqual(cache_key, "throttle_submission_/enketo/1234/submission")
self.assertEqual(
cache_key,
"throttle_submission_/enketo/1234/submission_127.0.0.1"
)

def test_users_get_throttled_based_on_uri_path(self):
request = self.factory.get("/enketo/1234/submission")
Expand Down
2 changes: 1 addition & 1 deletion onadata/libs/throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_cache_key(self, request, view):
if request.user and request.user.is_authenticated:
return super().get_cache_key(request, view)

return f'throttle_{self.scope}_{request.path}'
return f'throttle_{self.scope}_{request.path}_{self.get_ident(request)}'


class RequestHeaderThrottle(SimpleRateThrottle):
Expand Down

0 comments on commit e7db607

Please sign in to comment.