Have LDAP return a better error message if it fails to connect

Currently, the error results in a 500 being raised when a user tries to login.
This commit is contained in:
Joseph Schorr 2015-06-12 15:39:55 -04:00
parent 4aae3b870a
commit e7915baf8c
2 changed files with 35 additions and 9 deletions

View file

@ -85,6 +85,24 @@ class TestLDAP(unittest.TestCase):
finished_database_for_testing(self)
self.ctx.__exit__(True, None, None)
def test_invalid_admin_password(self):
base_dn = ['dc=quay', 'dc=io']
admin_dn = 'uid=testy,ou=employees,dc=quay,dc=io'
admin_passwd = 'INVALIDPASSWORD'
user_rdn = ['ou=employees']
uid_attr = 'uid'
email_attr = 'mail'
ldap = LDAPUsers('ldap://localhost', base_dn, admin_dn, admin_passwd, user_rdn,
uid_attr, email_attr)
self.ldap = ldap
# Try to login.
(response, err_msg) = self.ldap.verify_user('someuser', 'somepass')
self.assertIsNone(response)
self.assertEquals('LDAP Admin dn or password is invalid', err_msg)
def test_login(self):
# Verify we can login.
(response, _) = self.ldap.verify_user('someuser', 'somepass')