Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix rate limiting tests #8167

Merged
merged 2 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8167.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix tests that were broken due to the merge of 1.19.1.
27 changes: 14 additions & 13 deletions tests/rest/client/v1/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,38 +684,39 @@ class RoomJoinRatelimitTestCase(RoomBase):
]

@unittest.override_config(
{"rc_joins": {"local": {"per_second": 3, "burst_count": 3}}}
{"rc_joins": {"local": {"per_second": 0.5, "burst_count": 3}}}
)
def test_join_local_ratelimit(self):
"""Tests that local joins are actually rate-limited."""
for i in range(5):
for i in range(3):
babolivier marked this conversation as resolved.
Show resolved Hide resolved
self.helper.create_room_as(self.user_id)

self.helper.create_room_as(self.user_id, expect_code=429)

@unittest.override_config(
{"rc_joins": {"local": {"per_second": 3, "burst_count": 3}}}
{"rc_joins": {"local": {"per_second": 0.5, "burst_count": 3}}}
)
def test_join_local_ratelimit_profile_change(self):
"""Tests that sending a profile update into all of the user's joined rooms isn't
rate-limited by the rate-limiter on joins."""

# Create and join more rooms than the rate-limiting config allows in a second.
# Create and join as many rooms as the rate-limiting config allows in a second.
room_ids = [
self.helper.create_room_as(self.user_id),
self.helper.create_room_as(self.user_id),
self.helper.create_room_as(self.user_id),
]
self.reactor.advance(1)
room_ids = room_ids + [
self.helper.create_room_as(self.user_id),
self.helper.create_room_as(self.user_id),
self.helper.create_room_as(self.user_id),
]
# Let some time for the rate-limiter to forget about our multi-join.
self.reactor.advance(2)
# Add one to make sure we're joined to more rooms than the config allows us to
# join in a second.
room_ids.append(self.helper.create_room_as(self.user_id))

# Create a profile for the user, since it hasn't been done on registration.
store = self.hs.get_datastore()
store.create_profile(UserID.from_string(self.user_id).localpart)
self.get_success(
store.create_profile(UserID.from_string(self.user_id).localpart)
)

# Update the display name for the user.
path = "/_matrix/client/r0/profile/%s/displayname" % self.user_id
Expand All @@ -738,7 +739,7 @@ def test_join_local_ratelimit_profile_change(self):
self.assertEquals(channel.json_body["displayname"], "John Doe")

@unittest.override_config(
{"rc_joins": {"local": {"per_second": 3, "burst_count": 3}}}
{"rc_joins": {"local": {"per_second": 0.5, "burst_count": 3}}}
)
def test_join_local_ratelimit_idempotent(self):
"""Tests that the room join endpoints remain idempotent despite rate-limiting
Expand All @@ -754,7 +755,7 @@ def test_join_local_ratelimit_idempotent(self):
for path in paths_to_test:
# Make sure we send more requests than the rate-limiting config would allow
# if all of these requests ended up joining the user to a room.
for i in range(6):
for i in range(4):
request, channel = self.make_request("POST", path % room_id, {})
self.render(request)
self.assertEquals(channel.code, 200)
Expand Down