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:
Alex Vandiver 2021-11-03 13:36:10 -07:00 committed by Tim Abbott
parent 260ccc9620
commit 9495dad850
1 changed files with 1 additions and 4 deletions

View File

@ -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,