Skip to content
Snippets Groups Projects
Commit 8cdadd69 authored by Julian's avatar Julian
Browse files

handle LDAPPasswordIsMandatoryError in user_conn, closes #27

parent 54c98455
No related branches found
No related tags found
No related merge requests found
......@@ -75,7 +75,6 @@ class TestSession(UffdTestCase):
self.assertEqual(r.status_code, 200)
self.assertLogout()
@unittest.skip('See #27')
def test_empty_password(self):
r = self.client.post(path=url_for('session.login'),
data={'loginname': 'testuser', 'password': ''}, follow_redirects=True)
......
......@@ -2,7 +2,7 @@ import string
from flask import Blueprint, current_app
from ldap3.utils.conv import escape_filter_chars
from ldap3.core.exceptions import LDAPBindError, LDAPCursorError
from ldap3.core.exceptions import LDAPBindError, LDAPCursorError, LDAPPasswordIsMandatoryError
from ldap3 import Server, Connection, ALL, ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES, MOCK_SYNC
......@@ -45,13 +45,16 @@ def user_conn(loginname, password):
# implementation just compares the string in the objects's userPassword
# field with the password, no support for hashing or OpenLDAP-style
# password-prefixes ("{PLAIN}..." or "{ssha512}...").
if not conn.rebind(loginname_to_dn(loginname), password):
try:
if not conn.rebind(loginname_to_dn(loginname), password):
return False
except (LDAPBindError, LDAPPasswordIsMandatoryError):
return False
return get_mock_conn()
server = Server(current_app.config["LDAP_SERVICE_URL"], get_info=ALL)
try:
return fix_connection(Connection(server, loginname_to_dn(loginname), password, auto_bind=True))
except LDAPBindError:
except (LDAPBindError, LDAPPasswordIsMandatoryError):
return False
def get_conn():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment