mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 01:14:21 +01:00
fix unit tests
This commit is contained in:
parent
7d55cb2d14
commit
2a4815e142
@ -29,6 +29,7 @@ class CaFileDontExist(Exception):
|
||||
self.cafile = cafile
|
||||
self.log = "CA file %(cafile)s don't exist" % {'cafile': cafile}
|
||||
|
||||
|
||||
NO_ATTR = 0
|
||||
DISPLAYED_ATTRS = 1
|
||||
LISTED_ATTRS = 2
|
||||
@ -69,6 +70,7 @@ AD_BUILTIN_GROUPS = [
|
||||
'Users',
|
||||
]
|
||||
|
||||
|
||||
class Backend(ldapcherry.backend.backendLdap.Backend):
|
||||
|
||||
def __init__(self, config, logger, name, attrslist, key):
|
||||
@ -77,8 +79,8 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
|
||||
self.backend_name = name
|
||||
self.domain = self.get_param('domain')
|
||||
self.login = self.get_param('login')
|
||||
basedn = 'dc=' + re.sub(r'\.',',DC=', self.domain)
|
||||
self.binddn = self.get_param('login') + '@' + self.domain
|
||||
basedn = 'dc=' + re.sub(r'\.', ',DC=', self.domain)
|
||||
self.binddn = self.get_param('login') + '@' + self.domain
|
||||
self.bindpassword = self.get_param('password')
|
||||
self.ca = self.get_param('ca', False)
|
||||
self.checkcert = self.get_param('checkcert', 'on')
|
||||
@ -86,11 +88,12 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
|
||||
self.uri = self.get_param('uri')
|
||||
self.timeout = self.get_param('timeout', 1)
|
||||
self.userdn = 'CN=Users,' + basedn
|
||||
self.groupdn = self.userdn
|
||||
self.groupdn = self.userdn
|
||||
self.builtin = 'CN=Builtin,' + basedn
|
||||
self.user_filter_tmpl = '(sAMAccountName=%(username)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.key = 'sAMAccountName'
|
||||
self.objectlasses = ['top', 'person', 'organizationalPerson', 'user']
|
||||
@ -118,9 +121,7 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
|
||||
ldap_client.unbind_s()
|
||||
return r
|
||||
|
||||
|
||||
def get_groups(self, username):
|
||||
|
||||
username = ldap.filter.escape_filter_chars(username)
|
||||
userdn = self._get_user(username, NO_ATTR)
|
||||
|
||||
@ -140,4 +141,3 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
|
||||
ret.append(self._uni(entry[0]['CN']))
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -82,9 +82,11 @@ ldap.objectclasses = 'top, person, organizationalPerson, user'
|
||||
ldap.dn_user_attr = 'uid'
|
||||
ldap.timeout = 1
|
||||
|
||||
ad.module = 'ldapcherry.backend.backendSamba4'
|
||||
ad.auth = 'Administrator'
|
||||
ad.password = 'password'
|
||||
ad.module = 'ldapcherry.backend.backendAD'
|
||||
ad.domain = 'dc.ldapcherry.org'
|
||||
ad.login = 'administrator'
|
||||
ad.password = 'qwertyP455'
|
||||
ad.uri = 'ldap://ldap.ldapcherry.org'
|
||||
|
||||
# authentification parameters
|
||||
[auth]
|
||||
|
@ -144,7 +144,7 @@ class TestError(object):
|
||||
|
||||
def testLogin(self):
|
||||
app = LdapCherry()
|
||||
loadconf('./tests/cfg/ldapcherry.ini', app)
|
||||
loadconf('./tests/cfg/ldapcherry_test.ini', app)
|
||||
try:
|
||||
app.login('jwatson', 'passwordwatson')
|
||||
except cherrypy.HTTPRedirect as e:
|
||||
@ -155,15 +155,46 @@ class TestError(object):
|
||||
|
||||
def testSearch(self):
|
||||
app = LdapCherry()
|
||||
loadconf('./tests/cfg/ldapcherry.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'}}
|
||||
loadconf('./tests/cfg/ldapcherry_test.ini', app)
|
||||
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')
|
||||
assert expected == ret
|
||||
|
||||
def testGetUser(self):
|
||||
app = LdapCherry()
|
||||
loadconf('./tests/cfg/ldapcherry.ini', app)
|
||||
expected = {'password': u'passwordsmith', 'cn': u'Sheri Smith', 'uid': u'ssmith', 'name': u'smith'}
|
||||
loadconf('./tests/cfg/ldapcherry_test.ini', app)
|
||||
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')
|
||||
assert expected == ret
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user