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:
|
except:
|
||||||
raise BackendModuleLoadingFail(module)
|
raise BackendModuleLoadingFail(module)
|
||||||
try:
|
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:
|
except MissingParameter as e:
|
||||||
raise e
|
raise e
|
||||||
except:
|
except:
|
||||||
|
@ -12,7 +12,7 @@ import ldapcherry.backend
|
|||||||
|
|
||||||
class Backend(ldapcherry.backend.Backend):
|
class Backend(ldapcherry.backend.Backend):
|
||||||
|
|
||||||
def __init__(self, config, logger, name):
|
def __init__(self, config, logger, name, attrslist):
|
||||||
self.config = config
|
self.config = config
|
||||||
self._logger = logger
|
self._logger = logger
|
||||||
self.backend_name = name
|
self.backend_name = name
|
||||||
@ -25,6 +25,7 @@ class Backend(ldapcherry.backend.Backend):
|
|||||||
self.userdn = self.get_param('userdn')
|
self.userdn = self.get_param('userdn')
|
||||||
self.groupdn = self.get_param('groupdn')
|
self.groupdn = self.get_param('groupdn')
|
||||||
self.user_filter_tmpl = self.get_param('user_filter_tmpl')
|
self.user_filter_tmpl = self.get_param('user_filter_tmpl')
|
||||||
|
self.attrlist = attrslist
|
||||||
|
|
||||||
def auth(self, username, password):
|
def auth(self, username, password):
|
||||||
|
|
||||||
|
@ -9,5 +9,5 @@ import ldapcherry.backend
|
|||||||
|
|
||||||
class Backend(ldapcherry.backend.Backend):
|
class Backend(ldapcherry.backend.Backend):
|
||||||
|
|
||||||
def __init__(self, config, logger, name):
|
def __init__(self, config, logger, name, attrslist):
|
||||||
pass
|
pass
|
||||||
|
@ -28,15 +28,16 @@ cfg = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cherrypy.log.error = syslog_error
|
cherrypy.log.error = syslog_error
|
||||||
|
attr = ['shell', 'cn', 'uid', 'uidNumber', 'gidNumber', 'home', 'userPassword', 'givenName', 'email', 'sn']
|
||||||
|
|
||||||
class TestError(object):
|
class TestError(object):
|
||||||
|
|
||||||
def testNominal(self):
|
def testNominal(self):
|
||||||
inv = Backend(cfg, cherrypy.log, 'ldap')
|
inv = Backend(cfg, cherrypy.log, 'ldap', attr)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def testConnect(self):
|
def testConnect(self):
|
||||||
inv = Backend(cfg, cherrypy.log, 'ldap')
|
inv = Backend(cfg, cherrypy.log, 'ldap', attr)
|
||||||
ldap = inv._connect()
|
ldap = inv._connect()
|
||||||
ldap.simple_bind_s(inv.binddn, inv.bindpassword)
|
ldap.simple_bind_s(inv.binddn, inv.bindpassword)
|
||||||
return True
|
return True
|
||||||
@ -45,7 +46,7 @@ class TestError(object):
|
|||||||
cfg2 = cfg.copy()
|
cfg2 = cfg.copy()
|
||||||
cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637'
|
cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637'
|
||||||
cfg2['checkcert'] = 'on'
|
cfg2['checkcert'] = 'on'
|
||||||
inv = Backend(cfg2, cherrypy.log, 'ldap')
|
inv = Backend(cfg2, cherrypy.log, 'ldap', attr)
|
||||||
ldap = inv._connect()
|
ldap = inv._connect()
|
||||||
ldap.simple_bind_s(inv.binddn, inv.bindpassword)
|
ldap.simple_bind_s(inv.binddn, inv.bindpassword)
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ class TestError(object):
|
|||||||
cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637'
|
cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637'
|
||||||
cfg2['checkcert'] = 'on'
|
cfg2['checkcert'] = 'on'
|
||||||
cfg2['ca'] = './cfg/wrong_ca.crt'
|
cfg2['ca'] = './cfg/wrong_ca.crt'
|
||||||
inv = Backend(cfg2, cherrypy.log, 'ldap')
|
inv = Backend(cfg2, cherrypy.log, 'ldap', attr)
|
||||||
ldapc = inv._connect()
|
ldapc = inv._connect()
|
||||||
try:
|
try:
|
||||||
ldapc.simple_bind_s(inv.binddn, inv.bindpassword)
|
ldapc.simple_bind_s(inv.binddn, inv.bindpassword)
|
||||||
@ -65,21 +66,21 @@ class TestError(object):
|
|||||||
# cfg2 = cfg.copy()
|
# cfg2 = cfg.copy()
|
||||||
# cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637'
|
# cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637'
|
||||||
# cfg2['checkcert'] = 'off'
|
# cfg2['checkcert'] = 'off'
|
||||||
# inv = Backend(cfg2, cherrypy.log, 'ldap')
|
# inv = Backend(cfg2, cherrypy.log, 'ldap', attr)
|
||||||
# ldap = inv._connect()
|
# ldap = inv._connect()
|
||||||
# ldap.simple_bind_s(inv.binddn, inv.bindpassword)
|
# ldap.simple_bind_s(inv.binddn, inv.bindpassword)
|
||||||
|
|
||||||
def testAuthSuccess(self):
|
def testAuthSuccess(self):
|
||||||
inv = Backend(cfg, cherrypy.log, 'ldap')
|
inv = Backend(cfg, cherrypy.log, 'ldap', attr)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def testAuthSuccess(self):
|
def testAuthSuccess(self):
|
||||||
inv = Backend(cfg, cherrypy.log, 'ldap')
|
inv = Backend(cfg, cherrypy.log, 'ldap', attr)
|
||||||
ret = inv.auth('jwatson', 'passwordwatson')
|
ret = inv.auth('jwatson', 'passwordwatson')
|
||||||
assert ret == True
|
assert ret == True
|
||||||
|
|
||||||
def testAuthFailure(self):
|
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')
|
res = inv.auth('notauser', 'password') or inv.auth('jwatson', 'notapassword')
|
||||||
assert res == False
|
assert res == False
|
||||||
|
|
||||||
@ -87,12 +88,12 @@ class TestError(object):
|
|||||||
cfg2 = {}
|
cfg2 = {}
|
||||||
return True
|
return True
|
||||||
try:
|
try:
|
||||||
inv = Backend(cfg2, cherrypy.log, 'ldap')
|
inv = Backend(cfg2, cherrypy.log, 'ldap', attr)
|
||||||
except MissingKey:
|
except MissingKey:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
raise AssertionError("expected an exception")
|
raise AssertionError("expected an exception")
|
||||||
|
|
||||||
def testGetUser(self):
|
def testGetUser(self):
|
||||||
inv = Backend(cfg, cherrypy.log, 'ldap')
|
inv = Backend(cfg, cherrypy.log, 'ldap', attr)
|
||||||
return True
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user