1
0
This commit is contained in:
H. Shay
2022-04-27 15:34:11 -07:00
parent 301b9cdfcc
commit df621cbaa5
2 changed files with 14 additions and 10 deletions
+7 -4
View File
@@ -117,7 +117,7 @@ from synapse.types import (
UserInfo,
UserProfile,
create_requester,
map_username_to_mxid_localpart
map_username_to_mxid_localpart,
)
from synapse.util import Clock
from synapse.util.async_helpers import maybe_awaitable
@@ -574,7 +574,8 @@ class ModuleApi:
return username
return UserID(username, self._hs.hostname).to_string()
def normalize_username(self, username: Union[str, bytes]
def normalize_username(
self, username: Union[str, bytes], case_sensitive: bool = False
) -> str:
"""Map a username onto a string suitable for a MXID
@@ -582,11 +583,13 @@ class ModuleApi:
Args:
username: username to be mapped
case_sensitive: true if TEST and test should be mapped
onto different mxids
Returns:
string suitable for a mxid localpart
"""
return map_username_to_mxid_localpart(username)
"""
return map_username_to_mxid_localpart(username, case_sensitive)
async def get_profile_for_user(self, localpart: str) -> ProfileInfo:
"""Look up the profile info for the user with the given localpart.
+7 -6
View File
@@ -636,12 +636,13 @@ class ModuleApiTestCase(HomeserverTestCase):
)
def test_normalize_username(self) -> None:
username = "Haxxor"
username2 = "_leet"
username3 = "aNoThErTeSt"
self.assertEqual(self.module_api.normalize_username(username), "haxxor")
self.assertEqual(self.module_api.normalize_username(username2), "=5fleet")
self.assertEqual(self.module_api.normalize_username(username3), "anothertest")
username = "Haxxor"
username2 = "_leet"
username3 = "aNoThErTeSt"
self.assertEqual(self.module_api.normalize_username(username), "haxxor")
self.assertEqual(self.module_api.normalize_username(username2), "=5fleet")
self.assertEqual(self.module_api.normalize_username(username3), "anothertest")
class ModuleApiWorkerTestCase(BaseMultiWorkerStreamTestCase):
"""For testing ModuleApi functionality in a multi-worker setup"""