mirror of https://github.com/zulip/zulip.git
tests: Simplify by always clearing IP limits in rate_limit_rule.
The only use case of rate_limit_rule which does not clear the RateLimitedIPAddr history is test_hit_ratelimits_as_remote_server, which is not made any worse by clearing out the IP history for a non-existent `api_by_remote_server` domain.
This commit is contained in:
parent
260ccc9620
commit
9495dad850
|
@ -70,6 +70,7 @@ class MITNameTest(ZulipTestCase):
|
|||
|
||||
@contextmanager
|
||||
def rate_limit_rule(range_seconds: int, num_requests: int, domain: str) -> Iterator[None]:
|
||||
RateLimitedIPAddr("127.0.0.1", domain=domain).clear_history()
|
||||
add_ratelimit_rule(range_seconds, num_requests, domain=domain)
|
||||
try:
|
||||
yield
|
||||
|
@ -196,13 +197,11 @@ class RateLimitTests(ZulipTestCase):
|
|||
|
||||
@rate_limit_rule(1, 5, domain="api_by_ip")
|
||||
def test_hit_ratelimits_as_ip(self) -> None:
|
||||
RateLimitedIPAddr("127.0.0.1").clear_history()
|
||||
self.do_test_hit_ratelimits(self.send_unauthed_api_request)
|
||||
|
||||
@rate_limit_rule(1, 5, domain="create_realm_by_ip")
|
||||
def test_create_realm_rate_limiting(self) -> None:
|
||||
with self.settings(OPEN_REALM_CREATION=True):
|
||||
RateLimitedIPAddr("127.0.0.1", domain="create_realm_by_ip").clear_history()
|
||||
self.do_test_hit_ratelimits(
|
||||
lambda: self.client_post("/new/", {"email": "new@zulip.com"}),
|
||||
is_json=False,
|
||||
|
@ -210,7 +209,6 @@ class RateLimitTests(ZulipTestCase):
|
|||
|
||||
@rate_limit_rule(1, 5, domain="find_account_by_ip")
|
||||
def test_find_account_rate_limiting(self) -> None:
|
||||
RateLimitedIPAddr("127.0.0.1", domain="find_account_by_ip").clear_history()
|
||||
self.do_test_hit_ratelimits(
|
||||
lambda: self.client_post("/accounts/find/", {"emails": "new@zulip.com"}),
|
||||
is_json=False,
|
||||
|
@ -221,7 +219,6 @@ class RateLimitTests(ZulipTestCase):
|
|||
# submitted in each should be allowed.
|
||||
@rate_limit_rule(1, 10, domain="find_account_by_ip")
|
||||
def test_find_account_rate_limiting_multiple(self) -> None:
|
||||
RateLimitedIPAddr("127.0.0.1", domain="find_account_by_ip").clear_history()
|
||||
self.do_test_hit_ratelimits(
|
||||
lambda: self.client_post("/accounts/find/", {"emails": "new@zulip.com,new2@zulip.com"}),
|
||||
is_json=False,
|
||||
|
|
Loading…
Reference in New Issue