From 97cbdf814dd7405ddc3a5ad372b3c9e81f1f12dd Mon Sep 17 00:00:00 2001 From: Sven Haardiek Date: Fri, 16 Jun 2023 15:56:37 +0200 Subject: [PATCH] =?UTF-8?q?Add=20tests=20f=C3=BCr=20ldap=20connection=20co?= =?UTF-8?q?nfiguration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds tests to check the configuration of the ldap connection. Signed-off-by: Sven Haardiek --- .../test_ldap_attribute_store.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/satosa/micro_services/test_ldap_attribute_store.py b/tests/satosa/micro_services/test_ldap_attribute_store.py index e3af1a7f5..26dc3b9fb 100644 --- a/tests/satosa/micro_services/test_ldap_attribute_store.py +++ b/tests/satosa/micro_services/test_ldap_attribute_store.py @@ -2,6 +2,8 @@ from copy import deepcopy +from ldap3 import AUTO_BIND_NO_TLS, MOCK_SYNC + from satosa.internal import AuthenticationInformation from satosa.internal import InternalData from satosa.micro_services.ldap_attribute_store import LdapAttributeStore @@ -107,3 +109,60 @@ def test_attributes_general(self, ldap_attribute_store): internal_attr = ldap_to_internal_map[ldap_attr] response_attr = response.attributes[internal_attr] assert(ldap_value in response_attr) + + @pytest.mark.parametrize( + 'config,connection_attributes', + [ + ( + { + 'auto_bind': 'AUTO_BIND_NO_TLS', + 'client_strategy': 'MOCK_SYNC', + 'ldap_url': 'ldap://satosa.example.com', + 'bind_dn': 'uid=readonly_user,ou=system,dc=example,dc=com', + 'bind_password': 'password', + }, + { + 'user': 'uid=readonly_user,ou=system,dc=example,dc=com', + 'password': 'password', + 'auto_bind': AUTO_BIND_NO_TLS, + 'strategy_type': MOCK_SYNC, + 'read_only': True, + 'version': 3, + 'pool_size': 10, + 'pool_keepalive': 10, + 'pool_lifetime': None, + }, + ), + ( + { + 'auto_bind': 'AUTO_BIND_NO_TLS', + 'client_strategy': 'MOCK_SYNC', + 'ldap_url': 'ldap://satosa.example.com', + 'bind_dn': 'uid=readonly_user,ou=system,dc=example,dc=com', + 'bind_password': 'password', + 'pool_size': 40, + 'pool_keepalive': 41, + 'pool_lifetime': 42, + }, + { + 'user': 'uid=readonly_user,ou=system,dc=example,dc=com', + 'password': 'password', + 'auto_bind': AUTO_BIND_NO_TLS, + 'strategy_type': MOCK_SYNC, + 'read_only': True, + 'version': 3, + 'pool_size': 40, + 'pool_keepalive': 41, + 'pool_lifetime': 42, + }, + ), + ] + ) + def test_connection_config(self, config, connection_attributes): + ldapAttributeStore = LdapAttributeStore({'default': config}, + name="test_ldap_attribute_store", + base_url="https://satosa.example.com") + connection = ldapAttributeStore.config['default']['connection'] + + for k, v in connection_attributes.items(): + assert getattr(connection, k) == v