Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Add a test that IP rate-limiting is by IP.
Alex Vandiver5f0897e6f784
diff --git a/zerver/tests/test_external.py b/zerver/tests/test_external.pyindex 40781d200a6..e81bcaa952c 100644--- a/zerver/tests/test_external.py+++ b/zerver/tests/test_external.py@@ -1,6 +1,6 @@import timefrom contextlib import contextmanager-from typing import Callable, Iterator, Optional+from typing import Any, Callable, Iteratorfrom unittest import mock, skipUnlessimport DNS@@ -118,8 +118,8 @@ class RateLimitTests(ZulipTestCase):},)- def send_unauthed_api_request(self) -> HttpResponse:- result = self.client_get("/json/messages")+ def send_unauthed_api_request(self, **kwargs: Any) -> HttpResponse:+ result = self.client_get("/json/messages", **kwargs)# We're not making a correct request here, but rate-limiting is supposed# to happen before the request fails due to not being correctly made. Thus# we expect either an 400 error if the request is allowed by the rate limiter,@@ -199,6 +199,10 @@ class RateLimitTests(ZulipTestCase):def test_hit_ratelimits_as_ip(self) -> None:self.do_test_hit_ratelimits(self.send_unauthed_api_request)+ # Other IPs should not be rate-limited+ resp = self.send_unauthed_api_request(REMOTE_ADDR="127.0.0.2")+ self.assertNotEqual(resp.status_code, 429)+@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):