mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
ldap: Improve error message for username/LDAP domain mismatches.
This commit is contained in:
@@ -2274,7 +2274,7 @@ class TestLDAP(ZulipTestCase):
|
|||||||
def test_django_to_ldap_username_when_domain_does_not_match(self) -> None:
|
def test_django_to_ldap_username_when_domain_does_not_match(self) -> None:
|
||||||
backend = self.backend
|
backend = self.backend
|
||||||
email = self.example_email("hamlet")
|
email = self.example_email("hamlet")
|
||||||
with self.assertRaisesRegex(Exception, 'Username does not match LDAP domain.'):
|
with self.assertRaisesRegex(Exception, 'Email hamlet@zulip.com does not match LDAP domain acme.com.'):
|
||||||
with self.settings(LDAP_APPEND_DOMAIN='acme.com'):
|
with self.settings(LDAP_APPEND_DOMAIN='acme.com'):
|
||||||
backend.django_to_ldap_username(email)
|
backend.django_to_ldap_username(email)
|
||||||
|
|
||||||
|
|||||||
@@ -313,7 +313,8 @@ class ZulipLDAPAuthBackendBase(ZulipAuthMixin, LDAPBackend):
|
|||||||
def django_to_ldap_username(self, username: str) -> str:
|
def django_to_ldap_username(self, username: str) -> str:
|
||||||
if settings.LDAP_APPEND_DOMAIN:
|
if settings.LDAP_APPEND_DOMAIN:
|
||||||
if not username.endswith("@" + settings.LDAP_APPEND_DOMAIN):
|
if not username.endswith("@" + settings.LDAP_APPEND_DOMAIN):
|
||||||
raise ZulipLDAPExceptionOutsideDomain("Username does not match LDAP domain.")
|
raise ZulipLDAPExceptionOutsideDomain("Email %s does not match LDAP domain %s." % (
|
||||||
|
username, settings.LDAP_APPEND_DOMAIN))
|
||||||
return email_to_username(username)
|
return email_to_username(username)
|
||||||
return username
|
return username
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user