Skip to content

Commit

Permalink
Merge pull request #274 from borislaviv/master
Browse files Browse the repository at this point in the history
Expose ldap pool active parameter to limit retries
  • Loading branch information
etianen authored Jun 15, 2024
2 parents a21ca70 + b9b40bb commit 33dbd62
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Available settings
LDAP_AUTH_CONNECT_TIMEOUT = None
LDAP_AUTH_RECEIVE_TIMEOUT = None
# Set connection pool `active` parameter on the underlying `ldap3` library.
LDAP_AUTH_POOL_ACTIVE = True
Microsoft Active Directory support
----------------------------------
Expand Down
5 changes: 5 additions & 0 deletions django_python3_ldap/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,10 @@ def __init__(self, settings):
default=None
)

LDAP_AUTH_POOL_ACTIVE = LazySetting(
name="LDAP_AUTH_POOL_ACTIVE",
default=True
)


settings = LazySettings(settings)
6 changes: 5 additions & 1 deletion django_python3_ldap/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ def connection(**kwargs):
password = kwargs.pop("password")
username = format_username(kwargs)
# Build server pool
server_pool = ldap3.ServerPool(None, ldap3.RANDOM, active=True, exhaust=5)
server_pool = ldap3.ServerPool(
None, ldap3.RANDOM,
active=settings.LDAP_AUTH_POOL_ACTIVE,
exhaust=5
)
auth_url = settings.LDAP_AUTH_URL
if not isinstance(auth_url, list):
auth_url = [auth_url]
Expand Down
12 changes: 12 additions & 0 deletions django_python3_ldap/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ def testAuthenticateWithFailedRebind(self):
)
self.assertIs(user, None)

def testAuthenticateWithLimitedRetries(self):
# simulate offline server
with self.settings(
LDAP_AUTH_URL=["ldap://example.com:389"],
LDAP_AUTH_POOL_ACTIVE=1,
):
user = authenticate(
username=settings.LDAP_AUTH_TEST_USER_USERNAME,
password=settings.LDAP_AUTH_TEST_USER_PASSWORD,
)
self.assertEqual(user, None)

# User synchronisation.

def testSyncUsersCreatesUsers(self):
Expand Down

0 comments on commit 33dbd62

Please sign in to comment.