diff options
author | Shay <hillerys@element.io> | 2024-01-22 05:59:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-22 13:59:45 +0000 |
commit | a68b48a5dd0b617f12677b137742b813a2d805bb (patch) | |
tree | c2857be9b019985571cda0e09eea6f2dcd91a409 /tests/handlers | |
parent | Bump regex from 1.9.6 to 1.10.3 (#16837) (diff) | |
download | synapse-a68b48a5dd0b617f12677b137742b813a2d805bb.tar.xz |
Allow room creation but not publishing to continue if room publication rules are violated when creating a new room. (#16811)
Prior to this PR, if a request to create a public (public as in published to the rooms directory) room violated the room list publication rules set in the [config](https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html#room_list_publication_rules), the request to create the room was denied and the room was not created. This PR changes the behavior such that when a request to create a room published to the directory violates room list publication rules, the room is still created but the room is not published to the directory.
Diffstat (limited to 'tests/handlers')
-rw-r--r-- | tests/handlers/test_directory.py | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/tests/handlers/test_directory.py b/tests/handlers/test_directory.py index 03c360cca6..cb05fecf3c 100644 --- a/tests/handlers/test_directory.py +++ b/tests/handlers/test_directory.py @@ -496,19 +496,27 @@ class TestCreatePublishedRoomACL(unittest.HomeserverTestCase): self.denied_user_id = self.register_user("denied", "pass") self.denied_access_token = self.login("denied", "pass") + self.store = hs.get_datastores().main + def test_denied_without_publication_permission(self) -> None: """ - Try to create a room, register an alias for it, and publish it, + Try to create a room, register a valid alias for it, and publish it, as a user without permission to publish rooms. - (This is used as both a standalone test & as a helper function.) + The room should be created but not published. """ - self.helper.create_room_as( + room_id = self.helper.create_room_as( self.denied_user_id, tok=self.denied_access_token, extra_content=self.data, is_public=True, - expect_code=403, + expect_code=200, ) + res = self.get_success(self.store.get_room(room_id)) + assert res is not None + is_public, _ = res + + # room creation completes but room is not published to directory + self.assertEqual(is_public, False) def test_allowed_when_creating_private_room(self) -> None: """ @@ -526,9 +534,8 @@ class TestCreatePublishedRoomACL(unittest.HomeserverTestCase): def test_allowed_with_publication_permission(self) -> None: """ - Try to create a room, register an alias for it, and publish it, + Try to create a room, register a valid alias for it, and publish it, as a user WITH permission to publish rooms. - (This is used as both a standalone test & as a helper function.) """ self.helper.create_room_as( self.allowed_user_id, @@ -540,38 +547,26 @@ class TestCreatePublishedRoomACL(unittest.HomeserverTestCase): def test_denied_publication_with_invalid_alias(self) -> None: """ - Try to create a room, register an alias for it, and publish it, + Try to create a room, register an invalid alias for it, and publish it, as a user WITH permission to publish rooms. """ - self.helper.create_room_as( + room_id = self.helper.create_room_as( self.allowed_user_id, tok=self.allowed_access_token, extra_content={"room_alias_name": "foo"}, is_public=True, - expect_code=403, + expect_code=200, ) - def test_can_create_as_private_room_after_rejection(self) -> None: - """ - After failing to publish a room with an alias as a user without publish permission, - retry as the same user, but without publishing the room. + # the room is created with the requested alias, but the room is not published + res = self.get_success(self.store.get_room(room_id)) + assert res is not None + is_public, _ = res - This should pass, but used to fail because the alias was registered by the first - request, even though the room creation was denied. - """ - self.test_denied_without_publication_permission() - self.test_allowed_when_creating_private_room() - - def test_can_create_with_permission_after_rejection(self) -> None: - """ - After failing to publish a room with an alias as a user without publish permission, - retry as someone with permission, using the same alias. + self.assertFalse(is_public) - This also used to fail because of the alias having been registered by the first - request, leaving it unavailable for any other user's new rooms. - """ - self.test_denied_without_publication_permission() - self.test_allowed_with_publication_permission() + aliases = self.get_success(self.store.get_aliases_for_room(room_id)) + self.assertEqual(aliases[0], "#foo:test") class TestRoomListSearchDisabled(unittest.HomeserverTestCase): |