Exemplo n.º 1
0
    def test_connection_targets_separate_branch_of_tree(self):
        ldapurl = 'ldap://ldap.example.com'
        dom = 'dc=example,dc=com'
        self.assertRaises(backend.LDAPError, backend.initialize, ldapurl)
        backend._addTreeItems(ldapurl, dom)
        connection = backend.initialize(ldapurl)
        self.assert_(connection)

        ldapurl = 'ldap://ldap.example.org'
        dom = 'dc=example,dc=org'
        self.assertRaises(backend.LDAPError, backend.initialize, ldapurl)
        backend._addTreeItems(ldapurl, dom)
        connection = backend.initialize(ldapurl)
        self.assert_(connection)
Exemplo n.º 2
0
 def test_connection_targets_separate_branch_of_tree(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     self.assertRaises(backend.LDAPError, backend.initialize, ldapurl)
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     self.assert_(connection)
     
     ldapurl = 'ldap://ldap.example.org'
     dom = 'dc=example,dc=org'
     self.assertRaises(backend.LDAPError, backend.initialize, ldapurl)
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     self.assert_(connection)
Exemplo n.º 3
0
 def test_adding_items_to_tree(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     dn = 'uid=uid1,%s' % dom
     attrs = [('testattr','testattr1')]
     backend._addTreeItems(ldapurl, dom)
     c = backend.initialize(ldapurl)
     c.simple_bind_s()
     
     expected = {ldapurl: {
         'dc=com': {
             'dn': 'dc=com',
             'dc=example': {
                 'dn': 'dc=example,dc=com',
                 'uid=uid1': {
                     'dn': 'uid=uid1,dc=example,dc=com',
                     'uid': ['uid1'], 
                     'testattr': ['testattr1']
                 }
             }
         }
     }}
     
     c.add_s(dn, attrs)
     self.failUnlessEqual(backend.TREE, expected)
Exemplo n.º 4
0
    def test_searching_for_user_by_uid_with_only_wildcard_from_branch(self):
        base_dn = 'ou=users,%s' % self.root_dn
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        results = connection.search_s(base_dn, filterstr='(uid=*)')

        self.assertEqual(len(results), 2)
Exemplo n.º 5
0
 def test_searching_for_non_matching_attributes(self):
     base_dn = 'uid=jradford,ou=users,%s' % self.root_dn
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     results = connection.search_s(base_dn, attrlist=['uid', 'ou'])
     
     self.assertEqual(results[0], (base_dn, {'uid': ['jradford']}))
Exemplo n.º 6
0
    def test_adding_items_to_tree(self):
        ldapurl = 'ldap://ldap.example.com'
        dom = 'dc=example,dc=com'
        dn = 'uid=uid1,%s' % dom
        attrs = [('testattr', 'testattr1')]
        backend._addTreeItems(ldapurl, dom)
        c = backend.initialize(ldapurl)
        c.simple_bind_s()

        expected = {
            ldapurl: {
                'dc=com': {
                    'dn': 'dc=com',
                    'dc=example': {
                        'dn': 'dc=example,dc=com',
                        'uid=uid1': {
                            'dn': 'uid=uid1,dc=example,dc=com',
                            'uid': ['uid1'],
                            'testattr': ['testattr1']
                        }
                    }
                }
            }
        }

        c.add_s(dn, attrs)
        self.failUnlessEqual(backend.TREE, expected)
Exemplo n.º 7
0
 def test_unbound_modifying_raises_error(self):
     dn, attrs = self.makeOU(self.dom, 'users')
     backend._addTreeItems(self.ldapurl, dn, attrs)
     mod_attrs = [(backend.MOD_ADD, 'testattr', 'TESTATTR')]
     connection = backend.initialize(self.ldapurl)
     self.assertRaises(backend.LDAPError, connection.modify_s, dn,
                       mod_attrs)
Exemplo n.º 8
0
    def test_searching_for_everything_from_leaf_node(self):
        base_dn = 'uid=jradford,ou=users,%s' % self.root_dn
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        results = connection.search_s(base_dn)

        self.assertEqual(len(results), 1)
Exemplo n.º 9
0
 def test_modifications_fail_when_auth_required(self):
     backend._toggle_auth_required(self.ldapurl)
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'uid=jradford,ou=users,%s' % self.root_dn
     mod_attrs = [( backend.MOD_ADD, 'testattr', 'TESTATTR' )]
     self.assertRaises(backend.STRONG_AUTH_REQUIRED, connection.modify_s, dn, mod_attrs)
Exemplo n.º 10
0
 def test_deletions_fail_when_auth_required(self):
     backend._toggle_auth_required(self.ldapurl)
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'uid=jradford,ou=users,%s' % self.root_dn
     self.assertRaises(backend.STRONG_AUTH_REQUIRED, connection.delete_s,
                       dn)
Exemplo n.º 11
0
 def test_searching_for_user_by_uid_with_wildcard_at_start_and_end_from_root(self):
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     results = connection.search_s(self.root_dn, filterstr='(uid=*dfor*)')
     
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0][0], 'uid=jradford,ou=users,dc=example,dc=com')
Exemplo n.º 12
0
 def test_searching_for_user_by_uid_with_only_wildcard_from_branch(self):
     base_dn = 'ou=users,%s' % self.root_dn
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     results = connection.search_s(base_dn, filterstr='(uid=*)')
     
     self.assertEqual(len(results), 2)
