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

Commit

Permalink
Fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
babolivier committed May 3, 2022
1 parent e67f65f commit b84afb1
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 146 deletions.
10 changes: 0 additions & 10 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,6 @@ async def register_user(
shadow_banned=shadow_banned,
)

if default_display_name:
requester = create_requester(user)
# FIXME: this function call is DINUM-specific code to update DINUM's
# custom Sydent-powered userdir, and needed some custom changes to
# ignore the ratelimiter. On mainline, we don't need to call this
# function.
await self.profile_handler.set_displayname(
user, requester, default_display_name, by_admin=True
)

profile = await self.store.get_profileinfo(localpart)
await self.user_directory_handler.handle_local_profile_change(
user_id, profile
Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_rewritten_id_server(self):
"""
handler = self.hs.get_identity_handler()
post_json_get_json = handler.blacklisting_http_client.post_json_get_json
store = self.hs.get_datastore()
store = self.hs.get_datastores().main

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

Expand Down
9 changes: 2 additions & 7 deletions tests/handlers/test_user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ def test_disabling_room_list(self) -> None:
class UserInfoTestCase(unittest.FederatingHomeserverTestCase):
servlets = [
login.register_servlets,
synapse.rest.admin.register_servlets_for_client_rest_resource,
synapse.rest.admin.register_servlets,
account_validity.register_servlets,
user_directory.register_servlets,
account.register_servlets,
Expand All @@ -1085,11 +1085,6 @@ def default_config(self) -> JsonDict:
}
return config

def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
super(UserInfoTestCase, self).prepare(reactor, clock, hs)
self.store = hs.get_datastores().main
self.handler = hs.get_user_directory_handler()

def test_user_info(self) -> None:
"""Test /users/info for local users from the Client-Server API"""
user_one, user_two, user_three, user_three_token = self.setup_test_users()
Expand Down Expand Up @@ -1126,7 +1121,7 @@ def test_user_info_federation(self) -> None:
user_one, user_two, user_three, user_three_token = self.setup_test_users()

# Request information about our local users from the perspective of a remote server
channel = self.make_request(
channel = self.make_signed_federation_request(
"POST",
path="/_matrix/federation/unstable/users/info",
content={"user_ids": [user_one, user_two, user_three]},
Expand Down
5 changes: 2 additions & 3 deletions tests/rest/client/test_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ def test_3pid_bulk_lookup_enabled(self) -> None:
"id_server": "testis",
"threepids": [["email", "[email protected]"], ["email", "[email protected]"]],
}
channel = self.make_request("POST", url, data, access_token=self.tok)
self.make_request("POST", url, data, access_token=self.tok)

post_json = self.hs.get_simple_http_client().post_json_get_json
post_json.assert_called_once_with(
"https://testis/_matrix/identity/api/v1/bulk_lookup",
{"threepids": [["email", "[email protected]"], ["email", "[email protected]"]]},
)
self.assertEqual(channel.code, HTTPStatus.FORBIDDEN, channel.result)
)
124 changes: 0 additions & 124 deletions tests/rest/client/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,24 +810,6 @@ def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:

return self.hs

def test_profile_hidden(self) -> None:
user_id = self.register_user("kermit", "monkey")

post_json = self.hs.get_simple_http_client().post_json_get_json

# We expect post_json_get_json to have been called twice: once with the original
# profile and once with the None profile resulting from the request to hide it
# from the user directory.
self.assertEqual(post_json.call_count, 2, post_json.call_args_list)

# Get the args (and not kwargs) passed to post_json.
args = post_json.call_args[0]
# Make sure the last call was attempting to replicate profiles.
split_uri = args[0].split("/")
self.assertEqual(split_uri[len(split_uri) - 1], "replicate_profiles", args[0])
# Make sure the last profile update was overriding the user's profile to None.
self.assertEqual(args[1]["batch"][user_id], None, args[1])


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

return self.hs

def test_expired_user_in_directory(self) -> None:
"""Test that an expired user is hidden in the user directory"""
# Create an admin user to search the user directory
admin_id = self.register_user("admin", "adminpassword", admin=True)
admin_tok = self.login("admin", "adminpassword")

# Ensure the admin never expires
url = "/_synapse/admin/v1/account_validity/validity"
params = {
"user_id": admin_id,
"expiration_ts": 999999999999,
"enable_renewal_emails": False,
}
request_data = json.dumps(params)
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
self.assertEquals(channel.result["code"], b"200", channel.result)

# Mock the homeserver's HTTP client
post_json = self.hs.get_simple_http_client().post_json_get_json

# Create a user
username = "kermit"
user_id = self.register_user(username, "monkey")
self.login(username, "monkey")
self.get_success(
self.hs.get_datastore().set_profile_displayname(username, "mr.kermit", 1)
)

# Check that a full profile for this user is replicated
self.assertIsNotNone(post_json.call_args, post_json.call_args)
payload = post_json.call_args[0][1]
batch = payload.get("batch")

self.assertIsNotNone(batch, batch)
self.assertEquals(len(batch), 1, batch)

replicated_user_id = list(batch.keys())[0]
self.assertEquals(replicated_user_id, user_id, replicated_user_id)

# There was replicated information about our user
# Check that it's not None
replicated_content = batch[user_id]
self.assertIsNotNone(replicated_content)

# Expire the user
url = "/_synapse/admin/v1/account_validity/validity"
params = {
"user_id": user_id,
"expiration_ts": 0,
"enable_renewal_emails": False,
}
request_data = json.dumps(params)
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
self.assertEquals(channel.result["code"], b"200", channel.result)

# Wait for the background job to run which hides expired users in the directory
self.reactor.advance(60 * 60 * 1000)

# Check if the homeserver has replicated the user's profile to the identity server
self.assertIsNotNone(post_json.call_args, post_json.call_args)
payload = post_json.call_args[0][1]
batch = payload.get("batch")

self.assertIsNotNone(batch, batch)
self.assertEquals(len(batch), 1, batch)

replicated_user_id = list(batch.keys())[0]
self.assertEquals(replicated_user_id, user_id, replicated_user_id)

# There was replicated information about our user
# Check that it's None, signifying that the user should be removed from the user
# directory because they were expired
replicated_content = batch[user_id]
self.assertIsNone(replicated_content)

# Now renew the user, and check they get replicated again to the identity server
url = "/_synapse/admin/v1/account_validity/validity"
params = {
"user_id": user_id,
"expiration_ts": 99999999999,
"enable_renewal_emails": False,
}
request_data = json.dumps(params)
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
self.assertEquals(channel.result["code"], b"200", channel.result)

self.pump(10)
self.reactor.advance(10)
self.pump()

# Check if the homeserver has replicated the user's profile to the identity server
post_json = self.hs.get_simple_http_client().post_json_get_json
self.assertNotEquals(post_json.call_args, None, post_json.call_args)
payload = post_json.call_args[0][1]
batch = payload.get("batch")
self.assertNotEquals(batch, None, batch)
self.assertEquals(len(batch), 1, batch)
replicated_user_id = list(batch.keys())[0]
self.assertEquals(replicated_user_id, user_id, replicated_user_id)

# There was replicated information about our user
# Check that it's not None, signifying that the user is back in the user
# directory
replicated_content = batch[user_id]
self.assertIsNotNone(replicated_content)


class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):

Expand Down
2 changes: 1 addition & 1 deletion tests/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer):
verify_key_id,
FetchKeyResult(
verify_key=verify_key,
valid_until_ts=clock.time_msec() + 1000,
valid_until_ts=clock.time_msec() + 2000,
),
)
],
Expand Down

0 comments on commit b84afb1

Please sign in to comment.