LDAP: Restore an except clause and add test to cover it.

Most of the paths leading through this except clause were cut in
73e8bba37 "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 commit
8d7f961a6 "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:
Greg Price
2017-09-27 12:30:53 -07:00
parent f22daeba1a
commit f129dc4f72
2 changed files with 9 additions and 4 deletions

View File

@@ -433,10 +433,8 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase):
return user_profile
except Realm.DoesNotExist:
return None
# ZulipLDAPException subclasses _LDAPUser.AuthenticationFailed
# and thus will automatically be caught and return None via
# django-auth-ldap's existing code, so we don't need to catch
# them here.
except ZulipLDAPException:
return None
def get_or_create_user(self, username, ldap_user):
# type: (str, _LDAPUser) -> Tuple[UserProfile, bool]