Exemplo n.º 13
0
 def test_searching_for_everything_from_leaf_node(self):
     base_dn = 'uid=jradford,ou=users,%s' % self.root_dn
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     results = connection.search_s(base_dn)
     
     self.assertEqual(len(results), 1)
Exemplo n.º 14
0
 def XXtest_bind_with_non_existant_user(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     connection.add_s(*self.makeOU('dc=example,dc=com', 'users'))
     self.assertRaises(backend.NO_SUCH_OBJECT, connection.simple_bind_s, 'uid=noone,ou=users,dc=example,dc=com', 'password')
Exemplo n.º 15
0
    def test_searching_for_non_matching_attributes(self):
        base_dn = 'uid=jradford,ou=users,%s' % self.root_dn
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        results = connection.search_s(base_dn, attrlist=['uid', 'ou'])

        self.assertEqual(results[0], (base_dn, {'uid': ['jradford']}))
Exemplo n.º 16
0
 def test_bind_with_directory_manager(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     result = connection.simple_bind_s('Manager', 'password')
     self.assert_(result)
     self.assert_(connection.bound)
Exemplo n.º 17
0
 def test_bind_with_directory_manager(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     result = connection.simple_bind_s('Manager', 'password')
     self.assert_(result)
     self.assert_(connection.bound)
Exemplo n.º 18
0
    def test_searching_for_user_by_uid_with_wildcard_at_start_from_root(self):
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        results = connection.search_s(self.root_dn, filterstr='(uid=*d)')

        self.assertEqual(len(results), 1)
        self.assertEqual(results[0][0],
                         'uid=jradford,ou=users,dc=example,dc=com')
Exemplo n.º 19
0
    def test_searching_for_only_dn_attribute(self):
        base_dn = 'uid=jradford,ou=users,%s' % self.root_dn
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        results = connection.search_s(base_dn, attrlist=['dn'])

        self.assertEqual(len(results), 1)
        self.assertEqual(results[0], (base_dn, {}))
Exemplo n.º 20
0
 def test_searching_for_only_dn_attribute(self):
     base_dn = 'uid=jradford,ou=users,%s' % self.root_dn
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     results = connection.search_s(base_dn, attrlist=['dn'])
     
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0], (base_dn, {}))
Exemplo n.º 21
0
 def test_searching_for_user_by_uid_from_branch(self):
     base_dn = 'ou=users,%s' % self.root_dn
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     results = connection.search_s(base_dn, filterstr='(uid=jradford)')
     
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0][0], 'uid=jradford,ou=users,dc=example,dc=com')
Exemplo n.º 22
0
 def test_bind_with_blank_password(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     result = connection.simple_bind_s('noone', '')
     self.assert_(result)
     self.assert_(connection.bound)
Exemplo n.º 23
0
 def test_bind_with_blank_password(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     result = connection.simple_bind_s('noone', '')
     self.assert_(result)
     self.assert_(connection.bound)
Exemplo n.º 24
0
 def test_modifications_fail_when_auth_required(self):
     backend._toggle_auth_required(self.ldapurl)
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'uid=jradford,ou=users,%s' % self.root_dn
     mod_attrs = [(backend.MOD_ADD, 'testattr', 'TESTATTR')]
     self.assertRaises(backend.STRONG_AUTH_REQUIRED, connection.modify_s,
                       dn, mod_attrs)
Exemplo n.º 25
0
 def test_unbound_searching_always_returns_nothing(self):
     dn, attrs = self.makeOU(self.dom, 'users')
     backend._addTreeItems(self.ldapurl, dn, attrs)
     dn, attrs = self.makeUser('ou=users,%s' % self.dom, 'jradford', 'Jacob', 'Radford')
     backend._addTreeItems(self.ldapurl, dn, attrs)
     connection = backend.initialize(self.ldapurl)
     result = connection.search_s(self.dom)
     self.failIf(result)
Exemplo n.º 26
0
 def XXtest_bind_with_non_existant_user(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     connection.add_s(*self.makeOU('dc=example,dc=com', 'users'))
     self.assertRaises(backend.NO_SUCH_OBJECT, connection.simple_bind_s,
                       'uid=noone,ou=users,dc=example,dc=com', 'password')
Exemplo n.º 27
0
 def test_unbound_searching_always_returns_nothing(self):
     dn, attrs = self.makeOU(self.dom, 'users')
     backend._addTreeItems(self.ldapurl, dn, attrs)
     dn, attrs = self.makeUser('ou=users,%s' % self.dom, 'jradford',
                               'Jacob', 'Radford')
     backend._addTreeItems(self.ldapurl, dn, attrs)
     connection = backend.initialize(self.ldapurl)
     result = connection.search_s(self.dom)
     self.failIf(result)
Exemplo n.º 28
0
def exists(url, dn):
    connection = backend.initialize(url)
    try:
        if connection._search_s(dn, scope=backend.SCOPE_BASE):
            return True
    except backend.LDAPError:
        pass

    return False
Exemplo n.º 29
0
def exists(url, dn):
    connection = backend.initialize(url)
    try:
        if connection._search_s(dn, scope=backend.SCOPE_BASE):
            return True
    except backend.LDAPError:
        pass
    
    return False
Exemplo n.º 30
0
def check_password(url, dn, password):
    connection = backend.initialize(url)
    try:
        connection.simple_bind_s(dn, password)
        return True
    except backend.INVALID_CREDENTIALS:
        pass
    
    return False
Exemplo n.º 31
0
 def test_disconnecting(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     connection.simple_bind_s()
     connection.search_s( dom )
     connection.unbind_s()
     self.assertRaises(backend.LDAPError, connection.search_s, dom)
Exemplo n.º 32
0
 def test_deleting_non_existant_node(self):
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'uid=nonentity,ou=users,%s' % self.root_dn
     
     connection.delete_s(dn)
     results = connection.search_s(self.root_dn)
     
     self.assert_(len(results) == 4)
Exemplo n.º 33
0
 def XXtest_bind_with_user_but_wrong_pass(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     connection.add_s(*self.makeOU('dc=example,dc=com', 'users'))
     connection.add_s(*self.makeUser('ou=users,dc=example,dc=com', 'jradford', 'Jacob', 'Radford'))
     
     self.assertRaises(backend.INVALID_CREDENTIALS, connection.simple_bind_s, 'uid=jradford,ou=users,dc=example,dc=com', 'badpassword')
Exemplo n.º 34
0
 def XXtest_bind_with_user(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     connection.add_s(*self.makeOU('dc=example,dc=com', 'users'))
     connection.add_s(*self.makeUser('ou=users,dc=example,dc=com', 'jradford', 'Jacob', 'Radford'))
     result = connection.simple_bind_s('uid=jradford,ou=users,dc=example,dc=com', 'password')
     self.assert_(result)
Exemplo n.º 35
0
 def test_disconnecting(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     connection.simple_bind_s()
     connection.search_s(dom)
     connection.unbind_s()
     self.assertRaises(backend.LDAPError, connection.search_s, dom)
Exemplo n.º 36
0
    def test_deleting_non_existant_node(self):
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        dn = 'uid=nonentity,ou=users,%s' % self.root_dn

        connection.delete_s(dn)
        results = connection.search_s(self.root_dn)

        self.assert_(len(results) == 4)
Exemplo n.º 37
0
    def test_searching_for_user_by_uid_from_branch(self):
        base_dn = 'ou=users,%s' % self.root_dn
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        results = connection.search_s(base_dn, filterstr='(uid=jradford)')

        self.assertEqual(len(results), 1)
        self.assertEqual(results[0][0],
                         'uid=jradford,ou=users,dc=example,dc=com')
Exemplo n.º 38
0
def check_password(url, dn, password):
    connection = backend.initialize(url)
    try:
        connection.simple_bind_s(dn, password)
        return True
    except backend.INVALID_CREDENTIALS:
        pass

    return False
Exemplo n.º 39
0
 def test_modifying_with_mod_delete_on_attrib_using_non_matching_value(self):
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'uid=jradford,ou=users,%s' % self.root_dn
     mod_attrs = [( backend.MOD_DELETE, 'cn', 'non-existant' )]
     
     connection.modify_s(dn, mod_attrs)
     results = connection.search_s(dn)
     
     self.assert_(results[0][1].get('cn') == ['Jacob Radford'])
Exemplo n.º 40
0
 def test_modifying_with_mod_delete_on_attrib_with_single_value_using_None_value(self):
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'uid=jradford,ou=users,%s' % self.root_dn
     mod_attrs = [( backend.MOD_DELETE, 'cn', None )]
     
     connection.modify_s(dn, mod_attrs)
     results = connection.search_s(dn)
     
     self.failIf(results[0][1].get('cn'))
Exemplo n.º 41
0
 def test_deleting_root_of_multiple_nodes(self):
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'ou=users,%s' % self.root_dn
     
     connection.delete_s(dn)
     results = connection.search_s(self.root_dn)
     
     self.assert_(len(results) == 1)
     self.assertRaises(backend.NO_SUCH_OBJECT, connection.search_s, dn)
Exemplo n.º 42
0
    def test_deleting_root_of_multiple_nodes(self):
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        dn = 'ou=users,%s' % self.root_dn

        connection.delete_s(dn)
        results = connection.search_s(self.root_dn)

        self.assert_(len(results) == 1)
        self.assertRaises(backend.NO_SUCH_OBJECT, connection.search_s, dn)
Exemplo n.º 43
0
 def test_attempted_add_to_non_existant_branch_raises_error(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     dn = 'uid=uid1,ou=users,%s' % dom
     attrs = dict(testattr='testattr1')
     backend._addTreeItems(ldapurl, dom)
     c = backend.initialize(ldapurl)
     c.simple_bind_s()
     
     self.assertRaises(backend.NO_SUCH_OBJECT, c.add_s, dn, attrs)
Exemplo n.º 44
0
    def test_attempted_add_to_non_existant_branch_raises_error(self):
        ldapurl = 'ldap://ldap.example.com'
        dom = 'dc=example,dc=com'
        dn = 'uid=uid1,ou=users,%s' % dom
        attrs = dict(testattr='testattr1')
        backend._addTreeItems(ldapurl, dom)
        c = backend.initialize(ldapurl)
        c.simple_bind_s()

        self.assertRaises(backend.NO_SUCH_OBJECT, c.add_s, dn, attrs)
Exemplo n.º 45
0
    def test_modifying_with_mod_add_using_arr_value(self):
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        dn = 'uid=jradford,ou=users,%s' % self.root_dn
        mod_attrs = [(backend.MOD_ADD, 'testattr', ['TESTATTR'])]

        connection.modify_s(dn, mod_attrs)
        results = connection.search_s(dn)

        self.assert_('TESTATTR' in results[0][1].get('testattr'))
Exemplo n.º 46
0
 def test_modifying_with_mod_add_using_arr_value(self):
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'uid=jradford,ou=users,%s' % self.root_dn
     mod_attrs = [( backend.MOD_ADD, 'testattr', ['TESTATTR'] )]
     
     connection.modify_s(dn, mod_attrs)
     results = connection.search_s(dn)
     
     self.assert_('TESTATTR' in results[0][1].get('testattr'))
Exemplo n.º 47
0
 def test_modifying_with_mod_add_to_preexisting_using_str_value(self):
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'uid=jradford,ou=users,%s' % self.root_dn
     mod_attrs = [( backend.MOD_ADD, 'cn', 'TESTATTR' )]
     
     connection.modify_s(dn, mod_attrs)
     results = connection.search_s(dn)
     
     self.assert_('Jacob Radford' in results[0][1].get('cn'))
     self.assert_('TESTATTR' in results[0][1].get('cn'))
Exemplo n.º 48
0
    def test_modifying_with_mod_delete_on_attrib_with_single_value_using_None_value(
            self):
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        dn = 'uid=jradford,ou=users,%s' % self.root_dn
        mod_attrs = [(backend.MOD_DELETE, 'cn', None)]

        connection.modify_s(dn, mod_attrs)
        results = connection.search_s(dn)

        self.failIf(results[0][1].get('cn'))
Exemplo n.º 49
0
    def test_modifying_with_mod_delete_on_attrib_using_non_matching_value(
            self):
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        dn = 'uid=jradford,ou=users,%s' % self.root_dn
        mod_attrs = [(backend.MOD_DELETE, 'cn', 'non-existant')]

        connection.modify_s(dn, mod_attrs)
        results = connection.search_s(dn)

        self.assert_(results[0][1].get('cn') == ['Jacob Radford'])
Exemplo n.º 50
0
    def test_modifying_with_mod_replace_using_arr_value(self):
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        dn = 'uid=jradford,ou=users,%s' % self.root_dn
        mod_attrs = [(backend.MOD_REPLACE, 'cn', ['TESTATTR'])]

        connection.modify_s(dn, mod_attrs)
        results = connection.search_s(dn)

        self.failIf('Jacob Radford' in results[0][1].get('cn'))
        self.assert_('TESTATTR' in results[0][1].get('cn'))
Exemplo n.º 51
0
    def test_attempted_add_of_duplicate_raises_error(self):
        ldapurl = 'ldap://ldap.example.com'
        dom = 'dc=example,dc=com'
        dn = 'uid=uid1,%s' % dom
        attrs = [('testattr', 'testattr1')]
        backend._addTreeItems(ldapurl, dom)
        c = backend.initialize(ldapurl)
        c.simple_bind_s()

        c.add_s(dn, attrs)
        self.assertRaises(backend.ALREADY_EXISTS, c.add_s, dn, attrs)
Exemplo n.º 52
0
 def test_modifying_with_mod_replace_using_arr_value(self):
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'uid=jradford,ou=users,%s' % self.root_dn
     mod_attrs = [( backend.MOD_REPLACE, 'cn', ['TESTATTR'] )]
     
     connection.modify_s(dn, mod_attrs)
     results = connection.search_s(dn)
     
     self.failIf('Jacob Radford' in results[0][1].get('cn'))
     self.assert_('TESTATTR' in results[0][1].get('cn'))
Exemplo n.º 53
0
 def test_modifying_with_mod_delete_on_attrib_with_multiple_values_using_matching_str_value(self):
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'uid=jradford,ou=users,%s' % self.root_dn
     self.assert_(connection.search_s(dn)[0][1].get('objectClass') == ['person', 'inetOrgPerson'])
     mod_attrs = [( backend.MOD_DELETE, 'objectClass', 'inetOrgPerson' )]
     
     connection.modify_s(dn, mod_attrs)
     results = connection.search_s(dn)
     
     self.failIf(results[0][1].get('cn') == ['person'])
Exemplo n.º 54
0
    def test_modifying_with_mod_add_to_preexisting_using_str_value(self):
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        dn = 'uid=jradford,ou=users,%s' % self.root_dn
        mod_attrs = [(backend.MOD_ADD, 'cn', 'TESTATTR')]

        connection.modify_s(dn, mod_attrs)
        results = connection.search_s(dn)

        self.assert_('Jacob Radford' in results[0][1].get('cn'))
        self.assert_('TESTATTR' in results[0][1].get('cn'))
Exemplo n.º 55
0
 def XXtest_bind_with_user(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     connection = backend.initialize(ldapurl)
     connection.add_s(*self.makeOU('dc=example,dc=com', 'users'))
     connection.add_s(*self.makeUser('ou=users,dc=example,dc=com',
                                     'jradford', 'Jacob', 'Radford'))
     result = connection.simple_bind_s(
         'uid=jradford,ou=users,dc=example,dc=com', 'password')
     self.assert_(result)
Exemplo n.º 56
0
 def test_attempted_add_of_duplicate_raises_error(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     dn = 'uid=uid1,%s' % dom
     attrs = [('testattr','testattr1')]
     backend._addTreeItems(ldapurl, dom)
     c = backend.initialize(ldapurl)
     c.simple_bind_s()
     
     c.add_s(dn, attrs)
     self.assertRaises(backend.ALREADY_EXISTS, c.add_s, dn, attrs)
Exemplo n.º 57
0
 def test_inavlid_bind_removes_prior_bind(self):
     ldapurl = 'ldap://ldap.example.com'
     dom = 'dc=example,dc=com'
     backend._addTreeItems(ldapurl, dom)
     backend._addTreeItems(ldapurl, *self.makeOU('dc=example,dc=com', 'users'))
     backend._addTreeItems(ldapurl, *self.makeUser('ou=users,dc=example,dc=com', 'jradford', 'Jacob', 'Radford'))
     connection = backend.initialize(ldapurl)
     connection.simple_bind_s('Manager', 'password')
     
     self.assert_(connection.bound)
     self.assertRaises(backend.INVALID_CREDENTIALS, connection.simple_bind_s, 'uid=jradford,ou=users,dc=example,dc=com', 'badpassword')
     self.failIf(connection.bound)
Exemplo n.º 58
0
    def XXtest_bind_with_user_but_wrong_pass(self):
        ldapurl = 'ldap://ldap.example.com'
        dom = 'dc=example,dc=com'
        backend._addTreeItems(ldapurl, dom)
        connection = backend.initialize(ldapurl)
        connection.add_s(*self.makeOU('dc=example,dc=com', 'users'))
        connection.add_s(*self.makeUser('ou=users,dc=example,dc=com',
                                        'jradford', 'Jacob', 'Radford'))

        self.assertRaises(backend.INVALID_CREDENTIALS,
                          connection.simple_bind_s,
                          'uid=jradford,ou=users,dc=example,dc=com',
                          'badpassword')
Exemplo n.º 59
0
    def test_modifying_with_mod_delete_on_attrib_with_multiple_values_using_matching_str_value(
            self):
        connection = backend.initialize(self.ldapurl)
        connection.simple_bind_s()
        dn = 'uid=jradford,ou=users,%s' % self.root_dn
        self.assert_(
            connection.search_s(dn)[0][1].get('objectClass') ==
            ['person', 'inetOrgPerson'])
        mod_attrs = [(backend.MOD_DELETE, 'objectClass', 'inetOrgPerson')]

        connection.modify_s(dn, mod_attrs)
        results = connection.search_s(dn)

        self.failIf(results[0][1].get('cn') == ['person'])
Exemplo n.º 60
0
 def test_moving_single_node(self):
     connection = backend.initialize(self.ldapurl)
     connection.simple_bind_s()
     dn = 'ou=groups,%s' % self.root_dn
     newrdn = 'ou=orgs'
     newdn = '%s,%s' % (newrdn, self.root_dn)
     
     connection.modrdn_s(dn, newrdn)
     results = connection.search_s(self.root_dn)
     new_record = connection.search_s(newdn)[0]
     
     self.assert_(len(results) == 4)
     self.assertRaises(backend.NO_SUCH_OBJECT, connection.search_s, dn)
     self.assertEqual(new_record[0], newdn)
     self.assertEqual(new_record[1]['ou'], ['orgs'])