Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ldap pool active parameter to limit retries #274

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading