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

Fix join ratelimiter breaking profile updates and idempotency #8153

Merged
merged 6 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Also test ratelimiting while we're there
  • Loading branch information
babolivier committed Aug 24, 2020
commit d96ca0574953c6d66c27ce712ff99b429ec9cd04
16 changes: 15 additions & 1 deletion tests/rest/client/v1/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,14 +675,28 @@ def test_rooms_members_other_custom_keys(self):
self.assertEquals(json.loads(content), channel.json_body)


class RoomMembershipUpdateTestCase(RoomBase):
class RoomJoinRatelimitTestCase(RoomBase):
user_id = "@sid1:red"

servlets = [
profile.register_servlets,
room.register_servlets,
]

@unittest.override_config(
{
"rc_joins": {
"local": {"per_second": 3, "burst_count": 3},
}
}
)
def test_join_local_ratelimit(self):
"""Tests that local joins are actually rate-limited."""
for i in range(5):
self.helper.create_room_as(self.user_id)

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

@unittest.override_config(
{
"rc_joins": {
Expand Down
14 changes: 11 additions & 3 deletions tests/rest/client/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ class RestHelper(object):
resource = attr.ib()
auth_user_id = attr.ib()

def create_room_as(self, room_creator=None, is_public=True, tok=None):
def create_room_as(
self,
room_creator=None,
is_public=True,
tok=None,
expect_code=200,
):
temp_id = self.auth_user_id
self.auth_user_id = room_creator
path = "/_matrix/client/r0/createRoom"
Expand All @@ -54,9 +60,11 @@ def create_room_as(self, room_creator=None, is_public=True, tok=None):
)
render(request, self.resource, self.hs.get_reactor())

assert channel.result["code"] == b"200", channel.result
assert channel.result["code"] == b"%d" % expect_code, channel.result
self.auth_user_id = temp_id
return channel.json_body["room_id"]

if expect_code == 200:
return channel.json_body["room_id"]

def invite(self, room=None, src=None, targ=None, expect_code=200, tok=None):
self.change_membership(
Expand Down