Permalink
Browse files

Test check for uniqueness of results.

  • Loading branch information...
1 parent 6a4b262 commit 5630749836e5f2211e9b486e34ba4bdafbd57a83 @Cito committed Jul 3, 2014
Showing with 11 additions and 6 deletions.
  1. +3 −5 pyramid_ldap3/__init__.py
  2. +8 −1 pyramid_ldap3/tests.py
@@ -162,10 +162,8 @@ def authenticate(self, login, password):
result = search.execute(conn, login=login, password=password)
- if not result:
+ if not result or len(result) > 1:
return None
- if len(result) > 1:
- logger.debug('Non-unique result for login %r', login)
result = result[0]
login_dn = result[0]
@@ -175,8 +173,8 @@ def authenticate(self, login, password):
conn.bind()
conn.close()
except ldap3.LDAPException:
- logger.debug('Exception in authenticate with login %r',
- login, exc_info=True)
+ logger.debug('Exception in authenticate with login %r', login,
+ exc_info=True)
return None
return result
View
@@ -197,7 +197,7 @@ def test_authenticate_no_ldap_login_query(self):
inst = self._makeOne(None, manager)
self.assertRaises(ConfigurationError, inst.authenticate, None, None)
- def test_authenticate_search_returns_non_one_result(self):
+ def test_authenticate_search_returns_no_result(self):
manager = DummyManager()
registry = Dummy()
registry.ldap_login_query = DummySearch([])
@@ -218,6 +218,13 @@ def test_authenticate_search_returns_one_result(self):
inst = self._makeOne(registry, manager)
self.assertEqual(inst.authenticate(None, None), ('a', 'b'))
+ def test_authenticate_search_returns_multiple_results(self):
+ manager = DummyManager()
+ registry = Dummy()
+ registry.ldap_login_query = DummySearch([('a', 'b'), ('a', 'c')])
+ inst = self._makeOne(registry, manager)
+ self.assertTrue(inst.authenticate(None, None) is None)
+
def test_authenticate_search_bind_raises(self):
from pyramid_ldap3 import ldap3
manager = DummyManager([None, ldap3.LDAPException])

0 comments on commit 5630749

Please sign in to comment.