mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 09:24:21 +01:00
add passing attributes list to backend
This commit is contained in:
parent
ab8c380bb1
commit
3fe59e4349
@ -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:
|
||||
|
@ -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):
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user