1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-12-22 21:00:04 +01:00

add passing attributes list to backend

This commit is contained in:
kakwa 2015-05-22 10:27:46 +02:00
parent ab8c380bb1
commit 3fe59e4349
4 changed files with 16 additions and 13 deletions

View File

@ -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:

View File

@ -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):

View File

@ -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

View File

@ -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