mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
LDAP: Restore an except clause and add test to cover it.
Most of the paths leading through this except clause were cut in73e8bba37"ldap auth: Reassure django_auth_ldap". The remaining one had no test coverage -- the case that leads to it had a narrow unit test, but no test had the exception actually propagate here. As a result, the clause was mistakenly cut, in commit8d7f961a6"LDAP: Remove now-impossible except clause.", which could lead to an uncaught exception in production. Restore the except clause, and add a test for it.
This commit is contained in:
@@ -2174,6 +2174,13 @@ class TestLDAP(ZulipTestCase):
|
|||||||
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)
|
||||||
|
|
||||||
|
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
|
||||||
|
def test_login_failure_when_domain_does_not_match(self):
|
||||||
|
# type: () -> None
|
||||||
|
with self.settings(LDAP_APPEND_DOMAIN='acme.com'):
|
||||||
|
user_profile = self.backend.authenticate(self.example_email("hamlet"), 'pass')
|
||||||
|
self.assertIs(user_profile, None)
|
||||||
|
|
||||||
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
|
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
|
||||||
def test_login_failure_due_to_wrong_subdomain(self):
|
def test_login_failure_due_to_wrong_subdomain(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
|||||||
@@ -433,10 +433,8 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase):
|
|||||||
return user_profile
|
return user_profile
|
||||||
except Realm.DoesNotExist:
|
except Realm.DoesNotExist:
|
||||||
return None
|
return None
|
||||||
# ZulipLDAPException subclasses _LDAPUser.AuthenticationFailed
|
except ZulipLDAPException:
|
||||||
# and thus will automatically be caught and return None via
|
return None
|
||||||
# django-auth-ldap's existing code, so we don't need to catch
|
|
||||||
# them here.
|
|
||||||
|
|
||||||
def get_or_create_user(self, username, ldap_user):
|
def get_or_create_user(self, username, ldap_user):
|
||||||
# type: (str, _LDAPUser) -> Tuple[UserProfile, bool]
|
# type: (str, _LDAPUser) -> Tuple[UserProfile, bool]
|
||||||
|
|||||||
Reference in New Issue
Block a user