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

Commit b84afb1

Browse files
committed
Fix remaining tests
1 parent e67f65f commit b84afb1

File tree

6 files changed

+6
-146
lines changed

6 files changed

+6
-146
lines changed

synapse/handlers/register.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,6 @@ async def register_user(
309309
shadow_banned=shadow_banned,
310310
)
311311

312-
if default_display_name:
313-
requester = create_requester(user)
314-
# FIXME: this function call is DINUM-specific code to update DINUM's
315-
# custom Sydent-powered userdir, and needed some custom changes to
316-
# ignore the ratelimiter. On mainline, we don't need to call this
317-
# function.
318-
await self.profile_handler.set_displayname(
319-
user, requester, default_display_name, by_admin=True
320-
)
321-
322312
profile = await self.store.get_profileinfo(localpart)
323313
await self.user_directory_handler.handle_local_profile_change(
324314
user_id, profile

tests/handlers/test_identity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_rewritten_id_server(self):
8080
"""
8181
handler = self.hs.get_identity_handler()
8282
post_json_get_json = handler.blacklisting_http_client.post_json_get_json
83-
store = self.hs.get_datastore()
83+
store = self.hs.get_datastores().main
8484

8585
creds = {"sid": "123", "client_secret": "some_secret"}
8686

tests/handlers/test_user_directory.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ def test_disabling_room_list(self) -> None:
10691069
class UserInfoTestCase(unittest.FederatingHomeserverTestCase):
10701070
servlets = [
10711071
login.register_servlets,
1072-
synapse.rest.admin.register_servlets_for_client_rest_resource,
1072+
synapse.rest.admin.register_servlets,
10731073
account_validity.register_servlets,
10741074
user_directory.register_servlets,
10751075
account.register_servlets,
@@ -1085,11 +1085,6 @@ def default_config(self) -> JsonDict:
10851085
}
10861086
return config
10871087

1088-
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
1089-
super(UserInfoTestCase, self).prepare(reactor, clock, hs)
1090-
self.store = hs.get_datastores().main
1091-
self.handler = hs.get_user_directory_handler()
1092-
10931088
def test_user_info(self) -> None:
10941089
"""Test /users/info for local users from the Client-Server API"""
10951090
user_one, user_two, user_three, user_three_token = self.setup_test_users()
@@ -1126,7 +1121,7 @@ def test_user_info_federation(self) -> None:
11261121
user_one, user_two, user_three, user_three_token = self.setup_test_users()
11271122

11281123
# Request information about our local users from the perspective of a remote server
1129-
channel = self.make_request(
1124+
channel = self.make_signed_federation_request(
11301125
"POST",
11311126
path="/_matrix/federation/unstable/users/info",
11321127
content={"user_ids": [user_one, user_two, user_three]},

tests/rest/client/test_identity.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,10 @@ def test_3pid_bulk_lookup_enabled(self) -> None:
159159
"id_server": "testis",
160160
"threepids": [["email", "[email protected]"], ["email", "[email protected]"]],
161161
}
162-
channel = self.make_request("POST", url, data, access_token=self.tok)
162+
self.make_request("POST", url, data, access_token=self.tok)
163163

164164
post_json = self.hs.get_simple_http_client().post_json_get_json
165165
post_json.assert_called_once_with(
166166
"https://testis/_matrix/identity/api/v1/bulk_lookup",
167167
{"threepids": [["email", "[email protected]"], ["email", "[email protected]"]]},
168-
)
169-
self.assertEqual(channel.code, HTTPStatus.FORBIDDEN, channel.result)
168+
)

tests/rest/client/test_register.py

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -810,24 +810,6 @@ def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
810810

811811
return self.hs
812812

813-
def test_profile_hidden(self) -> None:
814-
user_id = self.register_user("kermit", "monkey")
815-
816-
post_json = self.hs.get_simple_http_client().post_json_get_json
817-
818-
# We expect post_json_get_json to have been called twice: once with the original
819-
# profile and once with the None profile resulting from the request to hide it
820-
# from the user directory.
821-
self.assertEqual(post_json.call_count, 2, post_json.call_args_list)
822-
823-
# Get the args (and not kwargs) passed to post_json.
824-
args = post_json.call_args[0]
825-
# Make sure the last call was attempting to replicate profiles.
826-
split_uri = args[0].split("/")
827-
self.assertEqual(split_uri[len(split_uri) - 1], "replicate_profiles", args[0])
828-
# Make sure the last profile update was overriding the user's profile to None.
829-
self.assertEqual(args[1]["batch"][user_id], None, args[1])
830-
831813

832814
class AccountValidityTemplateDirectoryTestCase(unittest.HomeserverTestCase):
833815
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
@@ -1031,112 +1013,6 @@ def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
10311013

10321014
return self.hs
10331015

1034-
def test_expired_user_in_directory(self) -> None:
1035-
"""Test that an expired user is hidden in the user directory"""
1036-
# Create an admin user to search the user directory
1037-
admin_id = self.register_user("admin", "adminpassword", admin=True)
1038-
admin_tok = self.login("admin", "adminpassword")
1039-
1040-
# Ensure the admin never expires
1041-
url = "/_synapse/admin/v1/account_validity/validity"
1042-
params = {
1043-
"user_id": admin_id,
1044-
"expiration_ts": 999999999999,
1045-
"enable_renewal_emails": False,
1046-
}
1047-
request_data = json.dumps(params)
1048-
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
1049-
self.assertEquals(channel.result["code"], b"200", channel.result)
1050-
1051-
# Mock the homeserver's HTTP client
1052-
post_json = self.hs.get_simple_http_client().post_json_get_json
1053-
1054-
# Create a user
1055-
username = "kermit"
1056-
user_id = self.register_user(username, "monkey")
1057-
self.login(username, "monkey")
1058-
self.get_success(
1059-
self.hs.get_datastore().set_profile_displayname(username, "mr.kermit", 1)
1060-
)
1061-
1062-
# Check that a full profile for this user is replicated
1063-
self.assertIsNotNone(post_json.call_args, post_json.call_args)
1064-
payload = post_json.call_args[0][1]
1065-
batch = payload.get("batch")
1066-
1067-
self.assertIsNotNone(batch, batch)
1068-
self.assertEquals(len(batch), 1, batch)
1069-
1070-
replicated_user_id = list(batch.keys())[0]
1071-
self.assertEquals(replicated_user_id, user_id, replicated_user_id)
1072-
1073-
# There was replicated information about our user
1074-
# Check that it's not None
1075-
replicated_content = batch[user_id]
1076-
self.assertIsNotNone(replicated_content)
1077-
1078-
# Expire the user
1079-
url = "/_synapse/admin/v1/account_validity/validity"
1080-
params = {
1081-
"user_id": user_id,
1082-
"expiration_ts": 0,
1083-
"enable_renewal_emails": False,
1084-
}
1085-
request_data = json.dumps(params)
1086-
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
1087-
self.assertEquals(channel.result["code"], b"200", channel.result)
1088-
1089-
# Wait for the background job to run which hides expired users in the directory
1090-
self.reactor.advance(60 * 60 * 1000)
1091-
1092-
# Check if the homeserver has replicated the user's profile to the identity server
1093-
self.assertIsNotNone(post_json.call_args, post_json.call_args)
1094-
payload = post_json.call_args[0][1]
1095-
batch = payload.get("batch")
1096-
1097-
self.assertIsNotNone(batch, batch)
1098-
self.assertEquals(len(batch), 1, batch)
1099-
1100-
replicated_user_id = list(batch.keys())[0]
1101-
self.assertEquals(replicated_user_id, user_id, replicated_user_id)
1102-
1103-
# There was replicated information about our user
1104-
# Check that it's None, signifying that the user should be removed from the user
1105-
# directory because they were expired
1106-
replicated_content = batch[user_id]
1107-
self.assertIsNone(replicated_content)
1108-
1109-
# Now renew the user, and check they get replicated again to the identity server
1110-
url = "/_synapse/admin/v1/account_validity/validity"
1111-
params = {
1112-
"user_id": user_id,
1113-
"expiration_ts": 99999999999,
1114-
"enable_renewal_emails": False,
1115-
}
1116-
request_data = json.dumps(params)
1117-
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
1118-
self.assertEquals(channel.result["code"], b"200", channel.result)
1119-
1120-
self.pump(10)
1121-
self.reactor.advance(10)
1122-
self.pump()
1123-
1124-
# Check if the homeserver has replicated the user's profile to the identity server
1125-
post_json = self.hs.get_simple_http_client().post_json_get_json
1126-
self.assertNotEquals(post_json.call_args, None, post_json.call_args)
1127-
payload = post_json.call_args[0][1]
1128-
batch = payload.get("batch")
1129-
self.assertNotEquals(batch, None, batch)
1130-
self.assertEquals(len(batch), 1, batch)
1131-
replicated_user_id = list(batch.keys())[0]
1132-
self.assertEquals(replicated_user_id, user_id, replicated_user_id)
1133-
1134-
# There was replicated information about our user
1135-
# Check that it's not None, signifying that the user is back in the user
1136-
# directory
1137-
replicated_content = batch[user_id]
1138-
self.assertIsNotNone(replicated_content)
1139-
11401016

11411017
class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
11421018

tests/unittest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer):
780780
verify_key_id,
781781
FetchKeyResult(
782782
verify_key=verify_key,
783-
valid_until_ts=clock.time_msec() + 1000,
783+
valid_until_ts=clock.time_msec() + 2000,
784784
),
785785
)
786786
],

0 commit comments

Comments
 (0)