diff options
author | Jorge Florian <jorge.floriannoriega@aiven.io> | 2022-04-08 13:51:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-08 07:51:27 -0400 |
commit | 2e2d8cc2f9b9af5f8b48d75e22c474e08feca236 (patch) | |
tree | 7777f2910c786fb18964b2ebbc50655337ec85e7 /tests | |
parent | CI: Get the portdb job to run under poetry (#12412) (diff) | |
download | synapse-2e2d8cc2f9b9af5f8b48d75e22c474e08feca236.tar.xz |
Update the server notices user profile in room if changed. (#12115)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/rest/admin/test_server_notice.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/rest/admin/test_server_notice.py b/tests/rest/admin/test_server_notice.py index a53463c9ba..dbcba2663c 100644 --- a/tests/rest/admin/test_server_notice.py +++ b/tests/rest/admin/test_server_notice.py @@ -409,6 +409,98 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase): # second room has new ID self.assertNotEqual(first_room_id, second_room_id) + @override_config({"server_notices": {"system_mxid_localpart": "notices"}}) + def test_update_notice_user_name_when_changed(self) -> None: + """ + Tests that existing server notices user name in room is updated after + server notice config changes. + """ + server_notice_request_content = { + "user_id": self.other_user, + "content": {"msgtype": "m.text", "body": "test msg one"}, + } + + self.make_request( + "POST", + self.url, + access_token=self.admin_user_tok, + content=server_notice_request_content, + ) + + # simulate a change in server config after a server restart. + new_display_name = "new display name" + self.server_notices_manager._config.servernotices.server_notices_mxid_display_name = ( + new_display_name + ) + self.server_notices_manager.get_or_create_notice_room_for_user.cache.invalidate_all() + + self.make_request( + "POST", + self.url, + access_token=self.admin_user_tok, + content=server_notice_request_content, + ) + + invited_rooms = self._check_invite_and_join_status(self.other_user, 1, 0) + notice_room_id = invited_rooms[0].room_id + self.helper.join( + room=notice_room_id, user=self.other_user, tok=self.other_user_token + ) + + notice_user_state_in_room = self.helper.get_state( + notice_room_id, + "m.room.member", + self.other_user_token, + state_key="@notices:test", + ) + self.assertEqual(notice_user_state_in_room["displayname"], new_display_name) + + @override_config({"server_notices": {"system_mxid_localpart": "notices"}}) + def test_update_notice_user_avatar_when_changed(self) -> None: + """ + Tests that existing server notices user avatar in room is updated when is + different from the one in homeserver config. + """ + server_notice_request_content = { + "user_id": self.other_user, + "content": {"msgtype": "m.text", "body": "test msg one"}, + } + + self.make_request( + "POST", + self.url, + access_token=self.admin_user_tok, + content=server_notice_request_content, + ) + + # simulate a change in server config after a server restart. + new_avatar_url = "test/new-url" + self.server_notices_manager._config.servernotices.server_notices_mxid_avatar_url = ( + new_avatar_url + ) + self.server_notices_manager.get_or_create_notice_room_for_user.cache.invalidate_all() + + self.make_request( + "POST", + self.url, + access_token=self.admin_user_tok, + content=server_notice_request_content, + ) + + invited_rooms = self._check_invite_and_join_status(self.other_user, 1, 0) + notice_room_id = invited_rooms[0].room_id + self.helper.join( + room=notice_room_id, user=self.other_user, tok=self.other_user_token + ) + + notice_user_state = self.helper.get_state( + notice_room_id, + "m.room.member", + self.other_user_token, + state_key="@notices:test", + ) + self.assertEqual(notice_user_state["avatar_url"], new_avatar_url) + def _check_invite_and_join_status( self, user_id: str, expected_invites: int, expected_memberships: int ) -> List[RoomsForUser]: |