summary refs log tree commit diff
path: root/tests/handlers
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2022-05-18 11:28:14 +0100
committerGitHub <noreply@github.com>2022-05-18 11:28:14 +0100
commitd4713d3e335b21d12284ddd8ebd00e38abcfd521 (patch)
treeca02237e04ac9f1139a52e36c7c169e82d7b8cdf /tests/handlers
parentMake handling of federation Authorization header (more) compliant with RFC723... (diff)
downloadsynapse-d4713d3e335b21d12284ddd8ebd00e38abcfd521.tar.xz
Discard null-containing strings before updating the user directory (#12762)
Diffstat (limited to 'tests/handlers')
-rw-r--r--tests/handlers/test_user_directory.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/handlers/test_user_directory.py b/tests/handlers/test_user_directory.py
index 96e2e3039b..4d658d29ca 100644
--- a/tests/handlers/test_user_directory.py
+++ b/tests/handlers/test_user_directory.py
@@ -1007,6 +1007,34 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase):
         self.assertEqual(in_public, {(bob, room1), (bob, room2)})
         self.assertEqual(in_private, set())
 
+    def test_ignore_display_names_with_null_codepoints(self) -> None:
+        MXC_DUMMY = "mxc://dummy"
+
+        # Alice creates a public room.
+        alice = self.register_user("alice", "pass")
+
+        # Alice has a user directory entry to start with.
+        self.assertIn(
+            alice,
+            self.get_success(self.user_dir_helper.get_profiles_in_user_directory()),
+        )
+
+        # Alice changes her name to include a null codepoint.
+        self.get_success(
+            self.hs.get_user_directory_handler().handle_local_profile_change(
+                alice,
+                ProfileInfo(
+                    display_name="abcd\u0000efgh",
+                    avatar_url=MXC_DUMMY,
+                ),
+            )
+        )
+        # Alice's profile should be updated with the new avatar, but no display name.
+        self.assertEqual(
+            self.get_success(self.user_dir_helper.get_profiles_in_user_directory()),
+            {alice: ProfileInfo(display_name=None, avatar_url=MXC_DUMMY)},
+        )
+
 
 class TestUserDirSearchDisabled(unittest.HomeserverTestCase):
     servlets = [