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

Commit 76751aa

Browse files
author
David Robertson
committed
Check appservice profile changes are ignored
1 parent 3f969d1 commit 76751aa

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

tests/handlers/test_user_directory.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import synapse.rest.admin
2121
from synapse.api.constants import UserTypes
2222
from synapse.api.room_versions import RoomVersion, RoomVersions
23-
from synapse.rest.client import login, room, user_directory
23+
from synapse.appservice import ApplicationService
24+
from synapse.rest.client import login, register, room, user_directory
2425
from synapse.server import HomeServer
2526
from synapse.storage.roommember import ProfileInfo
2627
from synapse.types import create_requester
@@ -47,13 +48,29 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase):
4748
servlets = [
4849
login.register_servlets,
4950
synapse.rest.admin.register_servlets,
51+
register.register_servlets,
5052
room.register_servlets,
5153
]
5254

5355
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
5456
config = self.default_config()
5557
config["update_user_directory"] = True
56-
return self.setup_test_homeserver(config=config)
58+
59+
self.appservice = ApplicationService(
60+
token="i_am_an_app_service",
61+
hostname="test",
62+
id="1234",
63+
namespaces={"users": [{"regex": r"@as_user.*", "exclusive": True}]},
64+
sender="@as:test",
65+
)
66+
67+
mock_load_appservices = Mock(return_value=[self.appservice])
68+
with patch(
69+
"synapse.storage.databases.main.appservice.load_appservices",
70+
mock_load_appservices,
71+
):
72+
hs = self.setup_test_homeserver(config=config)
73+
return hs
5774

5875
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
5976
self.store = hs.get_datastore()
@@ -125,6 +142,26 @@ def test_handle_local_profile_change_with_deactivated_user(self) -> None:
125142
profile = self.get_success(self.store.get_user_in_directory(r_user_id))
126143
self.assertTrue(profile is None)
127144

145+
def test_handle_local_profile_change_with_appservice_user(self) -> None:
146+
# create user
147+
as_user_id = self.register_appservice_user(
148+
"as_user_alice", self.appservice.token
149+
)
150+
151+
# profile is not in directory
152+
profile = self.get_success(self.store.get_user_in_directory(as_user_id))
153+
self.assertTrue(profile is None)
154+
155+
# update profile
156+
profile_info = ProfileInfo(avatar_url="avatar_url", display_name="4L1c3")
157+
self.get_success(
158+
self.handler.handle_local_profile_change(as_user_id, profile_info)
159+
)
160+
161+
# profile is still not in directory
162+
profile = self.get_success(self.store.get_user_in_directory(as_user_id))
163+
self.assertTrue(profile is None)
164+
128165
def test_handle_user_deactivated_support_user(self) -> None:
129166
s_user_id = "@support:test"
130167
self.get_success(

0 commit comments

Comments
 (0)