diff --git a/tests/rest/client/test_room_access_rules.py b/tests/rest/client/test_room_access_rules.py index 95a02c2240..78848335ad 100644 --- a/tests/rest/client/test_room_access_rules.py +++ b/tests/rest/client/test_room_access_rules.py @@ -464,6 +464,24 @@ def test_change_rules(self): new_rule=AccessRules.UNRESTRICTED, expected_code=403, ) + # We can't publish a room to the public rooms directory and then change its rule + # to unrestricted + + # Create a restricted room + test_room_id = self.create_room() + + # Publish the room to the public rooms directory + url = "/_matrix/client/r0/directory/list/room/%s" % test_room_id + data = {"visibility": "public"} + + request, channel = self.make_request("PUT", url, data, access_token=self.tok) + self.render(request) + self.assertEqual(channel.code, 200, channel.result) + + # Attempt to switch the room to "unrestricted" + self.change_rule_in_room( + room_id=test_room_id, new_rule=AccessRules.UNRESTRICTED, expected_code=403 + ) def test_change_room_avatar(self): """Tests that changing the room avatar is always allowed unless the room is a