Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize username before interacting with Synapse #163

Merged
merged 6 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ldap_auth_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def check_auth(
return None

# Get full user id from localpart
user_id = self.account_handler.get_qualified_user_id(localpart)
user_id = self.account_handler.get_qualified_user_id(localpart.lower())
Copy link
Contributor

@squahtx squahtx May 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I still think it'd be cleaner to do
localpart = localpart.lower(), above once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally fair, I've changed it to reflect this.


# check if user with user_id exists
if await self.account_handler.check_user_exists(user_id):
Expand Down Expand Up @@ -223,7 +223,9 @@ async def check_auth(
mail = None

# Register the user
user_id = await self.register_user(localpart, display_name, mail)
user_id = await self.register_user(
localpart.lower(), display_name, mail
)

return user_id

Expand Down
9 changes: 9 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ def test_no_pwd(self):
)
self.assertFalse(result)

@defer.inlineCallbacks
def test_uppercase_username(self):
result = yield defer.ensureDeferred(
self.auth_provider.check_auth(
"BOB", "m.login.password", {"password": "secret"}
)
)
self.assertEqual(result, "@bob:test")


class LdapSearchTestCase(unittest.TestCase):
@defer.inlineCallbacks
Expand Down