2015-05-22 20:07:09 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from __future__ import with_statement
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import sys
|
|
|
|
from sets import Set
|
|
|
|
from ldapcherry.backend.backendLdap import Backend
|
|
|
|
from ldapcherry import syslog_error
|
|
|
|
from ldapcherry.exceptions import *
|
|
|
|
import cherrypy
|
2015-05-26 00:34:56 +02:00
|
|
|
import logging
|
2015-05-22 20:07:09 +02:00
|
|
|
from ldap import SERVER_DOWN
|
|
|
|
|
|
|
|
cfg = {
|
2015-05-25 19:55:18 +02:00
|
|
|
'module' : 'ldapcherry.backend.ldap',
|
2015-05-27 22:00:15 +02:00
|
|
|
'groupdn' : 'ou=Groups,dc=example,dc=org',
|
2015-05-25 19:55:18 +02:00
|
|
|
'userdn' : 'ou=People,dc=example,dc=org',
|
|
|
|
'binddn' : 'cn=dnscherry,dc=example,dc=org',
|
|
|
|
'password' : 'password',
|
|
|
|
'uri' : 'ldap://ldap.ldapcherry.org:390',
|
|
|
|
'ca' : './tests/test_env/etc/ldapcherry/TEST-cacert.pem',
|
|
|
|
'starttls' : 'off',
|
|
|
|
'checkcert' : 'off',
|
|
|
|
'user_filter_tmpl' : '(uid=%(username)s)',
|
|
|
|
'group_filter_tmpl' : '(member=%(userdn)s)',
|
|
|
|
'search_filter_tmpl' : '(|(uid=%(searchstring)s*)(sn=%(searchstring)s*))',
|
2015-05-26 00:34:56 +02:00
|
|
|
'objectclasses' : 'top, person, organizationalPerson, simpleSecurityObject, posixAccount',
|
|
|
|
'dn_user_attr' : 'uid',
|
2015-05-22 20:07:09 +02:00
|
|
|
}
|
|
|
|
|
2015-05-26 00:34:56 +02:00
|
|
|
def syslog_error(msg='', context='',
|
|
|
|
severity=logging.INFO, traceback=False):
|
|
|
|
pass
|
|
|
|
|
2015-05-22 20:07:09 +02:00
|
|
|
cherrypy.log.error = syslog_error
|
|
|
|
attr = ['shéll', 'cn', 'uid', 'uidNumber', 'gidNumber', 'home', 'userPassword', 'givenName', 'email', 'sn']
|
|
|
|
|
2015-05-26 00:34:56 +02:00
|
|
|
cherrypy.log.error = syslog_error
|
|
|
|
|
2015-05-22 20:07:09 +02:00
|
|
|
inv = Backend(cfg, cherrypy.log, 'ldap', attr)
|
|
|
|
print inv.get_user('jwatson')
|
2015-05-27 22:00:15 +02:00
|
|
|
print inv.get_groups('jwatson')
|
|
|
|
print inv.search('smit')
|
2015-05-26 00:34:56 +02:00
|
|
|
user = {
|
|
|
|
'uid': 'test',
|
|
|
|
'sn': 'test',
|
|
|
|
'cn': 'test',
|
|
|
|
'userPassword': 'test',
|
|
|
|
'uidNumber': '42',
|
|
|
|
'gidNumber': '42',
|
|
|
|
'homeDirectory': '/home/test/'
|
|
|
|
}
|
|
|
|
inv.add_user(user)
|
2015-05-27 22:00:15 +02:00
|
|
|
print inv.get_user('test')
|
|
|
|
print inv.get_groups('test')
|
2015-05-26 00:34:56 +02:00
|
|
|
inv.del_user('test')
|