diff --git a/accounts/tests/test_ldap_timeouts.py b/accounts/tests/test_ldap_timeouts.py new file mode 100644 index 00000000..c51ec17b --- /dev/null +++ b/accounts/tests/test_ldap_timeouts.py @@ -0,0 +1,20 @@ +"""A login through LDAP waits a bounded time for the directory.""" + +import unittest + +from django.test import SimpleTestCase + +try: + import ldap + from django_auth_ldap.backend import LDAPBackend +except ImportError: # LDAP is optional (conf/requirements-ldap.txt) + ldap = None + + +@unittest.skipIf(ldap is None, "python-ldap is not installed") +class LdapTimeoutTests(SimpleTestCase): + def test_the_connection_and_each_answer_have_a_timeout(self): + # python-ldap's default for both is to wait without end + options = LDAPBackend().settings.CONNECTION_OPTIONS + self.assertGreater(options.get(ldap.OPT_NETWORK_TIMEOUT, -1), 0) + self.assertGreater(options.get(ldap.OPT_TIMEOUT, -1), 0) diff --git a/webvirtcloud/settings.py.template b/webvirtcloud/settings.py.template index 788fbfb3..d5fe1da7 100644 --- a/webvirtcloud/settings.py.template +++ b/webvirtcloud/settings.py.template @@ -411,6 +411,8 @@ if HAS_LDAP: AUTH_LDAP_SERVER_URI = "ldap://example.com" AUTH_LDAP_BIND_DN = "username@example.com" AUTH_LDAP_BIND_PASSWORD = "password" + # seconds to connect and for each answer: python-ldap waits for a server without end + AUTH_LDAP_CONNECTION_OPTIONS = {ldap.OPT_NETWORK_TIMEOUT: 5, ldap.OPT_TIMEOUT: 10} AUTH_LDAP_USER_SEARCH = LDAPSearch( "CN=Users,DC=example,DC=com", ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)" )