Beispiel #1
0
 def test_rename_without_parent(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     (newrdn, newparent) = self.env['modify_user'].split(',', 1)
     newrdn += '-newrdn'
     ld.rename(self.env['modify_user'], newrdn)
     # re-rename
     ld.rename('%s,%s' % (newrdn, newparent), self.env['modify_user'].split(',', 1)[0], newparent)
Beispiel #2
0
 def test_modify(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     dtime = datetime.utcnow().strftime('%Y%m%d%H%M%S.%fZ')
     changes = [
         ('description', ['Modified at %s' % (dtime,)], LDAP_MOD_REPLACE)
     ]
     ld.modify(self.env['modify_user'], changes)
Beispiel #3
0
 def test_add_with_relax(self):
     (dn, attributes) = create_user_entry(relax=True)
     self.new_user_dn = dn
     self.new_user_attributes = attributes
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     c = LDAPControl()
     c.add_control(LDAP_CONTROL_RELAX)
     ld.add(self.new_user_dn, self.new_user_attributes, controls=c)
Beispiel #4
0
 def setUp(self):
     server = os.environ.get('TEST_SERVER', 'ldap-server')
     self.env = Environment[server]
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     (dn, attributes) = create_user_entry()
     self.old_user_dn = dn
     self.old_user_attributes = attributes
     ld.add(self.old_user_dn, self.old_user_attributes)
Beispiel #5
0
 def setUp(self):
     server = os.environ.get('TEST_SERVER', 'ldap-server')
     self.env = Environment[server]
     self.compare_attribute = 'description'
     self.compare_value = 'This value will be compared'
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     ld.modify(self.env['modify_user'],
               [(self.compare_attribute, [self.compare_value], LDAP_MOD_REPLACE)])
Beispiel #6
0
 def test_modify_with_relax(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     c = LDAPControl()
     c.add_control(LDAP_CONTROL_RELAX)
     dtime = datetime.utcnow().strftime('%Y%m%d%H%M%S.%fZ')
     changes = [
         ('pwdAccountLockedTime', [dtime], LDAP_MOD_REPLACE)
     ]
     ld.modify(self.env['modify_user'], changes, controls=c)
Beispiel #7
0
 def test_rename_async(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     (newrdn, newparent) = self.env['modify_user'].split(',', 1)
     newrdn += '-newrdn'
     msgid = ld.rename(self.env['modify_user'], newrdn, newparent, async=True)
     result = ld.result(msgid)
     self.assertEqual(result['return_code'], 0)
     # re-rename
     ld.rename('%s,%s' % (newrdn, newparent), self.env['modify_user'].split(',', 1)[0], newparent)
Beispiel #8
0
 def test_modify_async(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     dtime = datetime.utcnow().strftime('%Y%m%d%H%M%S.%fZ')
     changes = [
         ('description', ['Modified at %s' % (dtime,)], LDAP_MOD_REPLACE)
     ]
     msgid = ld.modify(self.env['modify_user'], changes, async=True)
     result = ld.result(msgid)
     self.assertEqual(result['return_code'], 0)
Beispiel #9
0
 def test_rename_oldrdn(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     (newrdn, newparent) = self.env['modify_user'].split(',', 1)
     newrdn += '-newrdn'
     ld.rename(self.env['modify_user'], newrdn, newparent, deleteoldrdn=False, async=True)
     time.sleep(0.3)
     entry = ld.search('%s,%s' % (newrdn, newparent), attributes=['uid'])[0]
     self.assertEqual(len(entry['uid']), 2)
     # re-rename
     ld.rename('%s,%s' % (newrdn, newparent), self.env['modify_user'].split(',', 1)[0], newparent)
Beispiel #10
0
 def test_bind_controls(self):
     ld = LDAP(self.env['uri_389'])
     c = LDAPControl()
     c.add_control(LDAP_CONTROL_PASSWORDPOLICYREQUEST)
     msgid = ld.bind(self.env['auth_user'],
                     self.env['auth_pw'],
                     controls=c,
                     async=True)
     result = ld.result(msgid, controls=c)
     self.assertIn('ppolicy_msg', result)
Beispiel #11
0
 def test_passwd(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['auth_user'], self.env['auth_pw'])
     newpassword = '******'
     ld.passwd(self.env['auth_user'], self.env['auth_pw'], newpassword)
     ld.bind(self.env['auth_user'], newpassword)
     # re-passwd
     ld.passwd(self.env['auth_user'], newpassword, self.env['auth_pw'])
     ld.bind(self.env['auth_user'], self.env['auth_pw'])
Beispiel #12
0
 def test_compare_fail(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     result = ld.compare(self.env['modify_user'], self.compare_attribute, 'dummy')
     self.assertFalse(result)
Beispiel #13
0
 def test_whoami(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['auth_user'], self.env['auth_pw'])
     result = ld.whoami()
     self.assertEqual('dn:' + self.env['auth_user'], result)
Beispiel #14
0
 def test_search_filter(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     r = ld.search(self.env['suffix'], LDAP_SCOPE_SUB, filter='cn=auth')
     self.assertEqual(len(r), 1)
Beispiel #15
0
 def test_add_async(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     msgid = ld.add(self.new_user_dn, self.new_user_attributes, async=True)
     result = ld.result(msgid)
     self.assertEqual(result['return_code'], 0)
Beispiel #16
0
 def test_paged_search(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     gen = ld.paged_search(self.env['suffix'], LDAP_SCOPE_SUB, pagesize=1)
     self.assertIsInstance(gen, GeneratorType)
     [x for x in gen]
Beispiel #17
0
 def test_bind_error_async(self):
     ld = LDAP(self.env['uri_389'])
     msgid = ld.bind(self.env['auth_user'], 'bad password', async=True)
     result = ld.result(msgid)
     self.assertEqual(result['return_code'], 49)
Beispiel #18
0
 def test_add(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     ld.add(self.new_user_dn, self.new_user_attributes)
Beispiel #19
0
 def test_search_attributes(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     r = ld.search(self.env['suffix'], LDAP_SCOPE_SUB, filter='cn=auth', attrsonly=True)
     self.assertEqual(len(r[0]['cn']), 0)
Beispiel #20
0
 def test_delete_async(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     msgid = ld.delete(self.old_user_dn, async=True)
     result = ld.result(msgid)
     self.assertEqual(result['return_code'], 0)
Beispiel #21
0
 def test_bind(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['auth_user'], self.env['auth_pw'])
Beispiel #22
0
 def test_delete(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     ld.delete(self.old_user_dn)
Beispiel #23
0
 def test_start_tls_bind(self):
     ld = LDAP(self.env['uri_389'])
     ld.set_option(LDAP_OPT_X_TLS_CACERTFILE, str(cacert_file), is_global=True)
     ld.start_tls()
     ld.bind(self.env['auth_user'], self.env['auth_pw'])
Beispiel #24
0
def ldapsearch_ou():
    ldap = LDAP(URI)
    ldap.bind(BIND_DN, BIND_PASS)
    result = ldap.search(BASE_DN, LDAP_SCOPE_SUB, '(|(cn=miyabi)(dc=jp))')
    return result
Beispiel #25
0
 def test_bind_error(self):
     with self.assertRaises(LDAPError) as cm:
         ld = LDAP(self.env['uri_389'])
         ld.bind(self.env['auth_user'], 'bad password')
Beispiel #26
0
def ldapsearchmiyabi():
    ld = LDAP(URI)
    ld.bind(BIND_DN, BIND_PASS)
    result = ld.search('uid=miyabi2,ou=Users,dc=example,dc=jp', LDAP_SCOPE_SUB,
                       '(&(uid=miyabi2)(ou=Users))')
    return result
Beispiel #27
0
 def test_search_base(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     self.assertEqual(len(ld.search(self.env['suffix'])), 1)
Beispiel #28
0
 def test_compare(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     result = ld.compare(self.env['modify_user'], self.compare_attribute, self.compare_value)
     self.assertTrue(result)
Beispiel #29
0
 def test_search_attributes(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     r = ld.search(self.env['suffix'], LDAP_SCOPE_SUB, filter='cn=auth', attributes=['cn'])
     self.assertIn('cn', r[0])
     self.assertNotIn('objectClass', r[0])
Beispiel #30
0
 def test_modify_mod_delete(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     changes = [('description', [], LDAP_MOD_DELETE)]
     ld.modify(self.env['modify_user'], changes)
Beispiel #31
0
 def test_search_sizelimit(self):
     ld = LDAP(self.env['uri_389'])
     ld.bind(self.env['root_dn'], self.env['root_pw'])
     with self.assertRaises(LDAPError) as cm:
         r = ld.search(self.env['suffix'], LDAP_SCOPE_SUB, sizelimit=1)
     self.assertEqual(cm.exception.return_code, 4)  # Size limit exceeded (4)
Beispiel #32
0
 def test_bind_async(self):
     ld = LDAP(self.env['uri_389'])
     msgid = ld.bind(self.env['auth_user'], self.env['auth_pw'], async=True)
     result = ld.result(msgid)
     self.assertEqual(result['return_code'], 0)
Beispiel #33
0
def ldapsearch_uid(uri, bind_dn, bind_pass, base_dn):
    ldap = LDAP(URI)
    ldap.bind(BIND_DN, BIND_PASS)
    ldap.unbind()
    result = ldap.search(BASE_DN, LDAP_SCOPE_SUB, 'cn=miyabi', ['cn'])
    return result
Beispiel #34
0
# ldapadd2.py

from libldap import LDAP

URI = 'ldap://ldap.example.jp'
BASE_DN = 'dc=example,dc=jp'
BIND_DN = 'cn=master,dc=example,dc=jp'
BIND_PASS = '******'

ld = LDAP(URI)
ld.bind(BIND_DN, BIND_PASS)
result = ld.add('cn=group2,ou=Groups,dc=example,dc=jp',
                [('objectClass', ['top', 'posixGroup']), ('cn', ['group2']),
                 ('gidNumber', ['3000']), ('description', ['Test Group 3'])])

print(result)