mirror of https://github.com/zulip/zulip.git
parent
005037830c
commit
a4afca7b73
|
@ -1876,6 +1876,21 @@ class TestLDAP(ZulipTestCase):
|
|||
with self.assertRaisesRegex(Exception, 'Realm has been deactivated'):
|
||||
backend.get_or_create_user(email, _LDAPUser())
|
||||
|
||||
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
|
||||
def test_get_or_create_user_when_realm_is_none(self):
|
||||
# type: () -> None
|
||||
class _LDAPUser(object):
|
||||
attrs = {'fn': ['Full Name'], 'sn': ['Short Name']}
|
||||
|
||||
ldap_user_attr_map = {'full_name': 'fn', 'short_name': 'sn'}
|
||||
|
||||
with self.settings(AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map):
|
||||
backend = self.backend
|
||||
email = 'nonexisting@zulip.com'
|
||||
backend._realm = None
|
||||
with self.assertRaisesRegex(Exception, 'Realm is None'):
|
||||
backend.get_or_create_user(email, _LDAPUser())
|
||||
|
||||
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
|
||||
def test_django_to_ldap_username_when_domain_does_not_match(self):
|
||||
# type: () -> None
|
||||
|
|
|
@ -440,6 +440,8 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase):
|
|||
raise ZulipLDAPException("LDAP Authentication is not enabled")
|
||||
return user_profile, False
|
||||
except UserProfile.DoesNotExist:
|
||||
if self._realm is None:
|
||||
raise ZulipLDAPException("Realm is None")
|
||||
# No need to check for an inactive user since they don't exist yet
|
||||
if self._realm.deactivated:
|
||||
raise ZulipLDAPException("Realm has been deactivated")
|
||||
|
|
Loading…
Reference in New Issue