From 3fe59e43496db0a789a6f3a0fbde357199c5b919 Mon Sep 17 00:00:00 2001 From: kakwa Date: Fri, 22 May 2015 10:27:46 +0200 Subject: [PATCH] add passing attributes list to backend --- ldapcherry/__init__.py | 3 ++- ldapcherry/backend/backendLdap.py | 3 ++- ldapcherry/backend/backendSamba4.py | 2 +- tests/test_BackendLdap.py | 21 +++++++++++---------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index 2390c12..a263ec7 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -107,7 +107,8 @@ class LdapCherry(object): except: raise BackendModuleLoadingFail(module) try: - self.backends[backend] = bc.Backend(params, cherrypy.log, backend) + attrslist = self.attributes.get_backend_attributes(backend) + self.backends[backend] = bc.Backend(params, cherrypy.log, backend, attrslist) except MissingParameter as e: raise e except: diff --git a/ldapcherry/backend/backendLdap.py b/ldapcherry/backend/backendLdap.py index 241cd29..f7f150f 100644 --- a/ldapcherry/backend/backendLdap.py +++ b/ldapcherry/backend/backendLdap.py @@ -12,7 +12,7 @@ import ldapcherry.backend class Backend(ldapcherry.backend.Backend): - def __init__(self, config, logger, name): + def __init__(self, config, logger, name, attrslist): self.config = config self._logger = logger self.backend_name = name @@ -25,6 +25,7 @@ class Backend(ldapcherry.backend.Backend): self.userdn = self.get_param('userdn') self.groupdn = self.get_param('groupdn') self.user_filter_tmpl = self.get_param('user_filter_tmpl') + self.attrlist = attrslist def auth(self, username, password): diff --git a/ldapcherry/backend/backendSamba4.py b/ldapcherry/backend/backendSamba4.py index 3c56935..6f961d5 100644 --- a/ldapcherry/backend/backendSamba4.py +++ b/ldapcherry/backend/backendSamba4.py @@ -9,5 +9,5 @@ import ldapcherry.backend class Backend(ldapcherry.backend.Backend): - def __init__(self, config, logger, name): + def __init__(self, config, logger, name, attrslist): pass diff --git a/tests/test_BackendLdap.py b/tests/test_BackendLdap.py index 177cc8d..3e56785 100644 --- a/tests/test_BackendLdap.py +++ b/tests/test_BackendLdap.py @@ -28,15 +28,16 @@ cfg = { } cherrypy.log.error = syslog_error +attr = ['shell', 'cn', 'uid', 'uidNumber', 'gidNumber', 'home', 'userPassword', 'givenName', 'email', 'sn'] class TestError(object): def testNominal(self): - inv = Backend(cfg, cherrypy.log, 'ldap') + inv = Backend(cfg, cherrypy.log, 'ldap', attr) return True def testConnect(self): - inv = Backend(cfg, cherrypy.log, 'ldap') + inv = Backend(cfg, cherrypy.log, 'ldap', attr) ldap = inv._connect() ldap.simple_bind_s(inv.binddn, inv.bindpassword) return True @@ -45,7 +46,7 @@ class TestError(object): cfg2 = cfg.copy() cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637' cfg2['checkcert'] = 'on' - inv = Backend(cfg2, cherrypy.log, 'ldap') + inv = Backend(cfg2, cherrypy.log, 'ldap', attr) ldap = inv._connect() ldap.simple_bind_s(inv.binddn, inv.bindpassword) @@ -54,7 +55,7 @@ class TestError(object): cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637' cfg2['checkcert'] = 'on' cfg2['ca'] = './cfg/wrong_ca.crt' - inv = Backend(cfg2, cherrypy.log, 'ldap') + inv = Backend(cfg2, cherrypy.log, 'ldap', attr) ldapc = inv._connect() try: ldapc.simple_bind_s(inv.binddn, inv.bindpassword) @@ -65,21 +66,21 @@ class TestError(object): # cfg2 = cfg.copy() # cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637' # cfg2['checkcert'] = 'off' -# inv = Backend(cfg2, cherrypy.log, 'ldap') +# inv = Backend(cfg2, cherrypy.log, 'ldap', attr) # ldap = inv._connect() # ldap.simple_bind_s(inv.binddn, inv.bindpassword) def testAuthSuccess(self): - inv = Backend(cfg, cherrypy.log, 'ldap') + inv = Backend(cfg, cherrypy.log, 'ldap', attr) return True def testAuthSuccess(self): - inv = Backend(cfg, cherrypy.log, 'ldap') + inv = Backend(cfg, cherrypy.log, 'ldap', attr) ret = inv.auth('jwatson', 'passwordwatson') assert ret == True def testAuthFailure(self): - inv = Backend(cfg, cherrypy.log, 'ldap') + inv = Backend(cfg, cherrypy.log, 'ldap', attr) res = inv.auth('notauser', 'password') or inv.auth('jwatson', 'notapassword') assert res == False @@ -87,12 +88,12 @@ class TestError(object): cfg2 = {} return True try: - inv = Backend(cfg2, cherrypy.log, 'ldap') + inv = Backend(cfg2, cherrypy.log, 'ldap', attr) except MissingKey: return else: raise AssertionError("expected an exception") def testGetUser(self): - inv = Backend(cfg, cherrypy.log, 'ldap') + inv = Backend(cfg, cherrypy.log, 'ldap', attr) return True