1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-25 18:54:29 +01:00

fix unit tests

This commit is contained in:
kakwa 2015-07-26 09:26:04 +02:00
parent 7d55cb2d14
commit 2a4815e142
3 changed files with 48 additions and 15 deletions

View File

@ -29,6 +29,7 @@ class CaFileDontExist(Exception):
self.cafile = cafile self.cafile = cafile
self.log = "CA file %(cafile)s don't exist" % {'cafile': cafile} self.log = "CA file %(cafile)s don't exist" % {'cafile': cafile}
NO_ATTR = 0 NO_ATTR = 0
DISPLAYED_ATTRS = 1 DISPLAYED_ATTRS = 1
LISTED_ATTRS = 2 LISTED_ATTRS = 2
@ -69,6 +70,7 @@ AD_BUILTIN_GROUPS = [
'Users', 'Users',
] ]
class Backend(ldapcherry.backend.backendLdap.Backend): class Backend(ldapcherry.backend.backendLdap.Backend):
def __init__(self, config, logger, name, attrslist, key): def __init__(self, config, logger, name, attrslist, key):
@ -90,7 +92,8 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
self.builtin = 'CN=Builtin,' + basedn self.builtin = 'CN=Builtin,' + basedn
self.user_filter_tmpl = '(sAMAccountName=%(username)s)' self.user_filter_tmpl = '(sAMAccountName=%(username)s)'
self.group_filter_tmpl = '(uid=%(userdn)s)' self.group_filter_tmpl = '(uid=%(userdn)s)'
self.search_filter_tmpl = '(|(sAMAccountName=%(searchstring)s*)(sn=%(searchstring)s*)(cn=%(searchstring)s*))' self.search_filter_tmpl = '(|(sAMAccountName=%(searchstring)s*)' \
'(sn=%(searchstring)s*)(cn=%(searchstring)s*))'
self.dn_user_attr = 'cn' self.dn_user_attr = 'cn'
self.key = 'sAMAccountName' self.key = 'sAMAccountName'
self.objectlasses = ['top', 'person', 'organizationalPerson', 'user'] self.objectlasses = ['top', 'person', 'organizationalPerson', 'user']
@ -118,9 +121,7 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
ldap_client.unbind_s() ldap_client.unbind_s()
return r return r
def get_groups(self, username): def get_groups(self, username):
username = ldap.filter.escape_filter_chars(username) username = ldap.filter.escape_filter_chars(username)
userdn = self._get_user(username, NO_ATTR) userdn = self._get_user(username, NO_ATTR)
@ -140,4 +141,3 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
ret.append(self._uni(entry[0]['CN'])) ret.append(self._uni(entry[0]['CN']))
return ret return ret

View File

@ -82,9 +82,11 @@ ldap.objectclasses = 'top, person, organizationalPerson, user'
ldap.dn_user_attr = 'uid' ldap.dn_user_attr = 'uid'
ldap.timeout = 1 ldap.timeout = 1
ad.module = 'ldapcherry.backend.backendSamba4' ad.module = 'ldapcherry.backend.backendAD'
ad.auth = 'Administrator' ad.domain = 'dc.ldapcherry.org'
ad.password = 'password' ad.login = 'administrator'
ad.password = 'qwertyP455'
ad.uri = 'ldap://ldap.ldapcherry.org'
# authentification parameters # authentification parameters
[auth] [auth]

View File

@ -144,7 +144,7 @@ class TestError(object):
def testLogin(self): def testLogin(self):
app = LdapCherry() app = LdapCherry()
loadconf('./tests/cfg/ldapcherry.ini', app) loadconf('./tests/cfg/ldapcherry_test.ini', app)
try: try:
app.login('jwatson', 'passwordwatson') app.login('jwatson', 'passwordwatson')
except cherrypy.HTTPRedirect as e: except cherrypy.HTTPRedirect as e:
@ -155,15 +155,46 @@ class TestError(object):
def testSearch(self): def testSearch(self):
app = LdapCherry() app = LdapCherry()
loadconf('./tests/cfg/ldapcherry.ini', app) loadconf('./tests/cfg/ldapcherry_test.ini', app)
expected = {u'ssmith': {'password': u'passwordsmith', 'cn': u'Sheri Smith', 'name': u'smith', 'uid': u'ssmith'}, u'jsmith': {'password': u'passwordsmith', 'cn': u'John Smith', 'name': u'Smith', 'uid': u'jsmith'}} expected = {
u'ssmith': {
'password': u'passwordsmith',
'cn': u'Sheri Smith',
'name': u'smith',
'uid': u'ssmith',
'email': [u's.smith@example.com',
u'ssmith@example.com',
u'sheri.smith@example.com'
],
},
u'jsmith': {
'password': u'passwordsmith',
'cn': u'John Smith',
'name': u'Smith',
'uid': u'jsmith',
'email': [
'j.smith@example.com',
'jsmith@example.com',
'jsmith.smith@example.com'
],
}
}
ret = app._search('smith') ret = app._search('smith')
assert expected == ret assert expected == ret
def testGetUser(self): def testGetUser(self):
app = LdapCherry() app = LdapCherry()
loadconf('./tests/cfg/ldapcherry.ini', app) loadconf('./tests/cfg/ldapcherry_test.ini', app)
expected = {'password': u'passwordsmith', 'cn': u'Sheri Smith', 'uid': u'ssmith', 'name': u'smith'} expected = {
'password': u'passwordsmith',
'cn': u'Sheri Smith',
'uid': u'ssmith',
'name': u'smith',
'email': [u's.smith@example.com',
u'ssmith@example.com',
u'sheri.smith@example.com'
],
}
ret = app._get_user('ssmith') ret = app._get_user('ssmith')
assert expected == ret assert expected == ret