Пример #1
0
 def testConnectSSL(self):
     cfg2 = cfg.copy()
     cfg2['uri'] = 'ldaps://ldap.dnscherry.org:637'
     cfg2['checkcert'] = 'on'
     inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
     ldap = inv._connect()
     ldap.simple_bind_s(inv.binddn, inv.bindpassword)
Пример #2
0
 def testConnectSSL(self):
     cfg2 = cfg.copy()
     cfg2['uri'] = 'ldaps://ldap.dnscherry.org:637'
     cfg2['checkcert'] = 'on'
     inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
     ldap = inv._connect()
     ldap.simple_bind_s(inv.binddn, inv.bindpassword)
Пример #3
0
 def testConnectStartTLS(self):
     cfg2 = cfg.copy()
     cfg2['uri'] = 'ldap://ldap.ldapcherry.org:390'
     cfg2['checkcert'] = 'off'
     cfg2['starttls'] = 'on'
     cfg2['ca'] = './test/cfg/ca.crt'
     inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
     ldapc = inv._connect()
     ldapc.simple_bind_s(inv.binddn, inv.bindpassword)
Пример #4
0
 def testDelUserDontExists(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     try:
         inv.del_user(u'test☭')
         inv.del_user(u'test☭')
     except UserDoesntExist:
         return
     else:
         raise AssertionError("expected an exception")
Пример #5
0
 def testDelUserDontExists(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     try:
         inv.del_user(u'test☭')
         inv.del_user(u'test☭')
     except UserDoesntExist:
         return
     else:
         raise AssertionError("expected an exception")
Пример #6
0
 def testConnectStartTLS(self):
     cfg2 = cfg.copy()
     cfg2['uri'] = 'ldap://ldap.ldapcherry.org:390'
     cfg2['checkcert'] = 'off'
     cfg2['starttls'] = 'on'
     cfg2['ca'] = './test/cfg/ca.crt'
     inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
     ldapc = inv._connect()
     ldapc.simple_bind_s(inv.binddn, inv.bindpassword)
Пример #7
0
 def testMissingCA(self):
     cfg2 = cfg.copy()
     cfg2['uri'] = 'ldaps://ldap.dnscherry.org:637'
     cfg2['checkcert'] = 'on'
     cfg2['ca'] = './test/cfg/not_a_ca.crt'
     try:
         inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
         ldapc = inv._connect()
     except CaFileDontExist as e:
         return
     else:
         raise AssertionError("expected an exception")
Пример #8
0
 def testConnectSSLWrongCA(self):
     cfg2 = cfg.copy()
     cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637'
     cfg2['checkcert'] = 'on'
     inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
     ldapc = inv._connect()
     try:
         ldapc.simple_bind_s(inv.binddn, inv.bindpassword)
     except ldap.SERVER_DOWN as e:
         assert e[0]['info'] == 'TLS: hostname does not match CN in peer certificate'
     else:
         raise AssertionError("expected an exception")
Пример #9
0
 def testLdapUnavaible(self):
     cfg2 = cfg.copy()
     cfg2['uri'] = 'ldaps://notaldap:637'
     cfg2['checkcert'] = 'on'
     inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
     try:
         ldapc = inv._connect()
         ldapc.simple_bind_s(inv.binddn, inv.bindpassword)
     except ldap.SERVER_DOWN as e:
         return
     else:
         raise AssertionError("expected an exception")
Пример #10
0
 def testMissingCA(self):
     cfg2 = cfg.copy()
     cfg2['uri'] = 'ldaps://ldap.dnscherry.org:637'
     cfg2['checkcert'] = 'on'
     cfg2['ca'] = './test/cfg/not_a_ca.crt'
     try:
         inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
         ldapc = inv._connect()
     except CaFileDontExist as e:
         return
     else:
         raise AssertionError("expected an exception")
Пример #11
0
 def testLdapUnavaible(self):
     cfg2 = cfg.copy()
     cfg2['uri'] = 'ldaps://notaldap:637'
     cfg2['checkcert'] = 'on'
     inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
     try:
         ldapc = inv._connect()
         ldapc.simple_bind_s(inv.binddn, inv.bindpassword)
     except ldap.SERVER_DOWN as e:
         return
     else:
         raise AssertionError("expected an exception")
Пример #12
0
 def testConnectSSLWrongCA(self):
     cfg2 = cfg.copy()
     cfg2['uri'] = 'ldaps://ldap.ldapcherry.org:637'
     cfg2['checkcert'] = 'on'
     inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
     ldapc = inv._connect()
     try:
         ldapc.simple_bind_s(inv.binddn, inv.bindpassword)
     except ldap.SERVER_DOWN as e:
         assert e[0]['info'] == 'TLS: hostname does not match CN in peer certificate'
     else:
         raise AssertionError("expected an exception")
Пример #13
0
 def testGetUser(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ret = inv.get_user(u'jwatsoné')
     expected = {
         'uid': u'jwatsoné',
         'objectClass': 'inetOrgPerson',
         'carLicense': 'HERCAR 125',
         'sn': 'watson',
         'mail': '*****@*****.**',
         'homePhone': '555-111-2225',
         'cn': 'John Watson',
         'userPassword': u'passwordwatsoné'
     }
     assert ret == expected
Пример #14
0
 def testAddUserMissingMustattribute(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     user = {
     'uid': u'test☭',
     'sn':  u'test☭',
     'cn':  u'test☭',
     'userPassword': u'test☭',
     'gidNumber': '42',
     'homeDirectory': '/home/test/'
     }
     try:
         inv.add_user(user)
     except ldap.OBJECT_CLASS_VIOLATION:
         return
     else:
         inv.del_user(u'test☭')
         raise AssertionError("expected an exception")
Пример #15
0
 def testAddUser(self):
     try:
         inv.del_user(u'test☭,cn=')
     except:
         pass
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     user = {
     'uid': u'test☭,cn=',
     'sn':  u'test☭',
     'cn':  u'test☭',
     'userPassword': u'test☭',
     'uidNumber': '42',
     'gidNumber': '42',
     'homeDirectory': '/home/test/'
     }
     inv.add_user(user)
     inv.del_user(u'test☭,cn=')
Пример #16
0
 def testMissingParam(self):
     cfg2 = {}
     return True
     try:
         inv = Backend(cfg2, cherrypy.log, 'ldap', attr, 'uid')
     except MissingKey:
         return
     else:
         raise AssertionError("expected an exception")
Пример #17
0
 def testSearchUser(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ret = inv.search('smith')
     expected = {
         'ssmith': {
             'sn': 'smith',
             'uid': 'ssmith',
             'cn': 'Sheri Smith',
             'userPassword': '******'
         },
         'jsmith': {
             'sn': 'Smith',
             'uid': 'jsmith',
             'cn': 'John Smith',
             'userPassword': '******'
         }
     }
     assert ret == expected
Пример #18
0
 def testAddDeleteGroups(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     groups = [
         'cn=hrpeople,ou=Groups,dc=example,dc=org',
         'cn=itpeople,ou=Groups,dc=example,dc=org',
     ]
     inv.add_to_groups(u'jwatsoné', groups)
     ret = inv.get_groups(u'jwatsoné')
     inv.del_from_groups(u'jwatsoné',
                         ['cn=hrpeople,ou=Groups,dc=example,dc=org'])
     inv.del_from_groups(u'jwatsoné',
                         ['cn=hrpeople,ou=Groups,dc=example,dc=org'])
     assert ret == [
         'cn=itpeople,ou=Groups,dc=example,dc=org',
         'cn=hrpeople,ou=Groups,dc=example,dc=org'
     ]
Пример #19
0
 def testModifyUser(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     user = {
     'uid': u'test☭',
     'sn':  u'test☭',
     'cn':  u'test☭',
     'userPassword': u'test☭',
     'uidNumber': '42',
     'gidNumber': '42',
     'homeDirectory': '/home/test/'
     }
     inv.add_user(user)
     inv.set_attrs(u'test☭', {'gecos': 'test2', 'homeDirectory': '/home/test/'})
     inv.del_user(u'test☭')
Пример #20
0
 def testModifyUser(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     user = {
     'uid': u'test☭',
     'sn':  u'test☭',
     'cn':  u'test☭',
     'userPassword': u'test☭',
     'uidNumber': '42',
     'gidNumber': '42',
     'homeDirectory': '/home/test/'
     }
     inv.add_user(user)
     inv.set_attrs(u'test☭', {'gecos': 'test2', 'homeDirectory': '/home/test/'})
     inv.del_user(u'test☭')
Пример #21
0
 def testAddDeleteGroups(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     groups = [
        'cn=hrpeople,ou=Groups,dc=example,dc=org',
        'cn=itpeople,ou=Groups,dc=example,dc=org',
     ]
     inv.add_to_groups(u'jwatsoné', groups)
     ret = inv.get_groups(u'jwatsoné')
     inv.del_from_groups(u'jwatsoné', ['cn=hrpeople,ou=Groups,dc=example,dc=org'])
     inv.del_from_groups(u'jwatsoné', ['cn=hrpeople,ou=Groups,dc=example,dc=org'])
     assert ret == ['cn=itpeople,ou=Groups,dc=example,dc=org', 'cn=hrpeople,ou=Groups,dc=example,dc=org']
Пример #22
0
 def testAddUserDuplicate(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     user = {
         'uid': u'test☭',
         'sn': u'test☭',
         'cn': u'test☭',
         'uidNumber': '42',
         'userPassword': u'test☭',
         'gidNumber': '42',
         'homeDirectory': '/home/test/'
     }
     try:
         inv.add_user(user)
         inv.add_user(user)
     except UserAlreadyExists:
         inv.del_user(u'test☭')
         return
     else:
         inv.del_user(u'test☭')
         raise AssertionError("expected an exception")
Пример #23
0
 def testAddUserDuplicate(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     user = {
     'uid': u'test☭',
     'sn':  u'test☭',
     'cn':  u'test☭',
     'uidNumber': '42',
     'userPassword': u'test☭',
     'gidNumber': '42',
     'homeDirectory': '/home/test/'
     }
     try:
         inv.add_user(user)
         inv.add_user(user)
     except UserAlreadyExists:
         inv.del_user(u'test☭')
         return
     else:
         inv.del_user(u'test☭')
         raise AssertionError("expected an exception")
Пример #24
0
 def testAddUser(self):
     try:
         inv.del_user(u'test☭,cn=')
     except:
         pass
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     user = {
         'uid': u'test☭,cn=',
         'sn': u'test☭',
         'cn': u'test☭',
         'userPassword': u'test☭',
         'uidNumber': '42',
         'gidNumber': '42',
         'homeDirectory': '/home/test/'
     }
     inv.add_user(user)
     inv.del_user(u'test☭,cn=')
Пример #25
0
 def testAddUserMissingMustattribute(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     user = {
         'uid': u'test☭',
         'sn': u'test☭',
         'cn': u'test☭',
         'userPassword': u'test☭',
         'gidNumber': '42',
         'homeDirectory': '/home/test/'
     }
     try:
         inv.add_user(user)
     except ldap.OBJECT_CLASS_VIOLATION:
         return
     else:
         inv.del_user(u'test☭')
         raise AssertionError("expected an exception")
Пример #26
0
 def testAuthFailure(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     res = inv.auth('notauser', 'password') or inv.auth(u'jwatsoné', 'notapasswordé')
     assert res == False
Пример #27
0
 def testGetUser(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ret = inv.get_user(u'jwatsoné')
     expected = {'uid': u'jwatsoné', 'cn': 'John Watson', 'sn': 'watson'}
     assert ret == expected
Пример #28
0
 def testConnect(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ldap = inv._connect()
     ldap.simple_bind_s(inv.binddn, inv.bindpassword)
     return True
Пример #29
0
 def testNominal(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     return True
Пример #30
0
 def testSearchUser(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ret = inv.search('smith')
     expected = {'ssmith': {'sn': 'smith', 'uid': 'ssmith', 'cn': 'Sheri Smith', 'userPassword': '******'}, 'jsmith': {'sn': 'Smith', 'uid': 'jsmith', 'cn': 'John Smith', 'userPassword': '******'}}
     assert ret == expected
Пример #31
0
 def testGetGroups(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ret = inv.get_groups(u'jwatsoné')
     expected = ['cn=itpeople,ou=Groups,dc=example,dc=org']
     assert ret == expected
Пример #32
0
 def testAuthSuccess(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ret = inv.auth(u'jwatsoné', u'passwordwatsoné')
     assert ret == True
Пример #33
0
 def testConnect(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ldap = inv._connect()
     ldap.simple_bind_s(inv.binddn, inv.bindpassword)
     return True
Пример #34
0
 def testAuthSuccess(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ret = inv.auth(u'jwatsoné', u'passwordwatsoné')
     assert ret == True
Пример #35
0
 def testGetGroups(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ret = inv.get_groups(u'jwatsoné')
     expected = ['cn=itpeople,ou=Groups,dc=example,dc=org']
     assert ret == expected
Пример #36
0
 def testGetUser(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ret = inv.get_user(u'jwatsoné')
     expected = {'uid': u'jwatsoné', 'cn': 'John Watson', 'sn': 'watson'}
     assert ret == expected
Пример #37
0
 def testGetUser(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     ret = inv.get_user(u'jwatsoné')
     expected = {'uid': u'jwatsoné', 'objectClass': 'inetOrgPerson', 'carLicense': 'HERCAR 125', 'sn': 'watson', 'mail': '*****@*****.**', 'homePhone': '555-111-2225', 'cn': 'John Watson', 'userPassword': u'passwordwatsoné'}
     assert ret == expected
Пример #38
0
 def testAuthFailure(self):
     inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
     res = inv.auth('notauser', 'password') or inv.auth(
         u'jwatsoné', 'notapasswordé')
     assert res == False
Пример #39
0
}


def syslog_error(msg='', context='', severity=logging.INFO, traceback=False):
    pass


cherrypy.log.error = syslog_error
attr = [
    'shéll', 'cn', 'uid', 'uidNumber', 'gidNumber', 'home', 'userPassword',
    'givenName', 'email', 'sn'
]

cherrypy.log.error = syslog_error

inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
print inv.get_user('jwatson')
print inv.get_groups('jwatson')
print inv.search('smit')
user = {
    'uid': 'test',
    'sn': 'test',
    'cn': 'test',
    'userPassword': '******',
    'uidNumber': '42',
    'gidNumber': '42',
    'homeDirectory': '/home/test/'
}
inv.add_user(user)
print inv.get_user('test')
print inv.get_groups('test')
Пример #40
0
'dn_user_attr'          : 'uid',
'group_attr.uniqMember' : "%(dn)s",
'group_attr.memberUid'  : "%(uid)s",

}

def syslog_error(msg='', context='',
        severity=logging.INFO, traceback=False):
    pass

cherrypy.log.error = syslog_error
attr = ['shéll', 'cn', 'uid', 'uidNumber', 'gidNumber', 'home', 'userPassword', 'givenName', 'email', 'sn']

cherrypy.log.error = syslog_error

inv = Backend(cfg, cherrypy.log, 'ldap', attr, 'uid')
print inv.get_user('jwatson')
print inv.get_groups('jwatson')
print inv.search('smit')
user = {
'uid': 'test',
'sn':  'test',
'cn':  'test',
'userPassword': '******',
'uidNumber': '42',
'gidNumber': '42',
'homeDirectory': '/home/test/'
}
inv.add_user(user)
print inv.get_user('test')
print inv.get_groups('test')