ldap: Improve error message for username/LDAP domain mismatches.

This commit is contained in:
Tim Abbott
2018-08-20 10:38:59 -07:00
parent f70b9a3eba
commit 3cfb2000cc
2 changed files with 3 additions and 2 deletions

View File

@@ -2274,7 +2274,7 @@ class TestLDAP(ZulipTestCase):
def test_django_to_ldap_username_when_domain_does_not_match(self) -> None:
backend = self.backend
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'):
backend.django_to_ldap_username(email)

View File

@@ -313,7 +313,8 @@ class ZulipLDAPAuthBackendBase(ZulipAuthMixin, LDAPBackend):
def django_to_ldap_username(self, username: str) -> str:
if 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 username