0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-24 12:04:13 +01:00

Fix rate limiting unit tests. (#8167)

These were passing on the release-v1.19.1 branch but started failing once merged
to develop.
This commit is contained in:
Patrick Cloke 2020-08-26 07:19:20 -04:00 committed by GitHub
parent eba98fb024
commit 56efa9ec71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 13 deletions

1
changelog.d/8167.misc Normal file
View file

@ -0,0 +1 @@
Fix tests that were broken due to the merge of 1.19.1.

View file

@ -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):
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
@ -738,7 +739,7 @@ class RoomJoinRatelimitTestCase(RoomBase):
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
@ -754,7 +755,7 @@ class RoomJoinRatelimitTestCase(RoomBase):
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)