mirror of https://github.com/zulip/zulip.git
settings: Add new DEBUG_RATE_LIMITING setting.
This exists primarily in order to allow us to mock settings.DEBUG for the purposes of rate limiting, without actually mocking settings.DEBUG, which I suspect Django never intended one to do, and thus caused some very strange test failures (see https://github.com/zulip/zulip/pull/776 for details).
This commit is contained in:
parent
5691ca61b0
commit
700e803840
|
@ -466,7 +466,8 @@ def client_is_exempt_from_rate_limiting(request):
|
|||
# Don't rate limit requests from Django that come from our own servers,
|
||||
# and don't rate-limit dev instances
|
||||
return ((request.client and request.client.name.lower() == 'internal')
|
||||
and (is_local_addr(request.META['REMOTE_ADDR']) or settings.DEBUG))
|
||||
and (is_local_addr(request.META['REMOTE_ADDR']) or
|
||||
settings.DEBUG_RATE_LIMITING))
|
||||
|
||||
def internal_notify_view(view_func):
|
||||
# type: (ViewFuncT) -> ViewFuncT
|
||||
|
|
|
@ -263,7 +263,7 @@ class RateLimitTestCase(TestCase):
|
|||
with self.settings(RATE_LIMITING=True):
|
||||
with mock.patch('zerver.decorator.rate_limit_user') as rate_limit_mock:
|
||||
with self.errors_disallowed():
|
||||
with self.settings(DEBUG=True):
|
||||
with self.settings(DEBUG_RATE_LIMITING=True):
|
||||
self.assertEqual(f(req), 'some value')
|
||||
|
||||
self.assertFalse(rate_limit_mock.called)
|
||||
|
|
|
@ -404,6 +404,7 @@ CACHES = {
|
|||
RATE_LIMITING_RULES = [
|
||||
(60, 100), # 100 requests max every minute
|
||||
]
|
||||
DEBUG_RATE_LIMITING = DEBUG
|
||||
|
||||
########################################################################
|
||||
# SECURITY SETTINGS
|
||||
|
|
Loading…
Reference in New Issue