diff options
author | David Robertson <davidr@element.io> | 2023-10-06 18:31:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-06 17:31:52 +0000 |
commit | 1f10c208068ef8788b6796c54a3604ae51caf951 (patch) | |
tree | 4b84fda2a8662bef38c264f151659ada6bbad8c4 /tests/rest/client/test_rooms.py | |
parent | Convert simple_select_list_paginate_txn to return tuples. (#16433) (diff) | |
download | synapse-1f10c208068ef8788b6796c54a3604ae51caf951.tar.xz |
Apply join rate limiter outside the lineariser (#16441)
Diffstat (limited to 'tests/rest/client/test_rooms.py')
-rw-r--r-- | tests/rest/client/test_rooms.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/rest/client/test_rooms.py b/tests/rest/client/test_rooms.py index 7627823d3f..aaa4f3bba0 100644 --- a/tests/rest/client/test_rooms.py +++ b/tests/rest/client/test_rooms.py @@ -1447,6 +1447,30 @@ class RoomJoinRatelimitTestCase(RoomBase): @unittest.override_config( {"rc_joins": {"local": {"per_second": 0.5, "burst_count": 3}}} ) + def test_join_attempts_local_ratelimit(self) -> None: + """Tests that unsuccessful joins that end up being denied are rate-limited.""" + # Create 4 rooms + room_ids = [ + self.helper.create_room_as(self.user_id, is_public=True) for _ in range(4) + ] + # Pre-emptively ban the user who will attempt to join. + joiner_user_id = self.register_user("joiner", "secret") + for room_id in room_ids: + self.helper.ban(room_id, self.user_id, joiner_user_id) + + # Now make a new user try to join some of them. + # The user can make 3 requests, each of which should be denied. + for room_id in room_ids[0:3]: + self.helper.join(room_id, joiner_user_id, expect_code=HTTPStatus.FORBIDDEN) + + # The fourth attempt should be rate limited. + self.helper.join( + room_ids[3], joiner_user_id, expect_code=HTTPStatus.TOO_MANY_REQUESTS + ) + + @unittest.override_config( + {"rc_joins": {"local": {"per_second": 0.5, "burst_count": 3}}} + ) def test_join_local_ratelimit_profile_change(self) -> None: """Tests that sending a profile update into all of the user's joined rooms isn't rate-limited by the rate-limiter on joins.""" |