@@ -1181,14 +1181,15 @@ def prepare(self, reactor, clock, hs):
1181
1181
self .other_user , device_id = None , valid_until_ms = None
1182
1182
)
1183
1183
)
1184
+
1184
1185
self .url_prefix = "/_synapse/admin/v2/users/%s"
1185
1186
self .url_other_user = self .url_prefix % self .other_user
1186
1187
1187
1188
def test_requester_is_no_admin (self ):
1188
1189
"""
1189
1190
If the user is not a server admin, an error is returned.
1190
1191
"""
1191
- url = "/_synapse/admin/v2/users/ @bob:test"
1192
+ url = self . url_prefix % " @bob:test"
1192
1193
1193
1194
channel = self .make_request (
1194
1195
"GET" ,
@@ -1216,7 +1217,7 @@ def test_user_does_not_exist(self):
1216
1217
1217
1218
channel = self .make_request (
1218
1219
"GET" ,
1219
- "/_synapse/admin/v2/users/ @unknown_person:test" ,
1220
+ self . url_prefix % " @unknown_person:test" ,
1220
1221
access_token = self .admin_user_tok ,
1221
1222
)
1222
1223
@@ -1337,7 +1338,7 @@ def test_create_server_admin(self):
1337
1338
"""
1338
1339
Check that a new admin user is created successfully.
1339
1340
"""
1340
- url = "/_synapse/admin/v2/users/ @bob:test"
1341
+ url = self . url_prefix % " @bob:test"
1341
1342
1342
1343
# Create user (server admin)
1343
1344
body = {
@@ -1386,7 +1387,7 @@ def test_create_user(self):
1386
1387
"""
1387
1388
Check that a new regular user is created successfully.
1388
1389
"""
1389
- url = "/_synapse/admin/v2/users/ @bob:test"
1390
+ url = self . url_prefix % " @bob:test"
1390
1391
1391
1392
# Create user
1392
1393
body = {
@@ -1478,7 +1479,7 @@ def test_create_user_mau_limit_reached_active_admin(self):
1478
1479
)
1479
1480
1480
1481
# Register new user with admin API
1481
- url = "/_synapse/admin/v2/users/ @bob:test"
1482
+ url = self . url_prefix % " @bob:test"
1482
1483
1483
1484
# Create user
1484
1485
channel = self .make_request (
@@ -1515,7 +1516,7 @@ def test_create_user_mau_limit_reached_passive_admin(self):
1515
1516
)
1516
1517
1517
1518
# Register new user with admin API
1518
- url = "/_synapse/admin/v2/users/ @bob:test"
1519
+ url = self . url_prefix % " @bob:test"
1519
1520
1520
1521
# Create user
1521
1522
channel = self .make_request (
@@ -1545,7 +1546,7 @@ def test_create_user_email_notif_for_new_users(self):
1545
1546
Check that a new regular user is created successfully and
1546
1547
got an email pusher.
1547
1548
"""
1548
- url = "/_synapse/admin/v2/users/ @bob:test"
1549
+ url = self . url_prefix % " @bob:test"
1549
1550
1550
1551
# Create user
1551
1552
body = {
@@ -1588,7 +1589,7 @@ def test_create_user_email_no_notif_for_new_users(self):
1588
1589
Check that a new regular user is created successfully and
1589
1590
got not an email pusher.
1590
1591
"""
1591
- url = "/_synapse/admin/v2/users/ @bob:test"
1592
+ url = self . url_prefix % " @bob:test"
1592
1593
1593
1594
# Create user
1594
1595
body = {
@@ -2085,10 +2086,13 @@ def test_deactivate_user(self):
2085
2086
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
2086
2087
self .assertEqual ("@user:test" , channel .json_body ["name" ])
2087
2088
self .assertTrue (channel .json_body ["deactivated" ])
2088
- self .assertIsNone (channel .json_body ["password_hash" ])
2089
2089
self .assertEqual (0 , len (channel .json_body ["threepids" ]))
2090
2090
self .assertEqual ("mxc://servername/mediaid" , channel .json_body ["avatar_url" ])
2091
2091
self .assertEqual ("User" , channel .json_body ["displayname" ])
2092
+
2093
+ # This key was removed intentionally. Ensure it is not accidentally re-included.
2094
+ self .assertNotIn ("password_hash" , channel .json_body )
2095
+
2092
2096
# the user is deactivated, the threepid will be deleted
2093
2097
2094
2098
# Get user
@@ -2101,11 +2105,13 @@ def test_deactivate_user(self):
2101
2105
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
2102
2106
self .assertEqual ("@user:test" , channel .json_body ["name" ])
2103
2107
self .assertTrue (channel .json_body ["deactivated" ])
2104
- self .assertIsNone (channel .json_body ["password_hash" ])
2105
2108
self .assertEqual (0 , len (channel .json_body ["threepids" ]))
2106
2109
self .assertEqual ("mxc://servername/mediaid" , channel .json_body ["avatar_url" ])
2107
2110
self .assertEqual ("User" , channel .json_body ["displayname" ])
2108
2111
2112
+ # This key was removed intentionally. Ensure it is not accidentally re-included.
2113
+ self .assertNotIn ("password_hash" , channel .json_body )
2114
+
2109
2115
@override_config ({"user_directory" : {"enabled" : True , "search_all_users" : True }})
2110
2116
def test_change_name_deactivate_user_user_directory (self ):
2111
2117
"""
@@ -2177,9 +2183,11 @@ def test_reactivate_user(self):
2177
2183
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
2178
2184
self .assertEqual ("@user:test" , channel .json_body ["name" ])
2179
2185
self .assertFalse (channel .json_body ["deactivated" ])
2180
- self .assertIsNotNone (channel .json_body ["password_hash" ])
2181
2186
self ._is_erased ("@user:test" , False )
2182
2187
2188
+ # This key was removed intentionally. Ensure it is not accidentally re-included.
2189
+ self .assertNotIn ("password_hash" , channel .json_body )
2190
+
2183
2191
@override_config ({"password_config" : {"localdb_enabled" : False }})
2184
2192
def test_reactivate_user_localdb_disabled (self ):
2185
2193
"""
@@ -2209,9 +2217,11 @@ def test_reactivate_user_localdb_disabled(self):
2209
2217
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
2210
2218
self .assertEqual ("@user:test" , channel .json_body ["name" ])
2211
2219
self .assertFalse (channel .json_body ["deactivated" ])
2212
- self .assertIsNone (channel .json_body ["password_hash" ])
2213
2220
self ._is_erased ("@user:test" , False )
2214
2221
2222
+ # This key was removed intentionally. Ensure it is not accidentally re-included.
2223
+ self .assertNotIn ("password_hash" , channel .json_body )
2224
+
2215
2225
@override_config ({"password_config" : {"enabled" : False }})
2216
2226
def test_reactivate_user_password_disabled (self ):
2217
2227
"""
@@ -2241,9 +2251,11 @@ def test_reactivate_user_password_disabled(self):
2241
2251
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
2242
2252
self .assertEqual ("@user:test" , channel .json_body ["name" ])
2243
2253
self .assertFalse (channel .json_body ["deactivated" ])
2244
- self .assertIsNone (channel .json_body ["password_hash" ])
2245
2254
self ._is_erased ("@user:test" , False )
2246
2255
2256
+ # This key was removed intentionally. Ensure it is not accidentally re-included.
2257
+ self .assertNotIn ("password_hash" , channel .json_body )
2258
+
2247
2259
def test_set_user_as_admin (self ):
2248
2260
"""
2249
2261
Test setting the admin flag on a user.
@@ -2328,7 +2340,7 @@ def test_accidental_deactivation_prevention(self):
2328
2340
Ensure an account can't accidentally be deactivated by using a str value
2329
2341
for the deactivated body parameter
2330
2342
"""
2331
- url = "/_synapse/admin/v2/users/ @bob:test"
2343
+ url = self . url_prefix % " @bob:test"
2332
2344
2333
2345
# Create user
2334
2346
channel = self .make_request (
@@ -2392,18 +2404,20 @@ def _deactivate_user(self, user_id: str) -> None:
2392
2404
# Deactivate the user.
2393
2405
channel = self .make_request (
2394
2406
"PUT" ,
2395
- "/_synapse/admin/v2/users/%s" % urllib .parse .quote (user_id ),
2407
+ self . url_prefix % urllib .parse .quote (user_id ),
2396
2408
access_token = self .admin_user_tok ,
2397
2409
content = {"deactivated" : True },
2398
2410
)
2399
2411
self .assertEqual (HTTPStatus .OK , channel .code , msg = channel .json_body )
2400
2412
self .assertTrue (channel .json_body ["deactivated" ])
2401
- self .assertIsNone (channel .json_body ["password_hash" ])
2402
2413
self ._is_erased (user_id , False )
2403
2414
d = self .store .mark_user_erased (user_id )
2404
2415
self .assertIsNone (self .get_success (d ))
2405
2416
self ._is_erased (user_id , True )
2406
2417
2418
+ # This key was removed intentionally. Ensure it is not accidentally re-included.
2419
+ self .assertNotIn ("password_hash" , channel .json_body )
2420
+
2407
2421
def _check_fields (self , content : JsonDict ):
2408
2422
"""Checks that the expected user attributes are present in content
2409
2423
@@ -2416,13 +2430,15 @@ def _check_fields(self, content: JsonDict):
2416
2430
self .assertIn ("admin" , content )
2417
2431
self .assertIn ("deactivated" , content )
2418
2432
self .assertIn ("shadow_banned" , content )
2419
- self .assertIn ("password_hash" , content )
2420
2433
self .assertIn ("creation_ts" , content )
2421
2434
self .assertIn ("appservice_id" , content )
2422
2435
self .assertIn ("consent_server_notice_sent" , content )
2423
2436
self .assertIn ("consent_version" , content )
2424
2437
self .assertIn ("external_ids" , content )
2425
2438
2439
+ # This key was removed intentionally. Ensure it is not accidentally re-included.
2440
+ self .assertNotIn ("password_hash" , content )
2441
+
2426
2442
2427
2443
class UserMembershipRestTestCase (unittest .HomeserverTestCase ):
2428
2444
0 commit comments