@@ -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
832814class 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
11411017class AccountValidityRenewalByEmailTestCase (unittest .HomeserverTestCase ):
11421018
0 commit comments