summary refs log tree commit diff
path: root/tests/rest/admin/test_user.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2024-01-16 16:11:23 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2024-01-16 16:11:23 +0000
commit2927008e48ecb6ea5d24e622d7b2fffe94c45c44 (patch)
tree2bb081f43a6105f926cb99c10a6ce1674d08f9cb /tests/rest/admin/test_user.py
parentRevert changes to README (diff)
parentFix text and add second link (diff)
downloadsynapse-2927008e48ecb6ea5d24e622d7b2fffe94c45c44.tar.xz
Merge branch 'release-v1.99'
Diffstat (limited to 'tests/rest/admin/test_user.py')
-rw-r--r--tests/rest/admin/test_user.py80
1 files changed, 62 insertions, 18 deletions
diff --git a/tests/rest/admin/test_user.py b/tests/rest/admin/test_user.py
index cf71bbb461..61cbac2332 100644
--- a/tests/rest/admin/test_user.py
+++ b/tests/rest/admin/test_user.py
@@ -1,16 +1,22 @@
-# Copyright 2018-2022 The Matrix.org Foundation C.I.C.
 #
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# This file is licensed under the Affero General Public License (AGPL) version 3.
+#
+# Copyright (C) 2023 New Vector, Ltd
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# See the GNU Affero General Public License for more details:
+# <https://www.gnu.org/licenses/agpl-3.0.html>.
+#
+# Originally licensed under the Apache License, Version 2.0:
+# <http://www.apache.org/licenses/LICENSE-2.0>.
+#
+# [This file includes modifications made by New Vector Limited]
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 import hashlib
 import hmac
@@ -1632,8 +1638,17 @@ class UserRestTestCase(unittest.HomeserverTestCase):
             )
         )
 
+        self.non_ascii_displayname = "ąćęłńóśżźäöüß中国日本"
+        self.non_ascii_user = self.register_user(
+            "nonascii", "nonascii", displayname=self.non_ascii_displayname
+        )
+
         self.url_prefix = "/_synapse/admin/v2/users/%s"
         self.url_other_user = self.url_prefix % self.other_user
+        self.url_non_ascii_user = (
+            "/_synapse/admin/v2/users?name=%s"
+            % urllib.parse.quote(self.non_ascii_displayname)
+        )
 
     def test_requester_is_no_admin(self) -> None:
         """
@@ -1784,6 +1799,20 @@ class UserRestTestCase(unittest.HomeserverTestCase):
         self.assertEqual("User", channel.json_body["displayname"])
         self._check_fields(channel.json_body)
 
+    def test_get_user_nonascii_displayname(self) -> None:
+        """
+        Test get user by non-ascii display name
+        """
+        channel = self.make_request(
+            "GET",
+            self.url_non_ascii_user,
+            access_token=self.admin_user_tok,
+        )
+
+        users = {user["name"]: user for user in channel.json_body["users"]}
+        self.assertEqual(200, channel.code, msg=channel.json_body)
+        self.assertIn(self.non_ascii_user, users, channel.json_body["users"])
+
     def test_create_server_admin(self) -> None:
         """
         Check that a new admin user is created successfully.
@@ -2741,7 +2770,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
         profile = self.get_success(self.store._get_user_in_directory(self.other_user))
         self.assertIsNone(profile)
 
-    def test_reactivate_user(self) -> None:
+    def test_reactivate_user_with_password(self) -> None:
         """
         Test reactivating another user.
         """
@@ -2749,21 +2778,36 @@ class UserRestTestCase(unittest.HomeserverTestCase):
         # Deactivate the user.
         self._deactivate_user("@user:test")
 
-        # Attempt to reactivate the user (without a password).
+        # Reactivate the user with password.
         channel = self.make_request(
             "PUT",
             self.url_other_user,
             access_token=self.admin_user_tok,
-            content={"deactivated": False},
+            content={"deactivated": False, "password": "foo"},
         )
-        self.assertEqual(400, channel.code, msg=channel.json_body)
+        self.assertEqual(200, channel.code, msg=channel.json_body)
+        self.assertEqual("@user:test", channel.json_body["name"])
+        self.assertFalse(channel.json_body["deactivated"])
+        self._is_erased("@user:test", False)
+
+        # This key was removed intentionally. Ensure it is not accidentally re-included.
+        self.assertNotIn("password_hash", channel.json_body)
 
-        # Reactivate the user.
+    def test_reactivate_user_without_password(self) -> None:
+        """
+        Test reactivating another user without a password.
+        This can be using some local users and some user with SSO (password = `null`).
+        """
+
+        # Deactivate the user.
+        self._deactivate_user("@user:test")
+
+        # Reactivate the user without a password.
         channel = self.make_request(
             "PUT",
             self.url_other_user,
             access_token=self.admin_user_tok,
-            content={"deactivated": False, "password": "foo"},
+            content={"deactivated": False},
         )
         self.assertEqual(200, channel.code, msg=channel.json_body)
         self.assertEqual("@user:test", channel.json_body["name"])
@@ -2782,7 +2826,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
         # Deactivate the user.
         self._deactivate_user("@user:test")
 
-        # Reactivate the user with a password
+        # Reactivate the user with a password.
         channel = self.make_request(
             "PUT",
             self.url_other_user,
@@ -2816,7 +2860,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
         # Deactivate the user.
         self._deactivate_user("@user:test")
 
-        # Reactivate the user with a password
+        # Reactivate the user with a password.
         channel = self.make_request(
             "PUT",
             self.url_other_user,