diff options
Diffstat (limited to 'tests')
35 files changed, 2723 insertions, 2108 deletions
diff --git a/tests/test_cmdline/test_ipagetkeytab.py b/tests/test_cmdline/test_ipagetkeytab.py index 0437c80b..b01fdee9 100644 --- a/tests/test_cmdline/test_ipagetkeytab.py +++ b/tests/test_cmdline/test_ipagetkeytab.py @@ -31,7 +31,7 @@ import nose import tempfile import krbV from ipaserver.plugins.ldap2 import ldap2 -from ipalib.dn import * +from ipapython.dn import DN def use_keytab(principal, keytab): try: diff --git a/tests/test_install/0_reset.update b/tests/test_install/0_reset.update index ba2af5e0..bd6ee636 100644 --- a/tests/test_install/0_reset.update +++ b/tests/test_install/0_reset.update @@ -1,5 +1,5 @@ dn: uid=tuser, cn=test, cn=accounts, $SUFFIX -deleteentry: reset: nada +deleteentry: dn: cn=test, cn=accounts, $SUFFIX deleteentry: reset: nada diff --git a/tests/test_install/test_updates.py b/tests/test_install/test_updates.py index 8b9ac28e..711af3db 100644 --- a/tests/test_install/test_updates.py +++ b/tests/test_install/test_updates.py @@ -20,19 +20,18 @@ Test the `ipaserver/install/ldapupdate.py` module. """ +import unittest import os import sys import ldap import nose -from nose.tools import raises -from tests.util import PluginTester -from tests.data import unicode_str from ipalib import api from ipalib import errors from ipaserver.install.ldapupdate import LDAPUpdate, BadSyntax, UPDATES_DIR from ipaserver.install import installutils from ipaserver import ipaldap from ipapython import ipautil +from ipapython.dn import DN """ The updater works through files only so this is just a thin-wrapper controlling @@ -46,7 +45,7 @@ have occurred as expected. The DM password needs to be set in ~/.ipa/.dmpw """ -class test_update(object): +class test_update(unittest.TestCase): """ Test the LDAP updater. """ @@ -70,13 +69,16 @@ class test_update(object): else: raise nose.SkipTest("Unable to find test update files") + self.container_dn = DN(self.updater._template_str('cn=test, cn=accounts, $SUFFIX')) + self.user_dn = DN(self.updater._template_str('uid=tuser, cn=test, cn=accounts, $SUFFIX')) + def tearDown(self): if self.ld: self.ld.unbind() def test_0_reset(self): """ - Reset the updater test data to a known initial state + Reset the updater test data to a known initial state (test_0_reset) """ try: modified = self.updater.update([self.testdir + "0_reset.update"]) @@ -84,96 +86,121 @@ class test_update(object): # Just means the entry doesn't exist yet modified = True - assert(modified == True) + self.assertTrue(modified) + + with self.assertRaises(errors.NotFound): + entries = self.ld.getList(self.container_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + + with self.assertRaises(errors.NotFound): + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) def test_1_add(self): """ - Test the updater with an add directive + Test the updater with an add directive (test_1_add) """ modified = self.updater.update([self.testdir + "1_add.update"]) - assert(modified == True) + self.assertTrue(modified) + + entries = self.ld.getList(self.container_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + self.assertEqual(len(entries), 1) + entry = entries[0] + + objectclasses = entry.getValues('objectclass') + for item in ('top', 'nsContainer'): + self.assertTrue(item in objectclasses) + + self.assertEqual(entry.getValue('cn'), 'test') + + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + self.assertEqual(len(entries), 1) + entry = entries[0] + + objectclasses = entry.getValues('objectclass') + for item in ('top', 'person', 'posixaccount', 'krbprincipalaux', 'inetuser'): + self.assertTrue(item in objectclasses) + + self.assertEqual(entry.getValue('loginshell'), '/bin/bash') + self.assertEqual(entry.getValue('sn'), 'User') + self.assertEqual(entry.getValue('uid'), 'tuser') + self.assertEqual(entry.getValue('cn'), 'Test User') + def test_2_update(self): """ - Test the updater when adding an attribute to an existing entry + Test the updater when adding an attribute to an existing entry (test_2_update) """ modified = self.updater.update([self.testdir + "2_update.update"]) - assert(modified == True) + self.assertTrue(modified) - # The update passed, lets look at the record and see if it is - # really updated - dn = self.updater._template_str('uid=tuser, cn=test, cn=accounts, $SUFFIX') - entry = self.ld.getList(dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) - assert (len(entry) == 1) - assert(entry[0].gecos == 'Test User') + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + self.assertEqual(len(entries), 1) + entry = entries[0] + self.assertEqual(entry.getValue('gecos'), 'Test User') def test_3_update(self): """ - Test the updater forcing an attribute to a given value + Test the updater forcing an attribute to a given value (test_3_update) """ modified = self.updater.update([self.testdir + "3_update.update"]) - assert(modified == True) + self.assertTrue(modified) - # The update passed, lets look at the record and see if it is - # really updated - dn = self.updater._template_str('uid=tuser, cn=test, cn=accounts, $SUFFIX') - entry = self.ld.getList(dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) - assert (len(entry) == 1) - assert(entry[0].gecos == 'Test User New') + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + self.assertEqual(len(entries), 1) + entry = entries[0] + self.assertEqual(entry.getValue('gecos'), 'Test User New') def test_4_update(self): """ - Test the updater adding a new value to a single-valued attribute + Test the updater adding a new value to a single-valued attribute (test_4_update) """ modified = self.updater.update([self.testdir + "4_update.update"]) - assert(modified == True) + self.assertTrue(modified) + + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + self.assertEqual(len(entries), 1) + entry = entries[0] + self.assertEqual(entry.getValue('gecos'), 'Test User New2') def test_5_update(self): """ - Test the updater adding a new value to a multi-valued attribute + Test the updater adding a new value to a multi-valued attribute (test_5_update) """ modified = self.updater.update([self.testdir + "5_update.update"]) - assert(modified == True) + self.assertTrue(modified) - # The update passed, lets look at the record and see if it is - # really updated - dn = self.updater._template_str('uid=tuser, cn=test, cn=accounts, $SUFFIX') - entry = self.ld.getList(dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) - assert (len(entry) == 1) - assert(entry[0].getValues('cn') == ['Test User', 'Test User New']) + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + self.assertEqual(len(entries), 1) + entry = entries[0] + self.assertEqual(sorted(entry.getValues('cn')), sorted(['Test User', 'Test User New'])) def test_6_update(self): """ - Test the updater removing a value from a multi-valued attribute + Test the updater removing a value from a multi-valued attribute (test_6_update) """ modified = self.updater.update([self.testdir + "6_update.update"]) - assert(modified == True) + self.assertTrue(modified) - # The update passed, lets look at the record and see if it is - # really updated - dn = self.updater._template_str('uid=tuser, cn=test, cn=accounts, $SUFFIX') - entry = self.ld.getList(dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) - assert (len(entry) == 1) - assert(entry[0].cn == 'Test User') + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + self.assertEqual(len(entries), 1) + entry = entries[0] + self.assertEqual(sorted(entry.getValues('cn')), sorted(['Test User'])) def test_6_update_1(self): """ - Test the updater removing a non-existent value from a multi-valued attribute + Test the updater removing a non-existent value from a multi-valued attribute (test_6_update_1) """ modified = self.updater.update([self.testdir + "6_update.update"]) - assert(modified == False) + self.assertFalse(modified) - # The update passed, lets look at the record and see if it is - # really updated - dn = self.updater._template_str('uid=tuser, cn=test, cn=accounts, $SUFFIX') - entry = self.ld.getList(dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) - assert (len(entry) == 1) - assert(entry[0].cn == 'Test User') + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + self.assertEqual(len(entries), 1) + entry = entries[0] + self.assertEqual(sorted(entry.getValues('cn')), sorted(['Test User'])) def test_7_cleanup(self): """ - Reset the test data to a known initial state + Reset the test data to a known initial state (test_7_cleanup) """ try: modified = self.updater.update([self.testdir + "0_reset.update"]) @@ -181,18 +208,113 @@ class test_update(object): # Just means the entry doesn't exist yet modified = True - assert(modified == True) + self.assertTrue(modified) + + with self.assertRaises(errors.NotFound): + entries = self.ld.getList(self.container_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + + with self.assertRaises(errors.NotFound): + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) - @raises(BadSyntax) def test_8_badsyntax(self): """ - Test the updater with an unknown keyword + Test the updater with an unknown keyword (test_8_badsyntax) """ - modified = self.updater.update([self.testdir + "8_badsyntax.update"]) + with self.assertRaises(BadSyntax): + modified = self.updater.update([self.testdir + "8_badsyntax.update"]) - @raises(BadSyntax) def test_9_badsyntax(self): """ - Test the updater with an incomplete line + Test the updater with an incomplete line (test_9_badsyntax) + """ + with self.assertRaises(BadSyntax): + modified = self.updater.update([self.testdir + "9_badsyntax.update"]) + + def test_from_dict(self): + """ + Test updating from a dict. + + This replicates what was done in test 1. """ - modified = self.updater.update([self.testdir + "9_badsyntax.update"]) + + # First make sure we're clean + with self.assertRaises(errors.NotFound): + entries = self.ld.getList(self.container_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + + with self.assertRaises(errors.NotFound): + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + + + update = { + self.container_dn: + {'dn': self.container_dn, + 'updates': ['add:objectClass: top', + 'add:objectClass: nsContainer', + 'add:cn: test' + ], + }, + self.user_dn: + {'dn': self.user_dn, + 'updates': ['add:objectclass: top', + 'add:objectclass: person', + 'add:objectclass: posixaccount', + 'add:objectclass: krbprincipalaux', + 'add:objectclass: inetuser', + 'add:homedirectory: /home/tuser', + 'add:loginshell: /bin/bash', + 'add:sn: User', + 'add:uid: tuser', + 'add:uidnumber: 999', + 'add:gidnumber: 999', + 'add:cn: Test User', + ], + }, + } + + modified = self.updater.update_from_dict(update) + self.assertTrue(modified) + + entries = self.ld.getList(self.container_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + self.assertEqual(len(entries), 1) + entry = entries[0] + + objectclasses = entry.getValues('objectclass') + for item in ('top', 'nsContainer'): + self.assertTrue(item in objectclasses) + + self.assertEqual(entry.getValue('cn'), 'test') + + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + self.assertEqual(len(entries), 1) + entry = entries[0] + + objectclasses = entry.getValues('objectclass') + for item in ('top', 'person', 'posixaccount', 'krbprincipalaux', 'inetuser'): + self.assertTrue(item in objectclasses) + + self.assertEqual(entry.getValue('loginshell'), '/bin/bash') + self.assertEqual(entry.getValue('sn'), 'User') + self.assertEqual(entry.getValue('uid'), 'tuser') + self.assertEqual(entry.getValue('cn'), 'Test User') + + # Now delete + + update = { + self.container_dn: + {'dn': self.container_dn, + 'deleteentry': None, + }, + self.user_dn: + {'dn': self.user_dn, + 'deleteentry': 'deleteentry: reset: nada', + }, + } + + modified = self.updater.update_from_dict(update) + self.assertTrue(modified) + + with self.assertRaises(errors.NotFound): + entries = self.ld.getList(self.container_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) + + with self.assertRaises(errors.NotFound): + entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*']) diff --git a/tests/test_ipalib/test_dn.py b/tests/test_ipalib/test_dn.py deleted file mode 100644 index 04e442f3..00000000 --- a/tests/test_ipalib/test_dn.py +++ /dev/null @@ -1,1085 +0,0 @@ -#!/usr/bin/python - -import unittest -from ipalib.dn import AVA, RDN, DN - -def default_rdn_attr_arg(i): - return 'a%d' % i - -def default_rdn_value_arg(i): - return str(i) - -def alt_rdn_attr_arg(i): - return 'b%d' % i - -def alt_rdn_value_arg(i): - return str(i*10) - -def make_rdn_args(low, high, kind, attr=None, value=None): - result=[] - for i in range(low, high): - if attr is None: - new_attr = default_rdn_attr_arg(i) - elif callable(attr): - new_attr = attr(i) - else: - new_attr = attr - - if value is None: - new_value = default_rdn_value_arg(i) - elif callable(value): - new_value = value(i) - else: - new_value = value - - if kind == 'tuple': - result.append((new_attr, new_value)) - elif kind == 'list': - result.append([new_attr, new_value]) - elif kind == 'RDN': - result.append(RDN((new_attr, new_value))) - else: - raise ValueError("Unknown kind = %s" % kind) - - return result - -class TestAVA(unittest.TestCase): - def setUp(self): - self.attr1 = 'cn' - self.value1 = 'Bob' - self.str_ava1 = '%s=%s' % (self.attr1, self.value1) - self.ava1 = AVA(self.attr1, self.value1) - - def test_create(self): - # Create with attr,value pair - ava1 = AVA(self.attr1, self.value1) - self.assertEqual(ava1, self.ava1) - - # Create with "attr=value" string - ava1 = AVA(self.str_ava1) - self.assertEqual(ava1, self.ava1) - - # Create with tuple (attr, value) - ava1 = AVA((self.attr1, self.value1)) - self.assertEqual(ava1, self.ava1) - - # Create with list [attr, value] - ava1 = AVA([self.attr1, self.value1]) - self.assertEqual(ava1, self.ava1) - - # Create with no args should fail - with self.assertRaises(TypeError): - AVA() - - # Create with more than 2 args should fail - with self.assertRaises(TypeError): - AVA(self.attr1, self.value1, self.attr1) - - # Create with 1 arg which is not string should fail - with self.assertRaises(TypeError): - AVA(1) - - # Create with malformed AVA string should fail - with self.assertRaises(ValueError): - AVA("cn") - - # Create with non-string parameters, should fail - with self.assertRaises(TypeError): - AVA(1, self.value1) - - with self.assertRaises(TypeError): - AVA(self.attr1, 1) - - with self.assertRaises(TypeError): - AVA((1, self.value1)) - - with self.assertRaises(TypeError): - AVA((self.attr1, 1)) - - def test_encoding(self): - # Create with attr,value pair - ava1 = AVA(self.attr1, self.value1) - self.assertEqual(ava1, self.ava1) - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - - ava1 = AVA(unicode(self.attr1), self.value1) - self.assertEqual(ava1, self.ava1) - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - - ava1 = AVA(self.attr1, unicode(self.value1)) - self.assertEqual(ava1, self.ava1) - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - - # Create with "attr=value" string - ava1 = AVA(self.str_ava1) - self.assertEqual(ava1, self.ava1) - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - - ava1 = AVA(unicode(self.ava1)) - self.assertEqual(ava1, self.ava1) - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - - # Create with tuple (attr, value) - ava1 = AVA((unicode(self.attr1), self.value1)) - self.assertEqual(ava1, self.ava1) - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - - ava1 = AVA((self.attr1, unicode(self.value1))) - self.assertEqual(ava1, self.ava1) - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - - def test_indexing(self): - self.assertEqual(self.ava1[self.attr1], self.value1) - - with self.assertRaises(KeyError): - self.ava1['foo'] - - with self.assertRaises(TypeError): - self.ava1[0] - - def test_properties(self): - self.assertEqual(self.ava1.attr, self.attr1) - self.assertEqual(self.ava1.value, self.value1) - - def test_str(self): - self.assertEqual(str(self.ava1), self.str_ava1) - self.assertIsInstance(str(self.ava1), str) - - def test_cmp(self): - # Equality - ava1 = AVA(self.attr1, self.value1) - - self.assertTrue(ava1 == self.ava1) - self.assertFalse(ava1 != self.ava1) - - result = cmp(ava1, self.ava1) - self.assertEqual(result, 0) - - # Upper case attr should still be equal - ava1 = AVA(self.attr1.upper(), self.value1) - - self.assertFalse(ava1.attr == self.attr1) - self.assertTrue(ava1.value == self.value1) - self.assertTrue(ava1 == self.ava1) - self.assertFalse(ava1 != self.ava1) - - result = cmp(ava1, self.ava1) - self.assertEqual(result, 0) - - # Upper case value should still be equal - ava1 = AVA(self.attr1, self.value1.upper()) - - self.assertTrue(ava1.attr == self.attr1) - self.assertFalse(ava1.value == self.value1) - self.assertTrue(ava1 == self.ava1) - self.assertFalse(ava1 != self.ava1) - - result = cmp(ava1, self.ava1) - self.assertEqual(result, 0) - - # Make ava1's attr greater - ava1.attr = self.attr1 + "1" - - self.assertFalse(ava1 == self.ava1) - self.assertTrue(ava1 != self.ava1) - - result = cmp(ava1, self.ava1) - self.assertEqual(result, 1) - - result = cmp(self.ava1, ava1) - self.assertEqual(result, -1) - - # Reset ava1's attr, should be equal again - ava1.attr = self.attr1 - - result = cmp(ava1, self.ava1) - self.assertEqual(result, 0) - - # Make ava1's value greater - # attr will be equal, this tests secondary comparision component - ava1.value = self.value1 + "1" - - result = cmp(ava1, self.ava1) - self.assertEqual(result, 1) - - result = cmp(self.ava1, ava1) - self.assertEqual(result, -1) - -class TestRDN(unittest.TestCase): - def setUp(self): - # ava1 must sort before ava2 - self.attr1 = 'cn' - self.value1 = 'Bob' - self.str_ava1 = '%s=%s' % (self.attr1, self.value1) - self.ava1 = AVA(self.attr1, self.value1) - - self.str_rdn1 = '%s=%s' % (self.attr1, self.value1) - self.rdn1 = RDN((self.attr1, self.value1)) - - self.attr2 = 'ou' - self.value2 = 'people' - self.str_ava2 = '%s=%s' % (self.attr2, self.value2) - self.ava2 = AVA(self.attr2, self.value2) - - self.str_rdn2 = '%s=%s' % (self.attr2, self.value2) - self.rdn2 = RDN((self.attr2, self.value2)) - - self.str_ava3 = '%s=%s+%s=%s' % (self.attr1, self.value1, self.attr2, self.value2) - - self.str_rdn3 = '%s=%s+%s=%s' % (self.attr1, self.value1, self.attr2, self.value2) - self.rdn3 = RDN(self.ava1, self.ava2) - - def test_create(self): - # Create with single attr,value pair - rdn1 = RDN((self.attr1, self.value1)) - self.assertEqual(len(rdn1), 1) - self.assertEqual(rdn1, self.rdn1) - self.assertIsInstance(rdn1[0], AVA) - self.assertEqual(rdn1[0], self.ava1) - - # Create with multiple attr,value pairs - rdn3 = RDN((self.attr1, self.value1), (self.attr2, self.value2)) - self.assertEqual(len(rdn3), 2) - self.assertEqual(rdn3, self.rdn3) - self.assertIsInstance(rdn3[0], AVA) - self.assertEqual(rdn3[0], self.ava1) - self.assertIsInstance(rdn3[1], AVA) - self.assertEqual(rdn3[1], self.ava2) - - # Create with multiple attr,value pairs passed as lists - rdn3 = RDN([self.attr1, self.value1], [self.attr2, self.value2]) - self.assertEqual(len(rdn3), 2) - self.assertEqual(rdn3, self.rdn3) - self.assertIsInstance(rdn3[0], AVA) - self.assertEqual(rdn3[0], self.ava1) - self.assertIsInstance(rdn3[1], AVA) - self.assertEqual(rdn3[1], self.ava2) - - # Create with multiple attr,value pairs but reverse - # constructor parameter ordering. RDN canonical ordering - # should remain the same - rdn3 = RDN((self.attr2, self.value2), (self.attr1, self.value1)) - self.assertEqual(len(rdn3), 2) - self.assertEqual(rdn3, self.rdn3) - self.assertIsInstance(rdn3[0], AVA) - self.assertEqual(rdn3[0], self.ava1) - self.assertIsInstance(rdn3[1], AVA) - self.assertEqual(rdn3[1], self.ava2) - - # Create with single AVA object - rdn1 = RDN(self.ava1) - self.assertEqual(len(rdn1), 1) - self.assertEqual(rdn1, self.rdn1) - self.assertIsInstance(rdn1[0], AVA) - self.assertEqual(rdn1[0], self.ava1) - - # Create with multiple AVA objects - rdn3 = RDN(self.ava1, self.ava2) - self.assertEqual(len(rdn3), 2) - self.assertEqual(rdn3, self.rdn3) - self.assertIsInstance(rdn3[0], AVA) - self.assertEqual(rdn3[0], self.ava1) - self.assertIsInstance(rdn3[1], AVA) - self.assertEqual(rdn3[1], self.ava2) - - - # Create with multiple AVA objects but reverse constructor - # parameter ordering. RDN canonical ordering should remain - # the same - rdn3 = RDN(self.ava2, self.ava1) - self.assertEqual(len(rdn3), 2) - self.assertEqual(rdn3, self.rdn3) - self.assertIsInstance(rdn3[0], AVA) - self.assertEqual(rdn3[0], self.ava1) - self.assertIsInstance(rdn3[1], AVA) - self.assertEqual(rdn3[1], self.ava2) - - # Create with single string with 1 AVA - rdn1 = RDN(self.str_rdn1) - self.assertEqual(len(rdn1), 1) - self.assertEqual(rdn1, self.rdn1) - self.assertIsInstance(rdn1[0], AVA) - self.assertEqual(rdn1[0], self.ava1) - - # Create with single string with 2 AVA's - rdn3 = RDN(self.str_rdn3) - self.assertEqual(len(rdn3), 2) - self.assertEqual(rdn3, self.rdn3) - self.assertIsInstance(rdn3[0], AVA) - self.assertEqual(rdn3[0], self.ava1) - self.assertIsInstance(rdn3[1], AVA) - self.assertEqual(rdn3[1], self.ava2) - - def test_properties(self): - self.assertEqual(self.rdn1.attr, self.attr1) - self.assertIsInstance(self.rdn1.attr, unicode) - - self.assertEqual(self.rdn1.value, self.value1) - self.assertIsInstance(self.rdn1.value, unicode) - - self.assertEqual(self.rdn2.attr, self.attr2) - self.assertIsInstance(self.rdn2.attr, unicode) - - self.assertEqual(self.rdn2.value, self.value2) - self.assertIsInstance(self.rdn2.value, unicode) - - self.assertEqual(self.rdn3.attr, self.attr1) - self.assertIsInstance(self.rdn3.attr, unicode) - - self.assertEqual(self.rdn3.value, self.value1) - self.assertIsInstance(self.rdn3.value, unicode) - - def test_str(self): - self.assertEqual(str(self.rdn1), self.str_rdn1) - self.assertIsInstance(str(self.rdn1), str) - - self.assertEqual(str(self.rdn2), self.str_rdn2) - self.assertIsInstance(str(self.rdn2), str) - - self.assertEqual(str(self.rdn3), self.str_rdn3) - self.assertIsInstance(str(self.rdn3), str) - - def test_cmp(self): - # Equality - rdn1 = RDN((self.attr1, self.value1)) - - self.assertTrue(rdn1 == self.rdn1) - self.assertFalse(rdn1 != self.rdn1) - - result = cmp(rdn1, self.rdn1) - self.assertEqual(result, 0) - - # Make rdn1's attr greater - rdn1.attr = self.attr1 + "1" - - self.assertFalse(rdn1 == self.rdn1) - self.assertTrue(rdn1 != self.rdn1) - - result = cmp(rdn1, self.rdn1) - self.assertEqual(result, 1) - - result = cmp(self.rdn1, rdn1) - self.assertEqual(result, -1) - - # Reset rdn1's attr, should be equal again - rdn1.attr = self.attr1 - - result = cmp(rdn1, self.rdn1) - self.assertEqual(result, 0) - - # Make rdn1's value greater - # attr will be equal, this tests secondary comparision component - rdn1.value = self.value1 + "1" - - result = cmp(rdn1, self.rdn1) - self.assertEqual(result, 1) - - result = cmp(self.rdn1, rdn1) - self.assertEqual(result, -1) - - # Make sure rdn's with more ava's are greater - result = cmp(self.rdn1, self.rdn3) - self.assertEqual(result, -1) - result = cmp(self.rdn3, self.rdn1) - self.assertEqual(result, 1) - - def test_indexing(self): - self.assertEqual(self.rdn1[0], self.ava1) - self.assertEqual(self.rdn1[self.ava1.attr], self.ava1.value) - with self.assertRaises(KeyError): - self.rdn1['foo'] - - self.assertEqual(self.rdn2[0], self.ava2) - self.assertEqual(self.rdn2[self.ava2.attr], self.ava2.value) - with self.assertRaises(KeyError): - self.rdn2['foo'] - - self.assertEqual(self.rdn3[0], self.ava1) - self.assertEqual(self.rdn3[self.ava1.attr], self.ava1.value) - self.assertEqual(self.rdn3[1], self.ava2) - self.assertEqual(self.rdn3[self.ava2.attr], self.ava2.value) - with self.assertRaises(KeyError): - self.rdn3['foo'] - - self.assertEqual(self.rdn1.attr, self.attr1) - self.assertEqual(self.rdn1.value, self.value1) - - with self.assertRaises(TypeError): - self.rdn3[1.0] - - # Slices - self.assertEqual(self.rdn3[0:1], [self.ava1]) - self.assertEqual(self.rdn3[:], [self.ava1, self.ava2]) - - def test_assignments(self): - rdn = RDN((self.attr1, self.value1)) - rdn[0] = self.ava2 - self.assertEqual(rdn, self.rdn2) - - rdn = RDN((self.attr1, self.value1)) - rdn[0] = (self.attr2, self.value2) - self.assertEqual(rdn, self.rdn2) - - rdn = RDN((self.attr1, self.value1)) - rdn[self.attr1] = self.str_ava2 - self.assertEqual(rdn[0], self.ava2) - - # Can't assign multiples to single entry - rdn = RDN((self.attr1, self.value1)) - with self.assertRaises(TypeError): - rdn[self.attr1] = self.str_ava3 - - rdn = RDN((self.attr1, self.value1)) - with self.assertRaises(TypeError): - rdn[self.attr1] = (self.attr1, self.value1, self.attr2, self.value2) - - rdn = RDN((self.attr1, self.value1)) - with self.assertRaises(TypeError): - rdn[self.attr1] = [(self.attr1, self.value1), (self.attr2, self.value2)] - - # Slices - rdn = RDN((self.attr1, self.value1)) - self.assertEqual(rdn, self.rdn1) - rdn[0:1] = [self.ava2] - self.assertEqual(rdn, self.rdn2) - - rdn = RDN((self.attr1, self.value1)) - self.assertEqual(rdn, self.rdn1) - rdn[:] = [(self.attr2, self.value2)] - self.assertEqual(rdn, self.rdn2) - - rdn = RDN((self.attr1, self.value1)) - self.assertEqual(rdn, self.rdn1) - rdn[:] = [(self.attr1, self.value1),(self.attr2, self.value2)] - self.assertEqual(rdn, self.rdn3) - - rdn = RDN((self.attr1, self.value1)) - self.assertEqual(rdn, self.rdn1) - rdn[0:1] = [(self.attr1, self.value1), (self.attr2, self.value2)] - self.assertEqual(rdn, self.rdn3) - - - def test_iter(self): - self.assertEqual(len(self.rdn1), 1) - self.assertEqual(self.rdn1[:], [self.ava1]) - for i, ava in enumerate(self.rdn1): - if i == 0: - self.assertEqual(ava, self.ava1) - else: - self.fail("got iteration index %d, but len=%d" % (i, len(self.rdn1))) - - self.assertEqual(len(self.rdn2), 1) - self.assertEqual(self.rdn2[:], [self.ava2]) - for i, ava in enumerate(self.rdn2): - if i == 0: - self.assertEqual(ava, self.ava2) - else: - self.fail("got iteration index %d, but len=%d" % (i, len(self.rdn2))) - - self.assertEqual(len(self.rdn3), 2) - self.assertEqual(self.rdn3[:], [self.ava1, self.ava2]) - for i, ava in enumerate(self.rdn3): - if i == 0: - self.assertEqual(ava, self.ava1) - elif i == 1: - self.assertEqual(ava, self.ava2) - else: - self.fail("got iteration index %d, but len=%d" % (i, len(self.rdn3))) - - - def test_concat(self): - rdn1 = RDN((self.attr1, self.value1)) - rdn2 = RDN((self.attr2, self.value2)) - - # in-place addtion - rdn1 += rdn2 - self.assertEqual(rdn1, self.rdn3) - - rdn1 = RDN((self.attr1, self.value1)) - rdn1 += self.ava2 - self.assertEqual(rdn1, self.rdn3) - - rdn1 = RDN((self.attr1, self.value1)) - rdn1 += self.str_ava2 - self.assertEqual(rdn1, self.rdn3) - - # concatenation - rdn1 = RDN((self.attr1, self.value1)) - rdn3 = rdn1 + rdn2 - self.assertEqual(rdn3, self.rdn3) - - rdn3 = rdn1 + self.ava2 - self.assertEqual(rdn3, self.rdn3) - - rdn3 = rdn1 + self.str_ava2 - self.assertEqual(rdn3, self.rdn3) - - -class TestDN(unittest.TestCase): - def setUp(self): - # ava1 must sort before ava2 - self.attr1 = 'cn' - self.value1 = 'Bob' - self.str_ava1 = '%s=%s' % (self.attr1, self.value1) - self.ava1 = AVA(self.attr1, self.value1) - - self.str_rdn1 = '%s=%s' % (self.attr1, self.value1) - self.rdn1 = RDN((self.attr1, self.value1)) - - self.attr2 = 'ou' - self.value2 = 'people' - self.str_ava2 = '%s=%s' % (self.attr2, self.value2) - self.ava2 = AVA(self.attr2, self.value2) - - self.str_rdn2 = '%s=%s' % (self.attr2, self.value2) - self.rdn2 = RDN((self.attr2, self.value2)) - - self.str_dn1 = self.str_rdn1 - self.dn1 = DN(self.rdn1) - - self.str_dn2 = self.str_rdn2 - self.dn2 = DN(self.rdn2) - - self.str_dn3 = '%s,%s' % (self.str_rdn1, self.str_rdn2) - self.dn3 = DN(self.rdn1, self.rdn2) - - self.base_rdn1 = RDN(('dc', 'redhat')) - self.base_rdn2 = RDN(('dc', 'com')) - self.base_dn = DN(self.base_rdn1, self.base_rdn2) - - self.container_rdn1 = RDN(('cn', 'sudorules')) - self.container_rdn2 = RDN(('cn', 'sudo')) - self.container_dn = DN(self.container_rdn1, self.container_rdn2) - - self.base_container_dn = DN((self.attr1, self.value1), - self.container_dn, self.base_dn) - - - def test_create(self): - # Create with single attr,value pair - dn1 = DN((self.attr1, self.value1)) - self.assertEqual(len(dn1), 1) - self.assertIsInstance(dn1[0], RDN) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0], self.rdn1) - - # Create with single attr,value pair passed as a tuple - dn1 = DN((self.attr1, self.value1)) - self.assertEqual(len(dn1), 1) - self.assertIsInstance(dn1[0], RDN) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0], self.rdn1) - - # Creation with multiple attr,value string pairs should fail - with self.assertRaises(ValueError): - dn1 = DN(self.attr1, self.value1, self.attr2, self.value2) - - # Create with multiple attr,value pairs passed as tuples & lists - dn1 = DN((self.attr1, self.value1), [self.attr2, self.value2]) - self.assertEqual(len(dn1), 2) - self.assertIsInstance(dn1[0], RDN) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0], self.rdn1) - self.assertIsInstance(dn1[1], RDN) - self.assertIsInstance(dn1[1].attr, unicode) - self.assertIsInstance(dn1[1].value, unicode) - self.assertEqual(dn1[1], self.rdn2) - - # Create with multiple attr,value pairs passed as tuple and RDN - dn1 = DN((self.attr1, self.value1), RDN((self.attr2, self.value2))) - self.assertEqual(len(dn1), 2) - self.assertIsInstance(dn1[0], RDN) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0], self.rdn1) - self.assertIsInstance(dn1[1], RDN) - self.assertIsInstance(dn1[1].attr, unicode) - self.assertIsInstance(dn1[1].value, unicode) - self.assertEqual(dn1[1], self.rdn2) - - # Create with multiple attr,value pairs but reverse - # constructor parameter ordering. RDN ordering should also be - # reversed because DN's are a ordered sequence of RDN's - dn1 = DN((self.attr2, self.value2), (self.attr1, self.value1)) - self.assertEqual(len(dn1), 2) - self.assertIsInstance(dn1[0], RDN) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0], self.rdn2) - self.assertIsInstance(dn1[1], RDN) - self.assertIsInstance(dn1[1].attr, unicode) - self.assertIsInstance(dn1[1].value, unicode) - self.assertEqual(dn1[1], self.rdn1) - - # Create with single RDN object - dn1 = DN(self.rdn1) - self.assertEqual(len(dn1), 1) - self.assertIsInstance(dn1[0], RDN) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0], self.rdn1) - - # Create with multiple RDN objects, assure ordering is preserved. - dn1 = DN(self.rdn1, self.rdn2) - self.assertEqual(len(dn1), 2) - self.assertIsInstance(dn1[0], RDN) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0], self.rdn1) - self.assertIsInstance(dn1[1], RDN) - self.assertIsInstance(dn1[1].attr, unicode) - self.assertIsInstance(dn1[1].value, unicode) - self.assertEqual(dn1[1], self.rdn2) - - # Create with multiple RDN objects in different order, assure - # ordering is preserved. - dn1 = DN(self.rdn2, self.rdn1) - self.assertEqual(len(dn1), 2) - self.assertIsInstance(dn1[0], RDN) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0], self.rdn2) - self.assertIsInstance(dn1[1], RDN) - self.assertIsInstance(dn1[1].attr, unicode) - self.assertIsInstance(dn1[1].value, unicode) - self.assertEqual(dn1[1], self.rdn1) - - # Create with single string with 1 RDN - dn1 = DN(self.str_rdn1) - self.assertEqual(len(dn1), 1) - self.assertIsInstance(dn1[0], RDN) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0], self.rdn1) - - # Create with single string with 2 RDN's - dn1 = DN(self.str_dn3) - self.assertEqual(len(dn1), 2) - self.assertIsInstance(dn1[0], RDN) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0], self.rdn1) - self.assertIsInstance(dn1[1], RDN) - self.assertIsInstance(dn1[1].attr, unicode) - self.assertIsInstance(dn1[1].value, unicode) - self.assertEqual(dn1[1], self.rdn2) - - # Create with RDN, and 2 DN's (e.g. attr + container + base) - dn1 = DN((self.attr1, self.value1), self.container_dn, self.base_dn) - self.assertEqual(len(dn1), 5) - dn_str = ','.join([str(self.rdn1), - str(self.container_rdn1), str(self.container_rdn2), - str(self.base_rdn1), str(self.base_rdn2)]) - self.assertEqual(str(dn1), dn_str) - - def test_str(self): - self.assertEqual(str(self.dn1), self.str_dn1) - self.assertIsInstance(str(self.dn1), str) - - self.assertEqual(str(self.dn2), self.str_dn2) - self.assertIsInstance(str(self.dn2), str) - - self.assertEqual(str(self.dn3), self.str_dn3) - self.assertIsInstance(str(self.dn3), str) - - def test_cmp(self): - # Equality - dn1 = DN((self.attr1, self.value1)) - - self.assertTrue(dn1 == self.dn1) - self.assertFalse(dn1 != self.dn1) - - result = cmp(dn1, self.dn1) - self.assertEqual(result, 0) - - # Make dn1's attr greater - dn1[0].attr = self.attr1 + "1" - - self.assertFalse(dn1 == self.dn1) - self.assertTrue(dn1 != self.dn1) - - result = cmp(dn1, self.dn1) - self.assertEqual(result, 1) - - result = cmp(self.dn1, dn1) - self.assertEqual(result, -1) - - # Reset dn1's attr, should be equal again - dn1[0].attr = self.attr1 - - result = cmp(dn1, self.dn1) - self.assertEqual(result, 0) - - # Make dn1's value greater - # attr will be equal, this tests secondary comparision component - dn1[0].value = self.value1 + "1" - - result = cmp(dn1, self.dn1) - self.assertEqual(result, 1) - - result = cmp(self.dn1, dn1) - self.assertEqual(result, -1) - - # Make sure dn's with more rdn's are greater - result = cmp(self.dn1, self.dn3) - self.assertEqual(result, -1) - result = cmp(self.dn3, self.dn1) - self.assertEqual(result, 1) - - # Test startswith, endswith - self.assertTrue(self.base_container_dn.startswith(self.rdn1)) - self.assertTrue(self.base_container_dn.startswith(self.dn1)) - self.assertTrue(self.base_container_dn.startswith(self.dn1 + self.container_dn)) - self.assertFalse(self.base_container_dn.startswith(self.dn2)) - self.assertFalse(self.base_container_dn.startswith(self.rdn2)) - self.assertTrue(self.base_container_dn.startswith((self.dn1))) - self.assertTrue(self.base_container_dn.startswith((self.rdn1))) - self.assertFalse(self.base_container_dn.startswith((self.rdn2))) - self.assertTrue(self.base_container_dn.startswith((self.rdn2, self.rdn1))) - self.assertTrue(self.base_container_dn.startswith((self.dn1, self.dn2))) - - self.assertTrue(self.base_container_dn.endswith(self.base_dn)) - self.assertTrue(self.base_container_dn.endswith(self.container_dn + self.base_dn)) - self.assertFalse(self.base_container_dn.endswith(DN(self.base_rdn1))) - self.assertTrue(self.base_container_dn.endswith(DN(self.base_rdn2))) - self.assertTrue(self.base_container_dn.endswith((DN(self.base_rdn1), DN(self.base_rdn2)))) - - # Test "in" membership - self.assertTrue(self.container_rdn1 in self.container_dn) - self.assertTrue(self.container_dn in self.container_dn) - self.assertFalse(self.base_rdn1 in self.container_dn) - - self.assertTrue(self.container_rdn1 in self.base_container_dn) - self.assertTrue(self.container_dn in self.base_container_dn) - self.assertTrue(self.container_dn + self.base_dn in - self.base_container_dn) - self.assertTrue(self.dn1 + self.container_dn + self.base_dn in - self.base_container_dn) - self.assertTrue(self.dn1 + self.container_dn + self.base_dn == - self.base_container_dn) - - self.assertFalse(self.container_rdn1 in self.base_dn) - - def test_indexing(self): - self.assertEqual(self.dn1[0], self.rdn1) - self.assertEqual(self.dn1[self.rdn1.attr], self.rdn1.value) - with self.assertRaises(KeyError): - self.dn1['foo'] - - self.assertEqual(self.dn2[0], self.rdn2) - self.assertEqual(self.dn2[self.rdn2.attr], self.rdn2.value) - with self.assertRaises(KeyError): - self.dn2['foo'] - - self.assertEqual(self.dn3[0], self.rdn1) - self.assertEqual(self.dn3[self.rdn1.attr], self.rdn1.value) - self.assertEqual(self.dn3[1], self.rdn2) - self.assertEqual(self.dn3[self.rdn2.attr], self.rdn2.value) - with self.assertRaises(KeyError): - self.dn3['foo'] - - with self.assertRaises(TypeError): - self.dn3[1.0] - - def test_assignments(self): - dn_low = 0 - dn_high = 6 - - rdn_args = make_rdn_args(dn_low, dn_high, 'tuple', - default_rdn_attr_arg, default_rdn_value_arg) - dn1 = DN(*rdn_args) - - rdn_args = make_rdn_args(dn_low, dn_high, 'list', - default_rdn_attr_arg, default_rdn_value_arg) - dn2 = DN(*rdn_args) - - rdn_args = make_rdn_args(dn_low, dn_high, 'RDN', - default_rdn_attr_arg, default_rdn_value_arg) - dn3 = DN(*rdn_args) - - self.assertEqual(dn1, dn2) - self.assertEqual(dn1, dn3) - - for i in range(dn_low, dn_high): - attr = default_rdn_attr_arg(i) - value = default_rdn_value_arg(i) - self.assertEqual(dn1[i].attr, attr) - self.assertEqual(dn1[i].value, value) - self.assertEqual(dn1[attr], value) - - for i in range(dn_low, dn_high): - if i % 2: - orig_attr = default_rdn_attr_arg(i) - attr = alt_rdn_attr_arg(i) - value = alt_rdn_value_arg(i) - dn1[i] = attr, value - dn2[orig_attr] = (attr, value) - dn3[i] = RDN((attr, value)) - - self.assertEqual(dn1, dn2) - self.assertEqual(dn1, dn3) - - for i in range(dn_low, dn_high): - if i % 2: - attr = alt_rdn_attr_arg(i) - value = alt_rdn_value_arg(i) - else: - attr = default_rdn_attr_arg(i) - value = default_rdn_value_arg(i) - self.assertEqual(dn1[i].value, dn1[i].value) - self.assertEqual(dn1[attr], value) - - # Slices - slice_low = 2 - slice_high = 4 - interval = range(slice_low, slice_high) - - # Slices - # Assign via tuple - rdn_args = make_rdn_args(dn_low, dn_high, 'tuple', - default_rdn_attr_arg, default_rdn_value_arg) - dn1 = DN(*rdn_args) - - dn_slice = make_rdn_args(slice_low, slice_high, 'tuple', - alt_rdn_attr_arg, alt_rdn_value_arg) - - dn1[slice_low:slice_high] = dn_slice - - for i in range(dn_low, dn_high): - if i in interval: - attr = alt_rdn_attr_arg(i) - value = alt_rdn_value_arg(i) - else: - attr = default_rdn_attr_arg(i) - value = default_rdn_value_arg(i) - self.assertEqual(dn1[i].value, dn1[i].value) - self.assertEqual(dn1[attr], value) - - query_slice = dn1[slice_low:slice_high] - for i, query_rdn in enumerate(query_slice): - slice_rdn = RDN(dn_slice[i]) - self.assertEqual(slice_rdn, query_rdn) - - # insert - dn = DN(self.rdn2) - dn.insert(0, self.rdn1) - self.assertEqual(dn, self.dn3) - - dn = DN(self.rdn1) - dn.insert(1, (self.attr2, self.value2)) - self.assertEqual(dn, self.dn3) - - # Slices - # Assign via RDN - rdn_args = make_rdn_args(dn_low, dn_high, 'tuple', - default_rdn_attr_arg, default_rdn_value_arg) - dn1 = DN(*rdn_args) - - dn_slice = make_rdn_args(slice_low, slice_high, 'RDN', - alt_rdn_attr_arg, alt_rdn_value_arg) - - dn1[slice_low:slice_high] = dn_slice - - for i in range(dn_low, dn_high): - if i in interval: - attr = alt_rdn_attr_arg(i) - value = alt_rdn_value_arg(i) - else: - attr = default_rdn_attr_arg(i) - value = default_rdn_value_arg(i) - self.assertEqual(dn1[i].value, dn1[i].value) - self.assertEqual(dn1[attr], value) - - query_slice = dn1[slice_low:slice_high] - for i, query_rdn in enumerate(query_slice): - slice_rdn = dn_slice[i] - self.assertEqual(slice_rdn, query_rdn) - - - def test_iter(self): - self.assertEqual(len(self.dn1), 1) - self.assertEqual(self.dn1[:], [self.rdn1]) - for i, ava in enumerate(self.dn1): - if i == 0: - self.assertEqual(ava, self.rdn1) - else: - self.fail("got iteration index %d, but len=%d" % (i, len(self.rdn1))) - - self.assertEqual(len(self.dn2), 1) - self.assertEqual(self.dn2[:], [self.rdn2]) - for i, ava in enumerate(self.dn2): - if i == 0: - self.assertEqual(ava, self.rdn2) - else: - self.fail("got iteration index %d, but len=%d" % (i, len(self.rdn2))) - - self.assertEqual(len(self.dn3), 2) - self.assertEqual(self.dn3[:], [self.rdn1, self.rdn2]) - for i, ava in enumerate(self.dn3): - if i == 0: - self.assertEqual(ava, self.rdn1) - elif i == 1: - self.assertEqual(ava, self.rdn2) - else: - self.fail("got iteration index %d, but len=%d" % (i, len(self.dn3))) - - - def test_concat(self): - dn1 = DN((self.attr1, self.value1)) - dn2 = DN([self.attr2, self.value2]) - - # in-place addtion - dn1 += dn2 - self.assertEqual(dn1, self.dn3) - - dn1 = DN((self.attr1, self.value1)) - dn1 += self.rdn2 - self.assertEqual(dn1, self.dn3) - - dn1 = DN((self.attr1, self.value1)) - dn1 += self.dn2 - self.assertEqual(dn1, self.dn3) - - dn1 = DN((self.attr1, self.value1)) - dn1 += self.str_dn2 - self.assertEqual(dn1, self.dn3) - - # concatenation - dn1 = DN((self.attr1, self.value1)) - dn3 = dn1 + dn2 - self.assertEqual(dn3, self.dn3) - - dn1 = DN((self.attr1, self.value1)) - dn3 = dn1 + self.rdn2 - self.assertEqual(dn3, self.dn3) - - dn3 = dn1 + self.str_rdn2 - self.assertEqual(dn3, self.dn3) - - dn3 = dn1 + self.str_dn2 - self.assertEqual(dn3, self.dn3) - - dn3 = dn1 + self.dn2 - self.assertEqual(dn3, self.dn3) - -class TestEscapes(unittest.TestCase): - def setUp(self): - self.privilege = 'R,W privilege' - self.dn_str_hex_escape = 'cn=R\\2cW privilege,cn=privileges,cn=pbac,dc=idm,dc=lab,dc=bos,dc=redhat,dc=com' - self.dn_str_backslash_escape = 'cn=R\\,W privilege,cn=privileges,cn=pbac,dc=idm,dc=lab,dc=bos,dc=redhat,dc=com' - - def test_escape(self): - dn = DN(self.dn_str_hex_escape) - self.assertEqual(dn['cn'], self.privilege) - self.assertEqual(dn[0].value, self.privilege) - - dn = DN(self.dn_str_backslash_escape) - self.assertEqual(dn['cn'], self.privilege) - self.assertEqual(dn[0].value, self.privilege) - -class TestInternationalization(unittest.TestCase): - def setUp(self): - # Hello in Arabic - self.arabic_hello_utf8 = '\xd9\x85\xd9\x83\xd9\x8a\xd9\x84' + \ - '\xd8\xb9\x20\xd9\x85\xd8\xa7\xd9' + \ - '\x84\xd9\x91\xd8\xb3\xd9\x84\xd8\xa7' - - self.arabic_hello_unicode = self.arabic_hello_utf8.decode('utf-8') - - def test_i18n(self): - self.assertEqual(self.arabic_hello_utf8, - self.arabic_hello_unicode.encode('utf-8')) - - # AVA's - # test attr i18n - ava1 = AVA(self.arabic_hello_unicode, 'foo') - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - self.assertEqual(ava1.attr, self.arabic_hello_unicode) - self.assertEqual(str(ava1), self.arabic_hello_utf8+'=foo') - - ava1 = AVA(self.arabic_hello_utf8, 'foo') - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - self.assertEqual(ava1.attr, self.arabic_hello_unicode) - self.assertEqual(str(ava1), self.arabic_hello_utf8+'=foo') - - # test value i18n - ava1 = AVA('cn', self.arabic_hello_unicode) - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - self.assertEqual(ava1.value, self.arabic_hello_unicode) - self.assertEqual(str(ava1), 'cn='+self.arabic_hello_utf8) - - ava1 = AVA('cn', self.arabic_hello_utf8) - self.assertIsInstance(ava1.attr, unicode) - self.assertIsInstance(ava1.value, unicode) - self.assertEqual(ava1.value, self.arabic_hello_unicode) - self.assertEqual(str(ava1), 'cn='+self.arabic_hello_utf8) - - # RDN's - # test attr i18n - rdn1 = RDN((self.arabic_hello_unicode, 'foo')) - self.assertIsInstance(rdn1.attr, unicode) - self.assertIsInstance(rdn1.value, unicode) - self.assertEqual(rdn1.attr, self.arabic_hello_unicode) - self.assertEqual(str(rdn1), self.arabic_hello_utf8+'=foo') - - rdn1 = RDN((self.arabic_hello_utf8, 'foo')) - self.assertIsInstance(rdn1.attr, unicode) - self.assertIsInstance(rdn1.value, unicode) - self.assertEqual(rdn1.attr, self.arabic_hello_unicode) - self.assertEqual(str(rdn1), self.arabic_hello_utf8+'=foo') - - # test value i18n - rdn1 = RDN(('cn', self.arabic_hello_unicode)) - self.assertIsInstance(rdn1.attr, unicode) - self.assertIsInstance(rdn1.value, unicode) - self.assertEqual(rdn1.value, self.arabic_hello_unicode) - self.assertEqual(str(rdn1), 'cn='+self.arabic_hello_utf8) - - rdn1 = RDN(('cn', self.arabic_hello_utf8)) - self.assertIsInstance(rdn1.attr, unicode) - self.assertIsInstance(rdn1.value, unicode) - self.assertEqual(rdn1.value, self.arabic_hello_unicode) - self.assertEqual(str(rdn1), 'cn='+self.arabic_hello_utf8) - - # DN's - # test attr i18n - dn1 = DN((self.arabic_hello_unicode, 'foo')) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0].attr, self.arabic_hello_unicode) - self.assertEqual(str(dn1), self.arabic_hello_utf8+'=foo') - - dn1 = DN((self.arabic_hello_utf8, 'foo')) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0].attr, self.arabic_hello_unicode) - self.assertEqual(str(dn1), self.arabic_hello_utf8+'=foo') - - # test value i18n - dn1 = DN(('cn', self.arabic_hello_unicode)) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0].value, self.arabic_hello_unicode) - self.assertEqual(str(dn1), 'cn='+self.arabic_hello_utf8) - - dn1 = DN(('cn', self.arabic_hello_utf8)) - self.assertIsInstance(dn1[0].attr, unicode) - self.assertIsInstance(dn1[0].value, unicode) - self.assertEqual(dn1[0].value, self.arabic_hello_unicode) - self.assertEqual(str(dn1), 'cn='+self.arabic_hello_utf8) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/test_ipalib/test_encoder.py b/tests/test_ipalib/test_encoder.py deleted file mode 100644 index 430eda04..00000000 --- a/tests/test_ipalib/test_encoder.py +++ /dev/null @@ -1,149 +0,0 @@ -# encoding: utf-8 -# Authors: -# Pavel Zuna <pzuna@redhat.com> -# -# Copyright (C) 2009 Red Hat -# see file 'COPYING' for use and warranty information -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -""" -Test the `ipalib.encoder` module. -""" - -import string - -from tests.util import ClassChecker, assert_equal -from ipalib.encoder import Encoder, EncoderSettings, encode_args, decode_retval - -_encoder_settings = EncoderSettings() - -_test_str_d = u'ěščřžýáíé' -_test_str_e = u'ěščřžýáíé'.encode(_encoder_settings.encode_to) - - -class test_Encoder(ClassChecker): - """ - Test the `ipalib.encoder.Encoder` class. - """ - _cls = Encoder - - def test_encode(self): - """ - Test the `ipalib.encoder.Encoder.encode` method. - """ - o = self.cls() - encode_to = o.encoder_settings.encode_to - o.encoder_settings.encode_postprocessor = lambda x: x - # strings - assert_equal(o.encode('ahoj'), 'ahoj'.encode(encode_to)) - assert_equal(o.encode(_test_str_d), _test_str_e) - # bool, float, int, long - assert_equal(o.encode(True), 'TRUE'.encode(encode_to)) - assert_equal(o.encode(1.01), str(1.01).encode(encode_to)) - assert_equal(o.encode(1000), str(1000).encode(encode_to)) - assert_equal(o.encode(long(1)), str(long(1)).encode(encode_to)) - # lists - expected = [_test_str_e, '1'] - assert_equal(o.encode([_test_str_d, 1]), expected) - expected = ['1', ['1', '2', '3']] - assert_equal(o.encode([1, [1, 2, 3]]), expected) - # tuples - expected = (_test_str_e, '1') - assert_equal(o.encode((_test_str_d, 1)), expected) - expected = ('1', ('1', '2', '3')) - assert_equal(o.encode((1, (1, 2, 3))), expected) - # dicts: only values, no postprocessing - o.encoder_settings.encode_dict_keys = False - o.encoder_settings.encode_dict_keys_postprocess = False - o.encoder_settings.encode_dict_vals = True - o.encoder_settings.encode_dict_vals_postprocess = False - expected = {_test_str_d: _test_str_e} - assert_equal(o.encode({_test_str_d: _test_str_d}), expected) - # dicts: only keys, no postprocessing - o.encoder_settings.encode_dict_keys = True - o.encoder_settings.encode_dict_vals = False - expected = {_test_str_e: _test_str_d} - assert_equal(o.encode({_test_str_d: _test_str_d}), expected) - # dicts: both keys and values, no postprocessing - o.encoder_settings.encode_dict_vals = True - expected = {_test_str_e: _test_str_e} - assert_equal(o.encode({_test_str_d: _test_str_d}), expected) - # dicts: both keys and values, postprocessing on keys only - o.encoder_settings.encode_dict_keys = True - o.encoder_settings.encode_dict_keys_postprocess = True - o.encoder_settings.encode_postprocessor = string.upper - expected = {_test_str_e.upper(): _test_str_e} - assert_equal(o.encode({u'ěščřžýáíé': u'ěščřžýáíé'}), expected) - # None - o.encoder_settings.encode_postprocessor = lambda x: x - o.encoder_settings.encode_none = False - assert_equal(o.encode(None), None) - o.encoder_settings.encode_none = True - assert_equal(o.encode(None), str(None).encode(encode_to)) - - def test_decode(self): - """ - Test the `ipalib.encoder.Encoder.decode` method. - """ - o = self.cls() - decode_from = o.encoder_settings.decode_from - o.encoder_settings.decode_postprocessor = lambda x: x - # strings - assert_equal(o.decode('ahoj'), 'ahoj'.decode(decode_from)) - assert_equal(o.decode(_test_str_e), _test_str_d) - # bool, float, int, long - assert_equal(o.decode('True'), str(True).decode(decode_from)) - assert_equal(o.decode('1.01'), str(1.01).decode(decode_from)) - assert_equal(o.decode('1000'), str(1000).decode(decode_from)) - assert_equal(o.decode('1'), str(long(1)).decode(decode_from)) - # lists - expected = [_test_str_d, '1'] - assert_equal(o.decode([_test_str_e, '1']), expected) - expected = [u'1', [u'1', u'2', u'3']] - assert_equal(o.decode(['1', ['1', '2', '3']]), expected) - # tuples - expected = (_test_str_d, 1) - assert_equal(o.decode((_test_str_e, 1)), expected) - expected = (u'1', (u'1', u'2', u'3')) - assert_equal(o.decode(('1', ('1', '2', '3'))), expected) - # dicts: only values, no postprocessing - o.encoder_settings.decode_dict_keys = False - o.encoder_settings.decode_dict_keys_postprocess = False - o.encoder_settings.decode_dict_vals = True - o.encoder_settings.decode_dict_vals_postprocess = False - expected = {_test_str_e: _test_str_d} - assert_equal(o.decode({_test_str_e: _test_str_e}), expected) - # dicts: only keys, no postprocessing - o.encoder_settings.decode_dict_keys = True - o.encoder_settings.decode_dict_vals = False - expected = {_test_str_d: _test_str_e} - assert_equal(o.decode({_test_str_e: _test_str_e}), expected) - # dicts: both keys and values, no postprocessing - o.encoder_settings.decode_dict_vals = True - expected = {_test_str_d: _test_str_d} - assert_equal(o.decode({_test_str_e: _test_str_e}), expected) - # dicts: both keys and values, postprocessing on keys only - o.encoder_settings.decode_dict_keys = True - o.encoder_settings.decode_dict_keys_postprocess = True - o.encoder_settings.decode_postprocessor = string.upper - expected = {_test_str_d.upper(): _test_str_d} - assert_equal(o.decode({_test_str_e: _test_str_e}), expected) - # TODO: dict decoding using a table - # None - o.encoder_settings.decode_postprocessor = lambda x: x - o.encoder_settings.decode_none = False - assert_equal(o.decode(None), None) - o.encoder_settings.decode_none = True - assert_equal(o.decode(None), str(None).decode(decode_from)) - diff --git a/tests/test_ipalib/test_x509.py b/tests/test_ipalib/test_x509.py index a2e9b226..cf076313 100644 --- a/tests/test_ipalib/test_x509.py +++ b/tests/test_ipalib/test_x509.py @@ -32,7 +32,7 @@ from ipalib.constants import NAME_REGEX, NAME_ERROR import base64 from ipalib import x509 from nss.error import NSPRError -from ipalib.dn import * +from ipapython.dn import DN # certutil - diff --git a/tests/test_ipapython/test_dn.py b/tests/test_ipapython/test_dn.py new file mode 100644 index 00000000..441affa4 --- /dev/null +++ b/tests/test_ipapython/test_dn.py @@ -0,0 +1,1937 @@ +#!/usr/bin/python + +import unittest +from ipapython.dn import * + +def default_rdn_attr_arg(i): + return 'a%d' % i + +def default_rdn_value_arg(i): + return str(i) + +def alt_rdn_attr_arg(i): + return 'b%d' % i + +def alt_rdn_value_arg(i): + return str(i*10) + +def make_rdn_args(low, high, kind, attr=None, value=None): + result=[] + for i in range(low, high): + if attr is None: + new_attr = default_rdn_attr_arg(i) + elif callable(attr): + new_attr = attr(i) + else: + new_attr = attr + + if value is None: + new_value = default_rdn_value_arg(i) + elif callable(value): + new_value = value(i) + else: + new_value = value + + if kind == 'tuple': + result.append((new_attr, new_value)) + elif kind == 'list': + result.append([new_attr, new_value]) + elif kind == 'RDN': + result.append(RDN((new_attr, new_value))) + else: + raise ValueError("Unknown kind = %s" % kind) + + return result + +def expected_class(klass, component): + if klass is AVA: + if component == 'self': + return AVA + + elif klass is EditableAVA: + if component == 'self': + return EditableAVA + + elif klass is RDN: + if component == 'self': + return RDN + elif component == 'AVA': + return AVA + + elif klass is EditableRDN: + if component == 'self': + return EditableRDN + elif component == 'AVA': + return EditableAVA + + elif klass is DN: + if component == 'self': + return DN + elif component == 'AVA': + return AVA + elif component == 'RDN': + return RDN + + elif klass is EditableDN: + if component == 'self': + return EditableDN + elif component == 'AVA': + return EditableAVA + elif component == 'RDN': + return EditableRDN + + raise ValueError("class %s with component '%s' unknown" % (klass.__name__, component)) + + +class TestAVA(unittest.TestCase): + def setUp(self): + self.attr1 = 'cn' + self.value1 = 'Bob' + self.str_ava1 = '%s=%s' % (self.attr1, self.value1) + self.ava1 = AVA(self.attr1, self.value1) + + self.attr2 = 'ou' + self.value2 = 'People' + self.str_ava2 = '%s=%s' % (self.attr2, self.value2) + self.ava2 = AVA(self.attr2, self.value2) + + self.attr3 = 'c' + self.value3 = 'US' + self.str_ava3 = '%s=%s' % (self.attr3, self.value3) + self.ava3 = AVA(self.attr3, self.value3) + + def assertExpectedClass(self, klass, obj, component): + self.assertIs(obj.__class__, expected_class(klass, component)) + + def test_create(self): + for AVA_class in (AVA, EditableAVA): + # Create with attr,value pair + ava1 = AVA_class(self.attr1, self.value1) + self.assertExpectedClass(AVA_class, ava1, 'self') + self.assertEqual(ava1, self.ava1) + + # Create with "attr=value" string + ava1 = AVA_class(self.str_ava1) + self.assertExpectedClass(AVA_class, ava1, 'self') + self.assertEqual(ava1, self.ava1) + + # Create with tuple (attr, value) + ava1 = AVA_class((self.attr1, self.value1)) + self.assertExpectedClass(AVA_class, ava1, 'self') + self.assertEqual(ava1, self.ava1) + + # Create with list [attr, value] + ava1 = AVA_class([self.attr1, self.value1]) + self.assertExpectedClass(AVA_class, ava1, 'self') + self.assertEqual(ava1, self.ava1) + + # Create with no args should fail + with self.assertRaises(TypeError): + AVA_class() + + # Create with more than 2 args should fail + with self.assertRaises(TypeError): + AVA_class(self.attr1, self.value1, self.attr1) + + # Create with 1 arg which is not string should fail + with self.assertRaises(TypeError): + AVA_class(1) + + # Create with malformed AVA_class string should fail + with self.assertRaises(ValueError): + AVA_class("cn") + + # Create with non-string parameters, should convert + ava1 = AVA_class(1, self.value1) + self.assertExpectedClass(AVA_class, ava1, 'self') + self.assertEqual(ava1.attr, u'1') + + ava1 = AVA_class((1, self.value1)) + self.assertExpectedClass(AVA_class, ava1, 'self') + self.assertEqual(ava1.attr, u'1') + + ava1 = AVA_class(self.attr1, 1) + self.assertExpectedClass(AVA_class, ava1, 'self') + self.assertEqual(ava1.value, u'1') + + ava1 = AVA_class((self.attr1, 1)) + self.assertExpectedClass(AVA_class, ava1, 'self') + self.assertEqual(ava1.value, u'1') + + def test_indexing(self): + for AVA_class in (AVA, EditableAVA): + ava1 = AVA_class(self.ava1) + + self.assertEqual(ava1[self.attr1], self.value1) + + with self.assertRaises(KeyError): + ava1['foo'] + + with self.assertRaises(TypeError): + ava1[0] + + def test_properties(self): + for AVA_class in (AVA, EditableAVA): + ava1 = AVA_class(self.ava1) + + self.assertEqual(ava1.attr, self.attr1) + self.assertIsInstance(ava1.attr, unicode) + + self.assertEqual(ava1.value, self.value1) + self.assertIsInstance(ava1.value, unicode) + + def test_str(self): + for AVA_class in (AVA, EditableAVA): + ava1 = AVA_class(self.ava1) + + self.assertEqual(str(ava1), self.str_ava1) + self.assertIsInstance(str(ava1), str) + + def test_cmp(self): + for AVA_class in (AVA, EditableAVA): + # Equality + ava1 = AVA_class(self.attr1, self.value1) + + self.assertTrue(ava1 == self.ava1) + self.assertFalse(ava1 != self.ava1) + + self.assertTrue(ava1 == self.str_ava1) + self.assertFalse(ava1 != self.str_ava1) + + result = cmp(ava1, self.ava1) + self.assertEqual(result, 0) + + # Upper case attr should still be equal + ava1 = AVA_class(self.attr1.upper(), self.value1) + + self.assertFalse(ava1.attr == self.attr1) + self.assertTrue(ava1.value == self.value1) + self.assertTrue(ava1 == self.ava1) + self.assertFalse(ava1 != self.ava1) + + result = cmp(ava1, self.ava1) + self.assertEqual(result, 0) + + # Upper case value should still be equal + ava1 = AVA_class(self.attr1, self.value1.upper()) + + self.assertTrue(ava1.attr == self.attr1) + self.assertFalse(ava1.value == self.value1) + self.assertTrue(ava1 == self.ava1) + self.assertFalse(ava1 != self.ava1) + + result = cmp(ava1, self.ava1) + self.assertEqual(result, 0) + + # Make ava1's attr greater + if AVA_class.is_mutable: + ava1.attr = self.attr1 + "1" + else: + with self.assertRaises(AttributeError): + ava1.attr = self.attr1 + "1" + ava1 = AVA_class(self.attr1 + "1", self.value1.upper()) + + self.assertFalse(ava1 == self.ava1) + self.assertTrue(ava1 != self.ava1) + + result = cmp(ava1, self.ava1) + self.assertEqual(result, 1) + + result = cmp(self.ava1, ava1) + self.assertEqual(result, -1) + + # Reset ava1's attr, should be equal again + if AVA_class.is_mutable: + ava1.attr = self.attr1 + else: + with self.assertRaises(AttributeError): + ava1.attr = self.attr1 + ava1 = AVA_class(self.attr1, self.value1.upper()) + + result = cmp(ava1, self.ava1) + self.assertEqual(result, 0) + + # Make ava1's value greater + # attr will be equal, this tests secondary comparision component + if AVA_class.is_mutable: + ava1.value = self.value1 + "1" + else: + with self.assertRaises(AttributeError): + ava1.value = self.value1 + "1" + ava1 = AVA_class(self.attr1, self.value1 + "1") + + result = cmp(ava1, self.ava1) + self.assertEqual(result, 1) + + result = cmp(self.ava1, ava1) + self.assertEqual(result, -1) + + def test_hashing(self): + # create AVA's that have the same value + immutable_ava1 = AVA((self.attr1, self.value1)) + immutable_ava2 = AVA((self.attr1, self.value1)) + + mutable_ava1 = EditableAVA((self.attr1, self.value1)) + mutable_ava2 = EditableAVA((self.attr1, self.value1)) + + # Immutable AVA's that are equal should hash to the same value. + # Mutable AVA's should not be hashable. + + self.assertEqual(immutable_ava1, immutable_ava2) + self.assertEqual(immutable_ava1, mutable_ava1) + self.assertEqual(immutable_ava1, mutable_ava2) + self.assertEqual(mutable_ava1, immutable_ava2) + + # Good, everyone's equal, now verify their hash values + + self.assertEqual(hash(immutable_ava1), hash(immutable_ava2)) + with self.assertRaises(TypeError): + hash(mutable_ava1) + with self.assertRaises(TypeError): + hash(mutable_ava2) + + # Different immutable AVA objects with the same value should + # map to 1 common key and 1 member in a set. The key and + # member are based on the object's value. + # + # Mutable AVA objects should be unhashable. + + for AVA_class in (AVA, EditableAVA): + ava1_a = AVA_class(self.ava1) + ava1_b = AVA_class(self.ava1) + + ava2_a = AVA_class(self.ava2) + ava2_b = AVA_class(self.ava2) + + ava3_a = AVA_class(self.ava3) + ava3_b = AVA_class(self.ava3) + + self.assertEqual(ava1_a, ava1_b) + self.assertEqual(ava2_a, ava2_b) + self.assertEqual(ava3_a, ava3_b) + + d = dict() + s = set() + + if AVA_class.is_mutable: + with self.assertRaises(TypeError): + d[ava1_a] = str(ava1_a) + with self.assertRaises(TypeError): + d[ava1_b] = str(ava1_b) + with self.assertRaises(TypeError): + d[ava2_a] = str(ava2_a) + with self.assertRaises(TypeError): + d[ava2_b] = str(ava2_b) + + with self.assertRaises(TypeError): + s.add(ava1_a) + with self.assertRaises(TypeError): + s.add(ava1_b) + with self.assertRaises(TypeError): + s.add(ava2_a) + with self.assertRaises(TypeError): + s.add(ava2_b) + else: + d[ava1_a] = str(ava1_a) + d[ava1_b] = str(ava1_b) + d[ava2_a] = str(ava2_a) + d[ava2_b] = str(ava2_b) + + s.add(ava1_a) + s.add(ava1_b) + s.add(ava2_a) + s.add(ava2_b) + + self.assertEqual(len(d), 2) + self.assertEqual(len(s), 2) + self.assertEqual(sorted(d.keys()), sorted([ava1_a, ava2_a])) + self.assertEqual(sorted(s), sorted([ava1_a, ava2_a])) + + self.assertTrue(ava1_a in d) + self.assertTrue(ava1_b in d) + self.assertTrue(ava2_a in d) + self.assertTrue(ava2_b in d) + self.assertFalse(ava3_a in d) + self.assertFalse(ava3_b in d) + + self.assertTrue(d.has_key(ava1_a)) + self.assertTrue(d.has_key(ava1_b)) + self.assertTrue(d.has_key(ava2_a)) + self.assertTrue(d.has_key(ava2_b)) + self.assertFalse(d.has_key(ava3_a)) + self.assertFalse(d.has_key(ava3_b)) + + self.assertTrue(ava1_a in s) + self.assertTrue(ava1_b in s) + self.assertTrue(ava2_a in s) + self.assertTrue(ava2_b in s) + self.assertFalse(ava3_a in s) + self.assertFalse(ava3_b in s) + + def test_coerce(self): + # Coerce an immutable to a mutable + immutable_ava1 = AVA(self.ava1) + mutable_ava1 = EditableAVA(immutable_ava1) + self.assertEqual(mutable_ava1, self.ava1) + self.assertEqual(mutable_ava1, immutable_ava1) + + # Coerce a mutable to an immutable + mutable_ava1 = EditableAVA(self.ava1) + immutable_ava1 = AVA(mutable_ava1) + self.assertEqual(immutable_ava1, self.ava1) + self.assertEqual(immutable_ava1, mutable_ava1) + +class TestRDN(unittest.TestCase): + def setUp(self): + # ava1 must sort before ava2 + self.attr1 = 'cn' + self.value1 = 'Bob' + self.str_ava1 = '%s=%s' % (self.attr1, self.value1) + self.ava1 = AVA(self.attr1, self.value1) + + self.str_rdn1 = '%s=%s' % (self.attr1, self.value1) + self.rdn1 = RDN((self.attr1, self.value1)) + + self.attr2 = 'ou' + self.value2 = 'people' + self.str_ava2 = '%s=%s' % (self.attr2, self.value2) + self.ava2 = AVA(self.attr2, self.value2) + + self.str_rdn2 = '%s=%s' % (self.attr2, self.value2) + self.rdn2 = RDN((self.attr2, self.value2)) + + self.str_ava3 = '%s=%s+%s=%s' % (self.attr1, self.value1, self.attr2, self.value2) + + self.str_rdn3 = '%s=%s+%s=%s' % (self.attr1, self.value1, self.attr2, self.value2) + self.rdn3 = RDN(self.ava1, self.ava2) + + def assertExpectedClass(self, klass, obj, component): + self.assertIs(obj.__class__, expected_class(klass, component)) + + def test_create(self): + for RDN_class in (RDN, EditableRDN): + # Create with single attr,value pair + rdn1 = RDN_class((self.attr1, self.value1)) + + + self.assertEqual(len(rdn1), 1) + self.assertEqual(rdn1, self.rdn1) + self.assertExpectedClass(RDN_class, rdn1, 'self') + for i in range(0, len(rdn1)): + self.assertExpectedClass(RDN_class, rdn1[i], 'AVA') + self.assertEqual(rdn1[0], self.ava1) + + # Create with multiple attr,value pairs + rdn3 = RDN_class((self.attr1, self.value1), (self.attr2, self.value2)) + self.assertEqual(len(rdn3), 2) + self.assertEqual(rdn3, self.rdn3) + self.assertExpectedClass(RDN_class, rdn3, 'self') + for i in range(0, len(rdn3)): + self.assertExpectedClass(RDN_class, rdn3[i], 'AVA') + self.assertEqual(rdn3[0], self.ava1) + self.assertEqual(rdn3[1], self.ava2) + + # Create with multiple attr,value pairs passed as lists + rdn3 = RDN_class([self.attr1, self.value1], [self.attr2, self.value2]) + self.assertEqual(len(rdn3), 2) + self.assertEqual(rdn3, self.rdn3) + self.assertExpectedClass(RDN_class, rdn3, 'self') + for i in range(0, len(rdn3)): + self.assertExpectedClass(RDN_class, rdn3[i], 'AVA') + self.assertEqual(rdn3[0], self.ava1) + self.assertEqual(rdn3[1], self.ava2) + + # Create with multiple attr,value pairs but reverse + # constructor parameter ordering. RDN canonical ordering + # should remain the same + rdn3 = RDN_class((self.attr2, self.value2), (self.attr1, self.value1)) + self.assertEqual(len(rdn3), 2) + self.assertEqual(rdn3, self.rdn3) + self.assertExpectedClass(RDN_class, rdn3, 'self') + for i in range(0, len(rdn3)): + self.assertExpectedClass(RDN_class, rdn3[i], 'AVA') + self.assertEqual(rdn3[0], self.ava1) + self.assertEqual(rdn3[1], self.ava2) + + # Create with single AVA object + rdn1 = RDN_class(self.ava1) + self.assertEqual(len(rdn1), 1) + self.assertEqual(rdn1, self.rdn1) + self.assertExpectedClass(RDN_class, rdn1, 'self') + for i in range(0, len(rdn1)): + self.assertExpectedClass(RDN_class, rdn1[i], 'AVA') + self.assertEqual(rdn1[0], self.ava1) + + # Create with multiple AVA objects + rdn3 = RDN_class(self.ava1, self.ava2) + self.assertEqual(len(rdn3), 2) + self.assertEqual(rdn3, self.rdn3) + self.assertExpectedClass(RDN_class, rdn3, 'self') + for i in range(0, len(rdn3)): + self.assertExpectedClass(RDN_class, rdn3[i], 'AVA') + self.assertEqual(rdn3[0], self.ava1) + self.assertEqual(rdn3[1], self.ava2) + + + # Create with multiple AVA objects but reverse constructor + # parameter ordering. RDN canonical ordering should remain + # the same + rdn3 = RDN_class(self.ava2, self.ava1) + self.assertEqual(len(rdn3), 2) + self.assertEqual(rdn3, self.rdn3) + self.assertExpectedClass(RDN_class, rdn3, 'self') + for i in range(0, len(rdn3)): + self.assertExpectedClass(RDN_class, rdn3[i], 'AVA') + self.assertEqual(rdn3[0], self.ava1) + self.assertEqual(rdn3[1], self.ava2) + + # Create with single string with 1 AVA + rdn1 = RDN_class(self.str_rdn1) + self.assertEqual(len(rdn1), 1) + self.assertEqual(rdn1, self.rdn1) + self.assertExpectedClass(RDN_class, rdn1, 'self') + for i in range(0, len(rdn1)): + self.assertExpectedClass(RDN_class, rdn1[i], 'AVA') + self.assertEqual(rdn1[0], self.ava1) + + # Create with single string with 2 AVA's + rdn3 = RDN_class(self.str_rdn3) + self.assertEqual(len(rdn3), 2) + self.assertEqual(rdn3, self.rdn3) + self.assertExpectedClass(RDN_class, rdn3, 'self') + for i in range(0, len(rdn3)): + self.assertExpectedClass(RDN_class, rdn3[i], 'AVA') + self.assertEqual(rdn3[0], self.ava1) + self.assertEqual(rdn3[1], self.ava2) + + def test_properties(self): + for RDN_class in (RDN, EditableRDN): + rdn1 = RDN_class(self.rdn1) + rdn2 = RDN_class(self.rdn2) + rdn3 = RDN_class(self.rdn3) + + self.assertEqual(rdn1.attr, self.attr1) + self.assertIsInstance(rdn1.attr, unicode) + + self.assertEqual(rdn1.value, self.value1) + self.assertIsInstance(rdn1.value, unicode) + + self.assertEqual(rdn2.attr, self.attr2) + self.assertIsInstance(rdn2.attr, unicode) + + self.assertEqual(rdn2.value, self.value2) + self.assertIsInstance(rdn2.value, unicode) + + self.assertEqual(rdn3.attr, self.attr1) + self.assertIsInstance(rdn3.attr, unicode) + + self.assertEqual(rdn3.value, self.value1) + self.assertIsInstance(rdn3.value, unicode) + + def test_str(self): + for RDN_class in (RDN, EditableRDN): + rdn1 = RDN_class(self.rdn1) + rdn2 = RDN_class(self.rdn2) + rdn3 = RDN_class(self.rdn3) + + self.assertEqual(str(rdn1), self.str_rdn1) + self.assertIsInstance(str(rdn1), str) + + self.assertEqual(str(rdn2), self.str_rdn2) + self.assertIsInstance(str(rdn2), str) + + self.assertEqual(str(rdn3), self.str_rdn3) + self.assertIsInstance(str(rdn3), str) + + def test_cmp(self): + for RDN_class in (RDN, EditableRDN): + # Equality + rdn1 = RDN_class((self.attr1, self.value1)) + + self.assertTrue(rdn1 == self.rdn1) + self.assertFalse(rdn1 != self.rdn1) + + self.assertTrue(rdn1 == self.str_rdn1) + self.assertFalse(rdn1 != self.str_rdn1) + + result = cmp(rdn1, self.rdn1) + self.assertEqual(result, 0) + + # Make rdn1's attr greater + if RDN_class.is_mutable: + rdn1.attr = self.attr1 + "1" + else: + rdn1 = RDN_class((self.attr1 + "1", self.value1)) + + self.assertFalse(rdn1 == self.rdn1) + self.assertTrue(rdn1 != self.rdn1) + + result = cmp(rdn1, self.rdn1) + self.assertEqual(result, 1) + + result = cmp(self.rdn1, rdn1) + self.assertEqual(result, -1) + + # Reset rdn1's attr, should be equal again + if RDN_class.is_mutable: + rdn1.attr = self.attr1 + else: + rdn1 = RDN_class((self.attr1, self.value1)) + + result = cmp(rdn1, self.rdn1) + self.assertEqual(result, 0) + + # Make rdn1's value greater + # attr will be equal, this tests secondary comparision component + if RDN_class.is_mutable: + rdn1.value = self.value1 + "1" + else: + rdn1 = RDN_class((self.attr1, self.value1 + "1")) + + result = cmp(rdn1, self.rdn1) + self.assertEqual(result, 1) + + result = cmp(self.rdn1, rdn1) + self.assertEqual(result, -1) + + # Make sure rdn's with more ava's are greater + result = cmp(self.rdn1, self.rdn3) + self.assertEqual(result, -1) + result = cmp(self.rdn3, self.rdn1) + self.assertEqual(result, 1) + + def test_indexing(self): + for RDN_class in (RDN, EditableRDN): + rdn1 = RDN_class(self.rdn1) + rdn2 = RDN_class(self.rdn2) + rdn3 = RDN_class(self.rdn3) + + self.assertEqual(rdn1[0], self.ava1) + self.assertEqual(rdn1[self.ava1.attr], self.ava1.value) + with self.assertRaises(KeyError): + rdn1['foo'] + + self.assertEqual(rdn2[0], self.ava2) + self.assertEqual(rdn2[self.ava2.attr], self.ava2.value) + with self.assertRaises(KeyError): + rdn2['foo'] + + self.assertEqual(rdn3[0], self.ava1) + self.assertEqual(rdn3[self.ava1.attr], self.ava1.value) + self.assertEqual(rdn3[1], self.ava2) + self.assertEqual(rdn3[self.ava2.attr], self.ava2.value) + with self.assertRaises(KeyError): + rdn3['foo'] + + self.assertEqual(rdn1.attr, self.attr1) + self.assertEqual(rdn1.value, self.value1) + + with self.assertRaises(TypeError): + rdn3[1.0] + + # Slices + self.assertEqual(rdn3[0:1], [self.ava1]) + self.assertEqual(rdn3[:], [self.ava1, self.ava2]) + + def test_assignments(self): + for RDN_class in (RDN, EditableRDN): + rdn = RDN_class((self.attr1, self.value1)) + if RDN_class.is_mutable: + rdn[0] = self.ava2 + self.assertEqual(rdn, self.rdn2) + else: + with self.assertRaises(TypeError): + rdn[0] = self.ava2 + self.assertExpectedClass(RDN_class, rdn, 'self') + for i in range(0, len(rdn)): + self.assertExpectedClass(RDN_class, rdn[i], 'AVA') + + rdn = RDN_class((self.attr1, self.value1)) + if RDN_class.is_mutable: + rdn[0] = (self.attr2, self.value2) + self.assertEqual(rdn, self.rdn2) + else: + with self.assertRaises(TypeError): + rdn[0] = (self.attr2, self.value2) + self.assertExpectedClass(RDN_class, rdn, 'self') + for i in range(0, len(rdn)): + self.assertExpectedClass(RDN_class, rdn[i], 'AVA') + + rdn = RDN_class((self.attr1, self.value1)) + if RDN_class.is_mutable: + rdn[self.attr1] = self.str_ava2 + self.assertEqual(rdn[0], self.ava2) + else: + with self.assertRaises(TypeError): + rdn[self.attr1] = self.str_ava2 + self.assertExpectedClass(RDN_class, rdn, 'self') + for i in range(0, len(rdn)): + self.assertExpectedClass(RDN_class, rdn[i], 'AVA') + + # Can't assign multiples to single entry + rdn = RDN_class((self.attr1, self.value1)) + with self.assertRaises(TypeError): + rdn[self.attr1] = self.str_ava3 + self.assertExpectedClass(RDN_class, rdn, 'self') + for i in range(0, len(rdn)): + self.assertExpectedClass(RDN_class, rdn[i], 'AVA') + + rdn = RDN_class((self.attr1, self.value1)) + with self.assertRaises(TypeError): + rdn[self.attr1] = (self.attr1, self.value1, self.attr2, self.value2) + self.assertExpectedClass(RDN_class, rdn, 'self') + for i in range(0, len(rdn)): + self.assertExpectedClass(RDN_class, rdn[i], 'AVA') + + rdn = RDN_class((self.attr1, self.value1)) + with self.assertRaises(TypeError): + rdn[self.attr1] = [(self.attr1, self.value1), (self.attr2, self.value2)] + self.assertExpectedClass(RDN_class, rdn, 'self') + for i in range(0, len(rdn)): + self.assertExpectedClass(RDN_class, rdn[i], 'AVA') + + # Slices + rdn = RDN_class((self.attr1, self.value1)) + self.assertEqual(rdn, self.rdn1) + if RDN_class.is_mutable: + rdn[0:1] = [self.ava2] + self.assertEqual(rdn, self.rdn2) + else: + with self.assertRaises(TypeError): + rdn[0:1] = [self.ava2] + self.assertExpectedClass(RDN_class, rdn, 'self') + for i in range(0, len(rdn)): + self.assertExpectedClass(RDN_class, rdn[i], 'AVA') + + rdn = RDN_class((self.attr1, self.value1)) + self.assertEqual(rdn, self.rdn1) + if RDN_class.is_mutable: + rdn[:] = [(self.attr2, self.value2)] + self.assertEqual(rdn, self.rdn2) + else: + with self.assertRaises(TypeError): + rdn[:] = [(self.attr2, self.value2)] + self.assertExpectedClass(RDN_class, rdn, 'self') + for i in range(0, len(rdn)): + self.assertExpectedClass(RDN_class, rdn[i], 'AVA') + + rdn = RDN_class((self.attr1, self.value1)) + self.assertEqual(rdn, self.rdn1) + if RDN_class.is_mutable: + rdn[:] = [(self.attr1, self.value1),(self.attr2, self.value2)] + self.assertEqual(rdn, self.rdn3) + else: + with self.assertRaises(TypeError): + rdn[:] = [(self.attr1, self.value1),(self.attr2, self.value2)] + self.assertExpectedClass(RDN_class, rdn, 'self') + for i in range(0, len(rdn)): + self.assertExpectedClass(RDN_class, rdn[i], 'AVA') + + rdn = RDN_class((self.attr1, self.value1)) + self.assertEqual(rdn, self.rdn1) + if RDN_class.is_mutable: + rdn[0:1] = [(self.attr1, self.value1), (self.attr2, self.value2)] + self.assertEqual(rdn, self.rdn3) + else: + with self.assertRaises(TypeError): + rdn[0:1] = [(self.attr1, self.value1), (self.attr2, self.value2)] + self.assertExpectedClass(RDN_class, rdn, 'self') + for i in range(0, len(rdn)): + self.assertExpectedClass(RDN_class, rdn[i], 'AVA') + + + def test_iter(self): + for RDN_class in (RDN, EditableRDN): + rdn1 = RDN_class(self.rdn1) + rdn2 = RDN_class(self.rdn2) + rdn3 = RDN_class(self.rdn3) + + self.assertEqual(len(rdn1), 1) + self.assertEqual(rdn1[:], [self.ava1]) + for i, ava in enumerate(rdn1): + if i == 0: + self.assertEqual(ava, self.ava1) + else: + self.fail("got iteration index %d, but len=%d" % (i, len(rdn1))) + + self.assertEqual(len(rdn2), 1) + self.assertEqual(rdn2[:], [self.ava2]) + for i, ava in enumerate(rdn2): + if i == 0: + self.assertEqual(ava, self.ava2) + else: + self.fail("got iteration index %d, but len=%d" % (i, len(rdn2))) + + self.assertEqual(len(rdn3), 2) + self.assertEqual(rdn3[:], [self.ava1, self.ava2]) + for i, ava in enumerate(rdn3): + if i == 0: + self.assertEqual(ava, self.ava1) + elif i == 1: + self.assertEqual(ava, self.ava2) + else: + self.fail("got iteration index %d, but len=%d" % (i, len(rdn3))) + + + def test_concat(self): + for RDN_class in (RDN, EditableRDN): + rdn1 = RDN_class((self.attr1, self.value1)) + rdn2 = RDN_class((self.attr2, self.value2)) + + # in-place addtion + + # Note: If __iadd__ is not available Python will emulate += by + # replacing the lhs object with the result of __add__ (if available). + # Thus += works for both immutable and mutable RDN,DN object, the only + # difference is an immutable without __iadd__ will have a different object + # on the lhs after the operator evaluates. + + rdn1 += rdn2 + self.assertEqual(rdn1, self.rdn3) + self.assertExpectedClass(RDN_class, rdn1, 'self') + for i in range(0, len(rdn1)): + self.assertExpectedClass(RDN_class, rdn1[i], 'AVA') + + rdn1 = RDN_class((self.attr1, self.value1)) + rdn1 += self.ava2 + self.assertEqual(rdn1, self.rdn3) + self.assertExpectedClass(RDN_class, rdn1, 'self') + for i in range(0, len(rdn1)): + self.assertExpectedClass(RDN_class, rdn1[i], 'AVA') + + rdn1 = RDN_class((self.attr1, self.value1)) + rdn1 += self.str_ava2 + self.assertEqual(rdn1, self.rdn3) + self.assertExpectedClass(RDN_class, rdn1, 'self') + for i in range(0, len(rdn1)): + self.assertExpectedClass(RDN_class, rdn1[i], 'AVA') + + # concatenation + rdn1 = RDN_class((self.attr1, self.value1)) + rdn3 = rdn1 + rdn2 + self.assertEqual(rdn3, self.rdn3) + self.assertExpectedClass(RDN_class, rdn3, 'self') + for i in range(0, len(rdn3)): + self.assertExpectedClass(RDN_class, rdn3[i], 'AVA') + + rdn3 = rdn1 + self.ava2 + self.assertEqual(rdn3, self.rdn3) + self.assertExpectedClass(RDN_class, rdn3, 'self') + for i in range(0, len(rdn3)): + self.assertExpectedClass(RDN_class, rdn3[i], 'AVA') + + rdn3 = rdn1 + self.str_ava2 + self.assertEqual(rdn3, self.rdn3) + self.assertExpectedClass(RDN_class, rdn3, 'self') + for i in range(0, len(rdn3)): + self.assertExpectedClass(RDN_class, rdn3[i], 'AVA') + + + def test_hashing(self): + # create RDN's that have the same value + immutable_rdn1 = RDN((self.attr1, self.value1)) + immutable_rdn2 = RDN((self.attr1, self.value1)) + + mutable_rdn1 = EditableRDN((self.attr1, self.value1)) + mutable_rdn2 = EditableRDN((self.attr1, self.value1)) + + # Immutable RDN's that are equal should hash to the same value. + # Mutable RDN's should not be hashable. + + self.assertEqual(immutable_rdn1, immutable_rdn2) + self.assertEqual(immutable_rdn1, mutable_rdn1) + self.assertEqual(immutable_rdn1, mutable_rdn2) + self.assertEqual(mutable_rdn1, immutable_rdn2) + + # Good, everyone's equal, now verify their hash values + + self.assertEqual(hash(immutable_rdn1), hash(immutable_rdn2)) + with self.assertRaises(TypeError): + hash(mutable_rdn1) + with self.assertRaises(TypeError): + hash(mutable_rdn2) + + def test_coerce(self): + # Coerce an immutable to a mutable + immutable_rdn3 = RDN(self.rdn3) + mutable_rdn3 = EditableRDN(immutable_rdn3) + self.assertEqual(mutable_rdn3, self.rdn3) + self.assertEqual(mutable_rdn3, immutable_rdn3) + + # Coerce a mutable to an immutable + mutable_rdn3 = EditableRDN(self.rdn3) + immutable_rdn3 = RDN(mutable_rdn3) + self.assertEqual(immutable_rdn3, self.rdn3) + self.assertEqual(immutable_rdn3, mutable_rdn3) + +class TestDN(unittest.TestCase): + def setUp(self): + # ava1 must sort before ava2 + self.attr1 = 'cn' + self.value1 = 'Bob' + self.str_ava1 = '%s=%s' % (self.attr1, self.value1) + self.ava1 = AVA(self.attr1, self.value1) + + self.str_rdn1 = '%s=%s' % (self.attr1, self.value1) + self.rdn1 = RDN((self.attr1, self.value1)) + + self.attr2 = 'ou' + self.value2 = 'people' + self.str_ava2 = '%s=%s' % (self.attr2, self.value2) + self.ava2 = AVA(self.attr2, self.value2) + + self.str_rdn2 = '%s=%s' % (self.attr2, self.value2) + self.rdn2 = RDN((self.attr2, self.value2)) + + self.str_dn1 = self.str_rdn1 + self.dn1 = DN(self.rdn1) + + self.str_dn2 = self.str_rdn2 + self.dn2 = DN(self.rdn2) + + self.str_dn3 = '%s,%s' % (self.str_rdn1, self.str_rdn2) + self.dn3 = DN(self.rdn1, self.rdn2) + + self.base_rdn1 = RDN(('dc', 'redhat')) + self.base_rdn2 = RDN(('dc', 'com')) + self.base_dn = DN(self.base_rdn1, self.base_rdn2) + + self.container_rdn1 = RDN(('cn', 'sudorules')) + self.container_rdn2 = RDN(('cn', 'sudo')) + self.container_dn = DN(self.container_rdn1, self.container_rdn2) + + self.base_container_dn = DN((self.attr1, self.value1), + self.container_dn, self.base_dn) + + + def assertExpectedClass(self, klass, obj, component): + self.assertIs(obj.__class__, expected_class(klass, component)) + + def test_create(self): + for DN_class in (DN, EditableDN): + # Create with single attr,value pair + dn1 = DN_class((self.attr1, self.value1)) + self.assertEqual(len(dn1), 1) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + self.assertIsInstance(dn1[0].attr, unicode) + self.assertIsInstance(dn1[0].value, unicode) + self.assertEqual(dn1[0], self.rdn1) + + # Create with single attr,value pair passed as a tuple + dn1 = DN_class((self.attr1, self.value1)) + self.assertEqual(len(dn1), 1) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + self.assertIsInstance(dn1[i].attr, unicode) + self.assertIsInstance(dn1[i].value, unicode) + self.assertEqual(dn1[0], self.rdn1) + + # Creation with multiple attr,value string pairs should fail + with self.assertRaises(ValueError): + dn1 = DN_class(self.attr1, self.value1, self.attr2, self.value2) + + # Create with multiple attr,value pairs passed as tuples & lists + dn1 = DN_class((self.attr1, self.value1), [self.attr2, self.value2]) + self.assertEqual(len(dn1), 2) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + self.assertIsInstance(dn1[i].attr, unicode) + self.assertIsInstance(dn1[i].value, unicode) + self.assertEqual(dn1[0], self.rdn1) + self.assertEqual(dn1[1], self.rdn2) + + # Create with multiple attr,value pairs passed as tuple and RDN + dn1 = DN_class((self.attr1, self.value1), RDN((self.attr2, self.value2))) + self.assertEqual(len(dn1), 2) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + self.assertIsInstance(dn1[i].attr, unicode) + self.assertIsInstance(dn1[i].value, unicode) + self.assertEqual(dn1[0], self.rdn1) + self.assertEqual(dn1[1], self.rdn2) + + # Create with multiple attr,value pairs but reverse + # constructor parameter ordering. RDN ordering should also be + # reversed because DN's are a ordered sequence of RDN's + dn1 = DN_class((self.attr2, self.value2), (self.attr1, self.value1)) + self.assertEqual(len(dn1), 2) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + self.assertIsInstance(dn1[i].attr, unicode) + self.assertIsInstance(dn1[i].value, unicode) + self.assertEqual(dn1[0], self.rdn2) + self.assertEqual(dn1[1], self.rdn1) + + # Create with single RDN object + dn1 = DN_class(self.rdn1) + self.assertEqual(len(dn1), 1) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + self.assertIsInstance(dn1[i].attr, unicode) + self.assertIsInstance(dn1[i].value, unicode) + self.assertEqual(dn1[0], self.rdn1) + + # Create with multiple RDN objects, assure ordering is preserved. + dn1 = DN_class(self.rdn1, self.rdn2) + self.assertEqual(len(dn1), 2) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + self.assertIsInstance(dn1[i].attr, unicode) + self.assertIsInstance(dn1[i].value, unicode) + self.assertEqual(dn1[0], self.rdn1) + self.assertEqual(dn1[1], self.rdn2) + + # Create with multiple RDN objects in different order, assure + # ordering is preserved. + dn1 = DN_class(self.rdn2, self.rdn1) + self.assertEqual(len(dn1), 2) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + self.assertIsInstance(dn1[i].attr, unicode) + self.assertIsInstance(dn1[i].value, unicode) + self.assertEqual(dn1[0], self.rdn2) + self.assertEqual(dn1[1], self.rdn1) + + # Create with single string with 1 RDN + dn1 = DN_class(self.str_rdn1) + self.assertEqual(len(dn1), 1) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + self.assertIsInstance(dn1[i].attr, unicode) + self.assertIsInstance(dn1[i].value, unicode) + self.assertEqual(dn1[0], self.rdn1) + + # Create with single string with 2 RDN's + dn1 = DN_class(self.str_dn3) + self.assertEqual(len(dn1), 2) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + self.assertIsInstance(dn1[i].attr, unicode) + self.assertIsInstance(dn1[i].value, unicode) + self.assertEqual(dn1[0], self.rdn1) + self.assertEqual(dn1[1], self.rdn2) + + # Create with RDN, and 2 DN's (e.g. attr + container + base) + dn1 = DN_class((self.attr1, self.value1), self.container_dn, self.base_dn) + self.assertEqual(len(dn1), 5) + dn_str = ','.join([str(self.rdn1), + str(self.container_rdn1), str(self.container_rdn2), + str(self.base_rdn1), str(self.base_rdn2)]) + self.assertEqual(str(dn1), dn_str) + + def test_str(self): + for DN_class in (DN, EditableDN): + dn1 = DN_class(self.dn1) + dn2 = DN_class(self.dn2) + dn3 = DN_class(self.dn3) + + self.assertEqual(str(dn1), self.str_dn1) + self.assertIsInstance(str(dn1), str) + + self.assertEqual(str(dn2), self.str_dn2) + self.assertIsInstance(str(dn2), str) + + self.assertEqual(str(dn3), self.str_dn3) + self.assertIsInstance(str(dn3), str) + + def test_cmp(self): + for DN_class in (DN, EditableDN): + # Equality + dn1 = DN_class((self.attr1, self.value1)) + + self.assertTrue(dn1 == self.dn1) + self.assertFalse(dn1 != self.dn1) + + self.assertTrue(dn1 == self.str_dn1) + self.assertFalse(dn1 != self.str_dn1) + + result = cmp(dn1, self.dn1) + self.assertEqual(result, 0) + + # Make dn1's attr greater + if DN_class.is_mutable: + dn1[0].attr = self.attr1 + "1" + else: + with self.assertRaises(AttributeError): + dn1[0].attr = self.attr1 + "1" + dn1 = DN_class((self.attr1 + "1", self.value1)) + + self.assertFalse(dn1 == self.dn1) + self.assertTrue(dn1 != self.dn1) + + result = cmp(dn1, self.dn1) + self.assertEqual(result, 1) + + result = cmp(self.dn1, dn1) + self.assertEqual(result, -1) + + # Reset dn1's attr, should be equal again + if DN_class.is_mutable: + dn1[0].attr = self.attr1 + else: + with self.assertRaises(AttributeError): + dn1[0].attr = self.attr1 + dn1 = DN_class((self.attr1, self.value1)) + + result = cmp(dn1, self.dn1) + self.assertEqual(result, 0) + + # Make dn1's value greater + # attr will be equal, this tests secondary comparision component + if DN_class.is_mutable: + dn1[0].value = self.value1 + "1" + else: + with self.assertRaises(AttributeError): + dn1[0].value = self.value1 + "1" + dn1 = DN_class((self.attr1, self.value1 + "1")) + + result = cmp(dn1, self.dn1) + self.assertEqual(result, 1) + + result = cmp(self.dn1, dn1) + self.assertEqual(result, -1) + + # Make sure dn's with more rdn's are greater + result = cmp(self.dn1, self.dn3) + self.assertEqual(result, -1) + result = cmp(self.dn3, self.dn1) + self.assertEqual(result, 1) + + + # Test startswith, endswith + container_dn = DN_class(self.container_dn) + base_container_dn = DN_class(self.base_container_dn) + + self.assertTrue(base_container_dn.startswith(self.rdn1)) + self.assertTrue(base_container_dn.startswith(self.dn1)) + self.assertTrue(base_container_dn.startswith(self.dn1 + container_dn)) + self.assertFalse(base_container_dn.startswith(self.dn2)) + self.assertFalse(base_container_dn.startswith(self.rdn2)) + self.assertTrue(base_container_dn.startswith((self.dn1))) + self.assertTrue(base_container_dn.startswith((self.rdn1))) + self.assertFalse(base_container_dn.startswith((self.rdn2))) + self.assertTrue(base_container_dn.startswith((self.rdn2, self.rdn1))) + self.assertTrue(base_container_dn.startswith((self.dn1, self.dn2))) + + self.assertTrue(base_container_dn.endswith(self.base_dn)) + self.assertTrue(base_container_dn.endswith(container_dn + self.base_dn)) + self.assertFalse(base_container_dn.endswith(DN(self.base_rdn1))) + self.assertTrue(base_container_dn.endswith(DN(self.base_rdn2))) + self.assertTrue(base_container_dn.endswith((DN(self.base_rdn1), DN(self.base_rdn2)))) + + # Test "in" membership + self.assertTrue(self.container_rdn1 in container_dn) + self.assertTrue(container_dn in container_dn) + self.assertFalse(self.base_rdn1 in container_dn) + + self.assertTrue(self.container_rdn1 in base_container_dn) + self.assertTrue(container_dn in base_container_dn) + self.assertTrue(container_dn + self.base_dn in + base_container_dn) + self.assertTrue(self.dn1 + container_dn + self.base_dn in + base_container_dn) + self.assertTrue(self.dn1 + container_dn + self.base_dn == + base_container_dn) + + self.assertFalse(self.container_rdn1 in self.base_dn) + + def test_indexing(self): + for DN_class in (DN, EditableDN): + dn1 = DN_class(self.dn1) + dn2 = DN_class(self.dn2) + dn3 = DN_class(self.dn3) + + self.assertEqual(dn1[0], self.rdn1) + self.assertEqual(dn1[self.rdn1.attr], self.rdn1.value) + with self.assertRaises(KeyError): + dn1['foo'] + + self.assertEqual(dn2[0], self.rdn2) + self.assertEqual(dn2[self.rdn2.attr], self.rdn2.value) + with self.assertRaises(KeyError): + dn2['foo'] + + self.assertEqual(dn3[0], self.rdn1) + self.assertEqual(dn3[self.rdn1.attr], self.rdn1.value) + self.assertEqual(dn3[1], self.rdn2) + self.assertEqual(dn3[self.rdn2.attr], self.rdn2.value) + with self.assertRaises(KeyError): + dn3['foo'] + + with self.assertRaises(TypeError): + dn3[1.0] + + def test_assignments(self): + for DN_class in (DN, EditableDN): + dn_low = 0 + dn_high = 6 + + rdn_args = make_rdn_args(dn_low, dn_high, 'tuple', + default_rdn_attr_arg, default_rdn_value_arg) + dn1 = DN_class(*rdn_args) + + rdn_args = make_rdn_args(dn_low, dn_high, 'list', + default_rdn_attr_arg, default_rdn_value_arg) + dn2 = DN_class(*rdn_args) + + rdn_args = make_rdn_args(dn_low, dn_high, 'RDN', + default_rdn_attr_arg, default_rdn_value_arg) + dn3 = DN_class(*rdn_args) + + self.assertEqual(dn1, dn2) + self.assertEqual(dn1, dn3) + + for i in range(dn_low, dn_high): + attr = default_rdn_attr_arg(i) + value = default_rdn_value_arg(i) + + self.assertEqual(dn1[i].attr, attr) + self.assertEqual(dn1[i].value, value) + self.assertEqual(dn1[attr], value) + self.assertExpectedClass(DN_class, dn1, 'self') + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + + self.assertEqual(dn2[i].attr, attr) + self.assertEqual(dn2[i].value, value) + self.assertEqual(dn2[attr], value) + self.assertExpectedClass(DN_class, dn2, 'self') + self.assertExpectedClass(DN_class, dn2[i], 'RDN') + for j in range(0, len(dn2[i])): + self.assertExpectedClass(DN_class, dn2[i][j], 'AVA') + + self.assertEqual(dn3[i].attr, attr) + self.assertEqual(dn3[i].value, value) + self.assertEqual(dn3[attr], value) + self.assertExpectedClass(DN_class, dn3, 'self') + self.assertExpectedClass(DN_class, dn3[i], 'RDN') + for j in range(0, len(dn3[i])): + self.assertExpectedClass(DN_class, dn3[i][j], 'AVA') + + + for i in range(dn_low, dn_high): + if i % 2: + orig_attr = default_rdn_attr_arg(i) + attr = alt_rdn_attr_arg(i) + value = alt_rdn_value_arg(i) + + if DN_class.is_mutable: + dn1[i] = attr, value + else: + with self.assertRaises(TypeError): + dn1[i] = attr, value + + if DN_class.is_mutable: + dn2[orig_attr] = (attr, value) + else: + with self.assertRaises(TypeError): + dn2[orig_attr] = (attr, value) + + if DN_class.is_mutable: + dn3[i] = RDN((attr, value)) + else: + with self.assertRaises(TypeError): + dn3[i] = RDN((attr, value)) + + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + + self.assertExpectedClass(DN_class, dn2, 'self') + for i in range(0, len(dn2)): + self.assertExpectedClass(DN_class, dn2[i], 'RDN') + for j in range(0, len(dn2[i])): + self.assertExpectedClass(DN_class, dn2[i][j], 'AVA') + + self.assertExpectedClass(DN_class, dn3, 'self') + for i in range(0, len(dn3)): + self.assertExpectedClass(DN_class, dn3[i], 'RDN') + for j in range(0, len(dn3[i])): + self.assertExpectedClass(DN_class, dn3[i][j], 'AVA') + + + if DN_class.is_mutable: + self.assertEqual(dn1, dn2) + self.assertEqual(dn1, dn3) + + for i in range(dn_low, dn_high): + if i % 2: + attr = alt_rdn_attr_arg(i) + value = alt_rdn_value_arg(i) + else: + attr = default_rdn_attr_arg(i) + value = default_rdn_value_arg(i) + self.assertEqual(dn1[i].attr, attr) + self.assertEqual(dn1[i].value, value) + self.assertEqual(dn1[attr], value) + + # Slices + slice_low = 2 + slice_high = 4 + slice_interval = range(slice_low, slice_high) + + # Slices + # Assign via tuple + rdn_args = make_rdn_args(dn_low, dn_high, 'tuple', + default_rdn_attr_arg, default_rdn_value_arg) + dn = DN_class(*rdn_args) + + dn_slice = make_rdn_args(slice_low, slice_high, 'tuple', + alt_rdn_attr_arg, alt_rdn_value_arg) + + if DN_class.is_mutable: + dn[slice_low:slice_high] = dn_slice + for i in range(dn_low, dn_high): + if i in slice_interval: + attr = alt_rdn_attr_arg(i) + value = alt_rdn_value_arg(i) + else: + attr = default_rdn_attr_arg(i) + value = default_rdn_value_arg(i) + self.assertEqual(dn[i].attr, attr) + self.assertEqual(dn[i].value, value) + self.assertEqual(dn[attr], value) + + query_slice = dn[slice_low:slice_high] + for i, query_rdn in enumerate(query_slice): + slice_rdn = RDN(dn_slice[i]) + self.assertEqual(slice_rdn, query_rdn) + else: + with self.assertRaises(TypeError): + dn[slice_low:slice_high] = dn_slice + + + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + # insert + dn = DN_class(self.rdn2) + + if DN_class.is_mutable: + dn.insert(0, self.rdn1) + self.assertEqual(dn, self.dn3) + else: + with self.assertRaises(AttributeError): + dn.insert(0, self.rdn1) + + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + dn = DN_class(self.rdn1) + + if DN_class.is_mutable: + dn.insert(1, (self.attr2, self.value2)) + self.assertEqual(dn, self.dn3) + else: + with self.assertRaises(AttributeError): + dn.insert(1, (self.attr2, self.value2)) + + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + # Slices + # Assign via RDN + rdn_args = make_rdn_args(dn_low, dn_high, 'tuple', + default_rdn_attr_arg, default_rdn_value_arg) + dn = DN_class(*rdn_args) + + dn_slice = make_rdn_args(slice_low, slice_high, 'RDN', + alt_rdn_attr_arg, alt_rdn_value_arg) + + if DN_class.is_mutable: + dn[slice_low:slice_high] = dn_slice + for i in range(dn_low, dn_high): + if i in slice_interval: + attr = alt_rdn_attr_arg(i) + value = alt_rdn_value_arg(i) + else: + attr = default_rdn_attr_arg(i) + value = default_rdn_value_arg(i) + self.assertEqual(dn[i].value, value) + self.assertEqual(dn[attr], value) + + query_slice = dn[slice_low:slice_high] + for i, query_rdn in enumerate(query_slice): + slice_rdn = dn_slice[i] + self.assertEqual(slice_rdn, query_rdn) + else: + with self.assertRaises(TypeError): + dn[slice_low:slice_high] = dn_slice + + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + def test_iter(self): + for DN_class in (DN, EditableDN): + dn1 = DN_class(self.dn1) + dn2 = DN_class(self.dn2) + dn3 = DN_class(self.dn3) + + self.assertEqual(len(dn1), 1) + self.assertEqual(dn1[:], [self.rdn1]) + for i, ava in enumerate(dn1): + if i == 0: + self.assertEqual(ava, self.rdn1) + else: + self.fail("got iteration index %d, but len=%d" % (i, len(self.rdn1))) + + self.assertEqual(len(dn2), 1) + self.assertEqual(dn2[:], [self.rdn2]) + for i, ava in enumerate(dn2): + if i == 0: + self.assertEqual(ava, self.rdn2) + else: + self.fail("got iteration index %d, but len=%d" % (i, len(self.rdn2))) + + self.assertEqual(len(dn3), 2) + self.assertEqual(dn3[:], [self.rdn1, self.rdn2]) + for i, ava in enumerate(dn3): + if i == 0: + self.assertEqual(ava, self.rdn1) + elif i == 1: + self.assertEqual(ava, self.rdn2) + else: + self.fail("got iteration index %d, but len=%d" % (i, len(dn3))) + + + def test_concat(self): + for DN_class in (DN, EditableDN): + dn1 = DN_class((self.attr1, self.value1)) + dn2 = DN_class([self.attr2, self.value2]) + + # in-place addtion + + # Note: If __iadd__ is not available Python will emulate += by + # replacing the lhs object with the result of __add__ (if available). + # Thus += works for both immutable and mutable RDN,DN object, the only + # difference is an immutable without __iadd__ will have a different object + # on the lhs after the operator evaluates. + + dn1 += dn2 + self.assertEqual(dn1, self.dn3) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + + + dn1 = DN_class((self.attr1, self.value1)) + dn1 += self.rdn2 + self.assertEqual(dn1, self.dn3) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + + + dn1 = DN_class((self.attr1, self.value1)) + dn1 += self.dn2 + self.assertEqual(dn1, self.dn3) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + + + dn1 = DN_class((self.attr1, self.value1)) + dn1 += self.str_dn2 + self.assertEqual(dn1, self.dn3) + self.assertExpectedClass(DN_class, dn1, 'self') + for i in range(0, len(dn1)): + self.assertExpectedClass(DN_class, dn1[i], 'RDN') + for j in range(0, len(dn1[i])): + self.assertExpectedClass(DN_class, dn1[i][j], 'AVA') + + + # concatenation + dn1 = DN_class((self.attr1, self.value1)) + dn3 = dn1 + dn2 + self.assertEqual(dn3, self.dn3) + self.assertExpectedClass(DN_class, dn3, 'self') + for i in range(0, len(dn3)): + self.assertExpectedClass(DN_class, dn3[i], 'RDN') + for j in range(0, len(dn3[i])): + self.assertExpectedClass(DN_class, dn3[i][j], 'AVA') + + + dn1 = DN_class((self.attr1, self.value1)) + dn3 = dn1 + self.rdn2 + self.assertEqual(dn3, self.dn3) + self.assertExpectedClass(DN_class, dn3, 'self') + for i in range(0, len(dn3)): + self.assertExpectedClass(DN_class, dn3[i], 'RDN') + for j in range(0, len(dn3[i])): + self.assertExpectedClass(DN_class, dn3[i][j], 'AVA') + + dn3 = dn1 + self.str_rdn2 + self.assertEqual(dn3, self.dn3) + self.assertExpectedClass(DN_class, dn3, 'self') + for i in range(0, len(dn3)): + self.assertExpectedClass(DN_class, dn3[i], 'RDN') + self.assertExpectedClass(DN_class, dn3[i][0], 'AVA') + + dn3 = dn1 + self.str_dn2 + self.assertEqual(dn3, self.dn3) + self.assertExpectedClass(DN_class, dn3, 'self') + self.assertExpectedClass(DN_class, dn3, 'self') + for i in range(0, len(dn3)): + self.assertExpectedClass(DN_class, dn3[i], 'RDN') + for j in range(0, len(dn3[i])): + self.assertExpectedClass(DN_class, dn3[i][j], 'AVA') + + dn3 = dn1 + self.dn2 + self.assertEqual(dn3, self.dn3) + self.assertExpectedClass(DN_class, dn3, 'self') + self.assertExpectedClass(DN_class, dn3, 'self') + for i in range(0, len(dn3)): + self.assertExpectedClass(DN_class, dn3[i], 'RDN') + for j in range(0, len(dn3[i])): + self.assertExpectedClass(DN_class, dn3[i][j], 'AVA') + + def test_find(self): + for DN_class in (DN, EditableDN): + # -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 + dn = DN_class('t=0,t=1,cn=bob,t=3,t=4,t=5,cn=bob,t=7,t=8,t=9') + pat = DN_class('cn=bob') + + # forward + self.assertEqual(dn.find(pat), 2) + self.assertEqual(dn.find(pat, 1), 2) + self.assertEqual(dn.find(pat, 1, 3), 2) + self.assertEqual(dn.find(pat, 2, 3), 2) + self.assertEqual(dn.find(pat, 6), 6) + + self.assertEqual(dn.find(pat, 7), -1) + self.assertEqual(dn.find(pat, 1, 2), -1) + + with self.assertRaises(ValueError): + self.assertEqual(dn.index(pat, 7), -1) + with self.assertRaises(ValueError): + self.assertEqual(dn.index(pat, 1, 2), -1) + + # reverse + self.assertEqual(dn.rfind(pat), 6) + self.assertEqual(dn.rfind(pat, -4), 6) + self.assertEqual(dn.rfind(pat, 6), 6) + self.assertEqual(dn.rfind(pat, 6, 8), 6) + self.assertEqual(dn.rfind(pat, 6, 8), 6) + self.assertEqual(dn.rfind(pat, -8), 6) + self.assertEqual(dn.rfind(pat, -8, -4), 6) + self.assertEqual(dn.rfind(pat, -8, -5), 2) + + self.assertEqual(dn.rfind(pat, 7), -1) + self.assertEqual(dn.rfind(pat, -3), -1) + + with self.assertRaises(ValueError): + self.assertEqual(dn.rindex(pat, 7), -1) + with self.assertRaises(ValueError): + self.assertEqual(dn.rindex(pat, -3), -1) + + + def test_replace(self): + for DN_class in (DN, EditableDN): + dn = DN_class('t=0,t=1,t=2,t=3,t=4,t=5,t=6,t=7,t=8,t=9') + pat = DN('cn=bob') + replacement = DN('cn=bob') + + if DN_class.is_mutable: + n_replaced = dn.replace(pat, replacement) + self.assertEqual(n_replaced, 0) + else: + with self.assertRaises(AttributeError): + n_replaced = dn.replace(pat, replacement) + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + pat = DN('t=2') + if DN_class.is_mutable: + expected_dn = DN('t=0,t=1,cn=bob,t=3,t=4,t=5,t=6,t=7,t=8,t=9') + n_replaced = dn.replace(pat, replacement) + self.assertEqual(n_replaced, 1) + self.assertEqual(dn, expected_dn) + else: + with self.assertRaises(AttributeError): + n_replaced = dn.replace(pat, replacement) + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + dn = DN_class('t=0,t=1,t=2,t=3,t=4,t=5,t=6,t=7,t=2,t=9') + if DN_class.is_mutable: + expected_dn = DN('t=0,t=1,cn=bob,t=3,t=4,t=5,t=6,t=7,t=2,t=9') + n_replaced = dn.replace(pat, replacement, 1) + self.assertEqual(n_replaced, 1) + self.assertEqual(dn, expected_dn) + else: + with self.assertRaises(AttributeError): + n_replaced = dn.replace(pat, replacement, 1) + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + dn = DN_class('t=0,t=1,t=2,t=3,t=4,t=5,t=6,t=7,t=2,t=9') + if DN_class.is_mutable: + expected_dn = DN('t=0,t=1,cn=bob,t=3,t=4,t=5,t=6,t=7,t=2,t=9') + n_replaced = dn.replace(pat, replacement, 1) + self.assertEqual(n_replaced, 1) + self.assertEqual(dn, expected_dn) + else: + with self.assertRaises(AttributeError): + n_replaced = dn.replace(pat, replacement, 1) + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + replacement = DN('cn=bob,ou=people') + + dn = DN_class('t=0,t=1,t=2,t=3,t=4,t=5,t=6,t=7,t=2,t=9') + if DN_class.is_mutable: + expected_dn = DN('t=0,t=1,cn=bob,ou=people,t=3,t=4,t=5,t=6,t=7,t=2,t=9') + n_replaced = dn.replace(pat, replacement, 1) + self.assertEqual(n_replaced, 1) + self.assertEqual(dn, expected_dn) + else: + with self.assertRaises(AttributeError): + n_replaced = dn.replace(pat, replacement, 1) + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + dn = DN_class('t=0,t=1,t=2,t=3,t=4,t=5,t=6,t=7,t=2,t=9') + if DN_class.is_mutable: + expected_dn = DN('t=0,t=1,cn=bob,ou=people,t=3,t=4,t=5,t=6,t=7,cn=bob,ou=people,t=9') + n_replaced = dn.replace(pat, replacement) + self.assertEqual(n_replaced, 2) + self.assertEqual(dn, expected_dn) + else: + with self.assertRaises(AttributeError): + n_replaced = dn.replace(pat, replacement) + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + pat = DN('t=3,t=4') + replacement = DN('cn=bob') + dn = DN_class('t=0,t=1,t=2,t=3,t=4,t=5,t=6,t=7,t=8,t=9') + if DN_class.is_mutable: + expected_dn = DN('t=0,t=1,t=2,cn=bob,t=5,t=6,t=7,t=8,t=9') + n_replaced = dn.replace(pat, replacement) + self.assertEqual(n_replaced, 1) + self.assertEqual(dn, expected_dn) + else: + with self.assertRaises(AttributeError): + n_replaced = dn.replace(pat, replacement) + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + pat = DN('t=3,t=4') + replacement = DN('cn=bob,ou=people') + dn = DN_class('t=0,t=1,t=2,t=3,t=4,t=5,t=6,t=7,t=8,t=9') + if DN_class.is_mutable: + expected_dn = DN('t=0,t=1,t=2,cn=bob,ou=people,t=5,t=6,t=7,t=8,t=9') + n_replaced = dn.replace(pat, replacement) + self.assertEqual(n_replaced, 1) + self.assertEqual(dn, expected_dn) + else: + with self.assertRaises(AttributeError): + n_replaced = dn.replace(pat, replacement) + self.assertExpectedClass(DN_class, dn, 'self') + for i in range(0, len(dn)): + self.assertExpectedClass(DN_class, dn[i], 'RDN') + for j in range(0, len(dn[i])): + self.assertExpectedClass(DN_class, dn[i][j], 'AVA') + + def test_hashing(self): + # create DN's that have the same value + immutable_dn1 = DN((self.attr1, self.value1)) + immutable_dn2 = DN((self.attr1, self.value1)) + + mutable_dn1 = EditableDN((self.attr1, self.value1)) + mutable_dn2 = EditableDN((self.attr1, self.value1)) + + # Immutable DN's that are equal should hash to the same value. + # Mutable DN's should not be hashable. + + self.assertEqual(immutable_dn1, immutable_dn2) + self.assertEqual(immutable_dn1, mutable_dn1) + self.assertEqual(immutable_dn1, mutable_dn2) + self.assertEqual(mutable_dn1, immutable_dn2) + + # Good, everyone's equal, now verify their hash values + + self.assertEqual(hash(immutable_dn1), hash(immutable_dn2)) + with self.assertRaises(TypeError): + hash(mutable_dn1) + with self.assertRaises(TypeError): + hash(mutable_dn2) + + # Different immutable DN objects with the same value should + # map to 1 common key and 1 member in a set. The key and + # member are based on the object's value. + # + # Mutable DN objects should be unhashable. + + for DN_class in (DN, EditableDN): + dn1_a = DN_class(self.dn1) + dn1_b = DN_class(self.dn1) + + dn2_a = DN_class(self.dn2) + dn2_b = DN_class(self.dn2) + + dn3_a = DN_class(self.dn3) + dn3_b = DN_class(self.dn3) + + self.assertEqual(dn1_a, dn1_b) + self.assertEqual(dn2_a, dn2_b) + self.assertEqual(dn3_a, dn3_b) + + d = dict() + s = set() + + if DN_class.is_mutable: + with self.assertRaises(TypeError): + d[dn1_a] = str(dn1_a) + with self.assertRaises(TypeError): + d[dn1_b] = str(dn1_b) + with self.assertRaises(TypeError): + d[dn2_a] = str(dn2_a) + with self.assertRaises(TypeError): + d[dn2_b] = str(dn2_b) + + with self.assertRaises(TypeError): + s.add(dn1_a) + with self.assertRaises(TypeError): + s.add(dn1_b) + with self.assertRaises(TypeError): + s.add(dn2_a) + with self.assertRaises(TypeError): + s.add(dn2_b) + else: + d[dn1_a] = str(dn1_a) + d[dn1_b] = str(dn1_b) + d[dn2_a] = str(dn2_a) + d[dn2_b] = str(dn2_b) + + s.add(dn1_a) + s.add(dn1_b) + s.add(dn2_a) + s.add(dn2_b) + + self.assertEqual(len(d), 2) + self.assertEqual(len(s), 2) + self.assertEqual(sorted(d.keys()), sorted([dn1_a, dn2_a])) + self.assertEqual(sorted(s), sorted([dn1_a, dn2_a])) + + self.assertTrue(dn1_a in d) + self.assertTrue(dn1_b in d) + self.assertTrue(dn2_a in d) + self.assertTrue(dn2_b in d) + self.assertFalse(dn3_a in d) + self.assertFalse(dn3_b in d) + + self.assertTrue(d.has_key(dn1_a)) + self.assertTrue(d.has_key(dn1_b)) + self.assertTrue(d.has_key(dn2_a)) + self.assertTrue(d.has_key(dn2_b)) + self.assertFalse(d.has_key(dn3_a)) + self.assertFalse(d.has_key(dn3_b)) + + self.assertTrue(dn1_a in s) + self.assertTrue(dn1_b in s) + self.assertTrue(dn2_a in s) + self.assertTrue(dn2_b in s) + self.assertFalse(dn3_a in s) + self.assertFalse(dn3_b in s) + + def test_coerce(self): + # Coerce an immutable to a mutable + immutable_dn3 = DN(self.dn3) + mutable_dn3 = EditableDN(immutable_dn3) + self.assertEqual(mutable_dn3, self.dn3) + self.assertEqual(mutable_dn3, immutable_dn3) + + # Coerce a mutable to an immutable + mutable_dn3 = EditableDN(self.dn3) + immutable_dn3 = DN(mutable_dn3) + self.assertEqual(immutable_dn3, self.dn3) + self.assertEqual(immutable_dn3, mutable_dn3) + +class TestEscapes(unittest.TestCase): + def setUp(self): + self.privilege = 'R,W privilege' + self.dn_str_hex_escape = 'cn=R\\2cW privilege,cn=privileges,cn=pbac,dc=idm,dc=lab,dc=bos,dc=redhat,dc=com' + self.dn_str_backslash_escape = 'cn=R\\,W privilege,cn=privileges,cn=pbac,dc=idm,dc=lab,dc=bos,dc=redhat,dc=com' + + def test_escape(self): + for DN_class in (DN, EditableDN): + dn = DN_class(self.dn_str_hex_escape) + self.assertEqual(dn['cn'], self.privilege) + self.assertEqual(dn[0].value, self.privilege) + + dn = DN_class(self.dn_str_backslash_escape) + self.assertEqual(dn['cn'], self.privilege) + self.assertEqual(dn[0].value, self.privilege) + +class TestInternationalization(unittest.TestCase): + def setUp(self): + # Hello in Arabic + self.arabic_hello_utf8 = '\xd9\x85\xd9\x83\xd9\x8a\xd9\x84' + \ + '\xd8\xb9\x20\xd9\x85\xd8\xa7\xd9' + \ + '\x84\xd9\x91\xd8\xb3\xd9\x84\xd8\xa7' + + self.arabic_hello_unicode = self.arabic_hello_utf8.decode('utf-8') + + def test_i18n(self): + self.assertEqual(self.arabic_hello_utf8, + self.arabic_hello_unicode.encode('utf-8')) + + # AVA's + # test attr i18n + for AVA_class in (AVA, EditableAVA): + ava1 = AVA_class(self.arabic_hello_unicode, 'foo') + self.assertIsInstance(ava1.attr, unicode) + self.assertIsInstance(ava1.value, unicode) + self.assertEqual(ava1.attr, self.arabic_hello_unicode) + self.assertEqual(str(ava1), self.arabic_hello_utf8+'=foo') + + ava1 = AVA_class(self.arabic_hello_utf8, 'foo') + self.assertIsInstance(ava1.attr, unicode) + self.assertIsInstance(ava1.value, unicode) + self.assertEqual(ava1.attr, self.arabic_hello_unicode) + self.assertEqual(str(ava1), self.arabic_hello_utf8+'=foo') + + # test value i18n + ava1 = AVA_class('cn', self.arabic_hello_unicode) + self.assertIsInstance(ava1.attr, unicode) + self.assertIsInstance(ava1.value, unicode) + self.assertEqual(ava1.value, self.arabic_hello_unicode) + self.assertEqual(str(ava1), 'cn='+self.arabic_hello_utf8) + + ava1 = AVA_class('cn', self.arabic_hello_utf8) + self.assertIsInstance(ava1.attr, unicode) + self.assertIsInstance(ava1.value, unicode) + self.assertEqual(ava1.value, self.arabic_hello_unicode) + self.assertEqual(str(ava1), 'cn='+self.arabic_hello_utf8) + + # RDN's + # test attr i18n + for RDN_class in (RDN, EditableRDN): + rdn1 = RDN_class((self.arabic_hello_unicode, 'foo')) + self.assertIsInstance(rdn1.attr, unicode) + self.assertIsInstance(rdn1.value, unicode) + self.assertEqual(rdn1.attr, self.arabic_hello_unicode) + self.assertEqual(str(rdn1), self.arabic_hello_utf8+'=foo') + + rdn1 = RDN_class((self.arabic_hello_utf8, 'foo')) + self.assertIsInstance(rdn1.attr, unicode) + self.assertIsInstance(rdn1.value, unicode) + self.assertEqual(rdn1.attr, self.arabic_hello_unicode) + self.assertEqual(str(rdn1), self.arabic_hello_utf8+'=foo') + + # test value i18n + rdn1 = RDN_class(('cn', self.arabic_hello_unicode)) + self.assertIsInstance(rdn1.attr, unicode) + self.assertIsInstance(rdn1.value, unicode) + self.assertEqual(rdn1.value, self.arabic_hello_unicode) + self.assertEqual(str(rdn1), 'cn='+self.arabic_hello_utf8) + + rdn1 = RDN_class(('cn', self.arabic_hello_utf8)) + self.assertIsInstance(rdn1.attr, unicode) + self.assertIsInstance(rdn1.value, unicode) + self.assertEqual(rdn1.value, self.arabic_hello_unicode) + self.assertEqual(str(rdn1), 'cn='+self.arabic_hello_utf8) + + # DN's + # test attr i18n + for DN_class in (DN, EditableDN): + dn1 = DN_class((self.arabic_hello_unicode, 'foo')) + self.assertIsInstance(dn1[0].attr, unicode) + self.assertIsInstance(dn1[0].value, unicode) + self.assertEqual(dn1[0].attr, self.arabic_hello_unicode) + self.assertEqual(str(dn1), self.arabic_hello_utf8+'=foo') + + dn1 = DN_class((self.arabic_hello_utf8, 'foo')) + self.assertIsInstance(dn1[0].attr, unicode) + self.assertIsInstance(dn1[0].value, unicode) + self.assertEqual(dn1[0].attr, self.arabic_hello_unicode) + self.assertEqual(str(dn1), self.arabic_hello_utf8+'=foo') + + # test value i18n + dn1 = DN_class(('cn', self.arabic_hello_unicode)) + self.assertIsInstance(dn1[0].attr, unicode) + self.assertIsInstance(dn1[0].value, unicode) + self.assertEqual(dn1[0].value, self.arabic_hello_unicode) + self.assertEqual(str(dn1), 'cn='+self.arabic_hello_utf8) + + dn1 = DN_class(('cn', self.arabic_hello_utf8)) + self.assertIsInstance(dn1[0].attr, unicode) + self.assertIsInstance(dn1[0].value, unicode) + self.assertEqual(dn1[0].value, self.arabic_hello_unicode) + self.assertEqual(str(dn1), 'cn='+self.arabic_hello_utf8) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_ipaserver/test_changepw.py b/tests/test_ipaserver/test_changepw.py index 03576685..4491e0b6 100644 --- a/tests/test_ipaserver/test_changepw.py +++ b/tests/test_ipaserver/test_changepw.py @@ -23,7 +23,7 @@ from httptest import Unauthorized_HTTP_test from tests.test_xmlrpc.xmlrpc_test import XMLRPC_test from tests.util import assert_equal, assert_not_equal from ipalib import api, errors -from ipalib.dn import DN +from ipapython.dn import DN import ldap testuser = u'tuser' @@ -57,9 +57,7 @@ class test_changepw(XMLRPC_test, Unauthorized_HTTP_test): ) def _checkpw(self, user, password): - dn = str(DN(('uid', user), - api.env.container_user, - api.env.basedn)) + dn = str(DN(('uid', user), api.env.container_user, api.env.basedn)) conn = ldap.initialize(api.env.ldap_uri) try: conn.simple_bind_s(dn, password) diff --git a/tests/test_ipaserver/test_ldap.py b/tests/test_ipaserver/test_ldap.py index 1bbd94fb..cd3ba3cd 100644 --- a/tests/test_ipaserver/test_ldap.py +++ b/tests/test_ipaserver/test_ldap.py @@ -33,7 +33,7 @@ from ipalib.plugins.host import host import nss.nss as nss from ipalib import api, x509, create_api, errors from ipapython import ipautil -from ipalib.dn import * +from ipapython.dn import DN class test_ldap(object): """ @@ -45,8 +45,8 @@ class test_ldap(object): self.ldapuri = 'ldap://%s' % ipautil.format_netloc(api.env.host) self.ccache = '/tmp/krb5cc_%d' % os.getuid() nss.nss_init_nodb() - self.dn = str(DN(('krbprincipalname','ldap/%s@%s' % (api.env.host, api.env.realm)), - ('cn','services'),('cn','accounts'),api.env.basedn)) + self.dn = DN(('krbprincipalname','ldap/%s@%s' % (api.env.host, api.env.realm)), + ('cn','services'),('cn','accounts'),api.env.basedn) def tearDown(self): if self.conn and self.conn.isconnected(): @@ -90,7 +90,7 @@ class test_ldap(object): else: raise nose.SkipTest("No directory manager password in %s" % pwfile) self.conn = ldap2(shared_instance=False, ldap_uri=self.ldapuri) - self.conn.connect(bind_dn='cn=directory manager', bind_pw=dm_password) + self.conn.connect(bind_dn=DN(('cn', 'directory manager')), bind_pw=dm_password) (dn, entry_attrs) = self.conn.get_entry(self.dn, ['usercertificate']) cert = entry_attrs.get('usercertificate') cert = cert[0] @@ -120,7 +120,7 @@ class test_ldap(object): fp.close() else: raise nose.SkipTest("No directory manager password in %s" % pwfile) - myapi.Backend.ldap2.connect(bind_dn="cn=Directory Manager", bind_pw=dm_password) + myapi.Backend.ldap2.connect(bind_dn=DN(('cn', 'Directory Manager')), bind_pw=dm_password) result = myapi.Command['service_show']('ldap/%s@%s' % (api.env.host, api.env.realm,)) entry_attrs = result['result'] @@ -145,4 +145,3 @@ class test_ldap(object): cert = cert[0] serial = unicode(x509.get_serial_number(cert, x509.DER)) assert serial is not None - diff --git a/tests/test_xmlrpc/test_attr.py b/tests/test_xmlrpc/test_attr.py index f5003c40..799c7793 100644 --- a/tests/test_xmlrpc/test_attr.py +++ b/tests/test_xmlrpc/test_attr.py @@ -21,29 +21,17 @@ Test --setattr and --addattr and other attribute-specific issues """ -from ipalib import api, errors, x509 +from ipalib import api, errors from tests.test_xmlrpc import objectclasses -from xmlrpc_test import (Declarative, fuzzy_digits, fuzzy_uuid, fuzzy_date, - fuzzy_hex, fuzzy_hash, fuzzy_issuer) -from ipalib.dn import * -import base64 - -user1 = u'tuser1' -fqdn1 = u'testhost1.%s' % api.env.domain - -# We can use the same cert we generated for the service tests -fd = open('tests/test_xmlrpc/service.crt', 'r') -servercert = fd.readlines() -servercert = u''.join(servercert) -servercert = x509.strip_header(servercert) -servercert = servercert.replace('\n', '') -fd.close() +from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid +from ipapython.dn import DN + +user1=u'tuser1' class test_attr(Declarative): cleanup_commands = [ ('user_del', [user1], {}), - ('host_del', [fqdn1], {}), ] tests = [ @@ -72,16 +60,13 @@ class test_attr(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), has_keytab=False, has_password=False, ), @@ -563,71 +548,4 @@ class test_attr(Declarative): desc='Server is unwilling to perform', info=''), ), - dict( - desc='Try to create %r with description and --addattr description' % fqdn1, - command=('host_add', [fqdn1], - dict( - description=u'Test host 1', - addattr=u'description=Test host 2', - force=True, - ), - ), - expected=errors.OnlyOneValueAllowed(attr='description'), - ), - - dict( - desc='Create %r with a certificate' % fqdn1, - command=('host_add', [fqdn1], - dict( - usercertificate=servercert, - force=True, - ), - ), - expected=dict( - value=fqdn1, - summary=u'Added host "%s"' % fqdn1, - result=dict( - dn=lambda x: DN(x) == DN(('fqdn',fqdn1),('cn','computers'), - ('cn','accounts'),api.env.basedn), - fqdn=[fqdn1], - krbprincipalname=[u'host/%s@%s' % (fqdn1, api.env.realm)], - objectclass=objectclasses.host, - ipauniqueid=[fuzzy_uuid], - managedby_host=[fqdn1], - usercertificate=[base64.b64decode(servercert)], - valid_not_before=fuzzy_date, - valid_not_after=fuzzy_date, - subject=lambda x: DN(x) == \ - DN(('CN',api.env.host),x509.subject_base()), - serial_number=fuzzy_digits, - serial_number_hex=fuzzy_hex, - md5_fingerprint=fuzzy_hash, - sha1_fingerprint=fuzzy_hash, - issuer=fuzzy_issuer, - has_keytab=False, - has_password=False, - ), - ), - ), - - dict( - desc='Remove %r certificate using --delattr' % fqdn1, - command=('host_mod', [fqdn1], - dict( - delattr=u'usercertificate=%s' % servercert, - ), - ), - expected=dict( - value=fqdn1, - summary=u'Modified host "%s"' % fqdn1, - result=dict( - fqdn=[fqdn1], - krbprincipalname=[u'host/%s@%s' % (fqdn1, api.env.realm)], - managedby_host=[fqdn1], - has_keytab=False, - has_password=False, - ), - ), - ), - ] diff --git a/tests/test_xmlrpc/test_automember_plugin.py b/tests/test_xmlrpc/test_automember_plugin.py index ceae8c3f..36a51093 100644 --- a/tests/test_xmlrpc/test_automember_plugin.py +++ b/tests/test_xmlrpc/test_automember_plugin.py @@ -22,6 +22,7 @@ Test the `ipalib/plugins/automember.py` module. """ from ipalib import api, errors +from ipapython.dn import DN from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid @@ -132,7 +133,7 @@ class test_automember(Declarative): gidnumber=[fuzzy_digits], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], - dn=u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn), + dn=DN(('cn', group1), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn), ), ), ), @@ -151,8 +152,8 @@ class test_automember(Declarative): description=[u'Test desc'], objectclass=objectclasses.hostgroup, ipauniqueid=[fuzzy_uuid], - mepmanagedentry=['cn=%s,cn=ng,cn=alt,%s' % (hostgroup1, api.env.basedn)], - dn=u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup1, api.env.basedn), + mepmanagedentry=[DN(('cn', hostgroup1), ('cn', 'ng'), ('cn', 'alt'), api.env.basedn)], + dn=DN(('cn', hostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn), ), ), ), @@ -171,8 +172,8 @@ class test_automember(Declarative): description=[u'Test desc'], objectclass=objectclasses.hostgroup, ipauniqueid=[fuzzy_uuid], - mepmanagedentry=['cn=%s,cn=ng,cn=alt,%s' % (hostgroup2, api.env.basedn)], - dn=u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup2, api.env.basedn), + mepmanagedentry=[DN(('cn', hostgroup2), ('cn', 'ng'), ('cn', 'alt'), api.env.basedn)], + dn=DN(('cn', hostgroup2), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn), ), ), ), @@ -191,8 +192,8 @@ class test_automember(Declarative): description=[u'Test desc'], objectclass=objectclasses.hostgroup, ipauniqueid=[fuzzy_uuid], - mepmanagedentry=['cn=%s,cn=ng,cn=alt,%s' % (hostgroup3, api.env.basedn)], - dn=u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup3, api.env.basedn), + mepmanagedentry=[DN(('cn', hostgroup3), ('cn', 'ng'), ('cn', 'alt'), api.env.basedn)], + dn=DN(('cn', hostgroup3), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn), ), ), ), @@ -211,8 +212,8 @@ class test_automember(Declarative): description=[u'Test desc'], objectclass=objectclasses.hostgroup, ipauniqueid=[fuzzy_uuid], - mepmanagedentry=['cn=%s,cn=ng,cn=alt,%s' % (hostgroup4, api.env.basedn)], - dn=u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup4, api.env.basedn), + mepmanagedentry=[DN(('cn', hostgroup4), ('cn', 'ng'), ('cn', 'alt'), api.env.basedn)], + dn=DN(('cn', hostgroup4), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn), ), ), ), @@ -232,7 +233,7 @@ class test_automember(Declarative): gidnumber=[fuzzy_digits], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], - dn=u'cn=%s,cn=groups,cn=accounts,%s' % (defaultgroup1, api.env.basedn), + dn=DN(('cn', defaultgroup1), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn), ), ), ), @@ -251,8 +252,8 @@ class test_automember(Declarative): description=[u'Default test desc'], objectclass=objectclasses.hostgroup, ipauniqueid=[fuzzy_uuid], - mepmanagedentry=['cn=%s,cn=ng,cn=alt,%s' % (defaulthostgroup1, api.env.basedn)], - dn=u'cn=%s,cn=hostgroups,cn=accounts,%s' % (defaulthostgroup1, api.env.basedn), + mepmanagedentry=[DN(('cn', defaulthostgroup1), ('cn', 'ng'), ('cn', 'alt'), api.env.basedn)], + dn=DN(('cn', defaulthostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn), ), ), ), @@ -269,9 +270,9 @@ class test_automember(Declarative): result=dict( cn=[group1], description=[u'Test desc'], - automembertargetgroup=[u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn)], + automembertargetgroup=[DN(('cn', group1), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn)], objectclass=objectclasses.automember, - dn=u'cn=%s,cn=group,cn=automember,cn=etc,%s' % (group1, api.env.basedn), + dn=DN(('cn', group1), ('cn', 'group'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), ), ), ), @@ -299,7 +300,7 @@ class test_automember(Declarative): cn=[group1], description=[u'Test desc'], automemberinclusiveregex=[u'manager=%s' % group_include_regex], - automembertargetgroup=[u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn)], + automembertargetgroup=[DN(('cn', group1), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn)], ), ), ), @@ -318,9 +319,9 @@ class test_automember(Declarative): result=dict( cn=[hostgroup1], description=[u'Test desc'], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup1, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], objectclass=objectclasses.automember, - dn=u'cn=%s,cn=hostgroup,cn=automember,cn=etc,%s' % (hostgroup1, api.env.basedn), + dn=DN(('cn', hostgroup1), ('cn', 'hostgroup'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), ), ), ), @@ -348,7 +349,7 @@ class test_automember(Declarative): cn=[hostgroup1], description=[u'Test desc'], automemberinclusiveregex=[u'fqdn=%s' % hostgroup_include_regex], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup1, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], ), ), ), @@ -401,7 +402,7 @@ class test_automember(Declarative): result=dict( cn=[hostgroup1], description=[u'Test desc'], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup1, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], automemberinclusiveregex=[u'fqdn=%s' % hostgroup_include_regex, u'fqdn=%s' % hostgroup_include_regex3, u'fqdn=%s' % hostgroup_include_regex2, @@ -428,9 +429,9 @@ class test_automember(Declarative): result=dict( cn=[hostgroup2], description=[u'Test desc'], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup2, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup2), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], objectclass=objectclasses.automember, - dn=u'cn=%s,cn=hostgroup,cn=automember,cn=etc,%s' % (hostgroup2, api.env.basedn), + dn=DN(('cn', hostgroup2), ('cn', 'hostgroup'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), ), ), ), @@ -458,7 +459,7 @@ class test_automember(Declarative): cn=[hostgroup2], description=[u'Test desc'], automemberinclusiveregex=[u'fqdn=%s' % hostgroup_exclude_regex], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup2, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup2), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], ), ), ), @@ -477,9 +478,9 @@ class test_automember(Declarative): result=dict( cn=[hostgroup3], description=[u'Test desc'], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup3, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup3), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], objectclass=objectclasses.automember, - dn=u'cn=%s,cn=hostgroup,cn=automember,cn=etc,%s' % (hostgroup3, api.env.basedn), + dn=DN(('cn', hostgroup3), ('cn', 'hostgroup'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), ), ), ), @@ -507,7 +508,7 @@ class test_automember(Declarative): cn=[hostgroup3], description=[u'Test desc'], automemberinclusiveregex=[u'fqdn=%s' % hostgroup_exclude_regex2], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup3, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup3), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], ), ), ), @@ -526,9 +527,9 @@ class test_automember(Declarative): result=dict( cn=[hostgroup4], description=[u'Test desc'], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup4, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup4), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], objectclass=objectclasses.automember, - dn=u'cn=%s,cn=hostgroup,cn=automember,cn=etc,%s' % (hostgroup4, api.env.basedn), + dn=DN(('cn', hostgroup4), ('cn', 'hostgroup'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), ), ), ), @@ -556,7 +557,7 @@ class test_automember(Declarative): cn=[hostgroup4], description=[u'Test desc'], automemberinclusiveregex=[u'fqdn=%s' % hostgroup_exclude_regex3], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup4, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup4), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], ), ), ), @@ -574,8 +575,8 @@ class test_automember(Declarative): cn=[group1], description=[u'Test desc'], automemberinclusiveregex=[u'manager=%s' % group_include_regex], - automembertargetgroup=[u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn)], - dn=u'cn=%s,cn=group,cn=automember,cn=etc,%s' % (group1, api.env.basedn), + automembertargetgroup=[DN(('cn', group1), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn)], + dn=DN(('cn', group1), ('cn', 'group'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), ), summary=None, ), @@ -596,8 +597,8 @@ class test_automember(Declarative): cn=[group1], description=[u'Test desc'], automemberinclusiveregex=[u'manager=%s' % group_include_regex], - automembertargetgroup=[u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn)], - dn=u'cn=%s,cn=group,cn=automember,cn=etc,%s' % (group1, api.env.basedn), + automembertargetgroup=[DN(('cn', group1), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn)], + dn=DN(('cn', group1), ('cn', 'group'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), ), ], summary=u'1 rules matched', @@ -618,7 +619,7 @@ class test_automember(Declarative): cn=[group1], description=[u'New desc 1'], automemberinclusiveregex=[u'manager=%s' % group_include_regex], - automembertargetgroup=[u'cn=%s,cn=groups,cn=accounts,%s' % (group1, api.env.basedn)], + automembertargetgroup=[DN(('cn', group1), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn)], ), summary=u'Modified automember rule "%s"' % group1, value=group1, @@ -637,7 +638,7 @@ class test_automember(Declarative): result=dict( cn=[hostgroup1], description=[u'Test desc'], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup1, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], automemberinclusiveregex=[u'fqdn=%s' % hostgroup_include_regex, u'fqdn=%s' % hostgroup_include_regex3, u'fqdn=%s' % hostgroup_include_regex2, @@ -646,7 +647,7 @@ class test_automember(Declarative): u'fqdn=%s' % hostgroup_exclude_regex3, u'fqdn=%s' % hostgroup_exclude_regex, ], - dn=u'cn=%s,cn=hostgroup,cn=automember,cn=etc,%s' % (hostgroup1, api.env.basedn), + dn=DN(('cn', hostgroup1), ('cn', 'hostgroup'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), ), summary=None, ), @@ -666,7 +667,7 @@ class test_automember(Declarative): dict( cn=[hostgroup1], description=[u'Test desc'], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup1, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], automemberinclusiveregex=[u'fqdn=%s' % hostgroup_include_regex, u'fqdn=%s' % hostgroup_include_regex3, u'fqdn=%s' % hostgroup_include_regex2, @@ -675,7 +676,7 @@ class test_automember(Declarative): u'fqdn=%s' % hostgroup_exclude_regex3, u'fqdn=%s' % hostgroup_exclude_regex, ], - dn=u'cn=%s,cn=hostgroup,cn=automember,cn=etc,%s' % (hostgroup1, api.env.basedn), + dn=DN(('cn', hostgroup1), ('cn', 'hostgroup'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), ), ], summary=u'1 rules matched', @@ -695,7 +696,7 @@ class test_automember(Declarative): result=dict( cn=[hostgroup1], description=[u'New desc 1'], - automembertargetgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup1, api.env.basedn)], + automembertargetgroup=[DN(('cn', hostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], automemberinclusiveregex=[u'fqdn=%s' % hostgroup_include_regex, u'fqdn=%s' % hostgroup_include_regex3, u'fqdn=%s' % hostgroup_include_regex2, @@ -722,7 +723,7 @@ class test_automember(Declarative): expected=dict( result=dict( cn=[u'Group'], - automemberdefaultgroup=[u'cn=%s,cn=groups,cn=accounts,%s' % (defaultgroup1, api.env.basedn)], + automemberdefaultgroup=[DN(('cn', defaultgroup1), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn)], ), value=u'group', summary=u'Set default (fallback) group for automember "group"', @@ -737,9 +738,9 @@ class test_automember(Declarative): ), expected=dict( result=dict( - dn=u'cn=group,cn=automember,cn=etc,%s' % (api.env.basedn), + dn=DN(('cn', 'group'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), cn=[u'Group'], - automemberdefaultgroup=[u'cn=%s,cn=groups,cn=accounts,%s' % (defaultgroup1, api.env.basedn)], + automemberdefaultgroup=[DN(('cn', defaultgroup1), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn)], ), value=u'group', summary=None, @@ -758,7 +759,7 @@ class test_automember(Declarative): expected=dict( result=dict( cn=[u'Hostgroup'], - automemberdefaultgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (defaulthostgroup1, api.env.basedn)], + automemberdefaultgroup=[DN(('cn', defaulthostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], ), value=u'hostgroup', summary=u'Set default (fallback) group for automember "hostgroup"', @@ -775,9 +776,9 @@ class test_automember(Declarative): ), expected=dict( result=dict( - dn=u'cn=hostgroup,cn=automember,cn=etc,%s' % (api.env.basedn), + dn=DN(('cn', 'hostgroup'), ('cn', 'automember'), ('cn', 'etc'), api.env.basedn), cn=[u'Hostgroup'], - automemberdefaultgroup=[u'cn=%s,cn=hostgroups,cn=accounts,%s' % (defaulthostgroup1, api.env.basedn)], + automemberdefaultgroup=[DN(('cn', defaulthostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn)], ), value=u'hostgroup', summary=None, @@ -810,10 +811,13 @@ class test_automember(Declarative): cn=[u'Michael Scott'], initials=[u'MS'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=[u'cn=global_policy,cn=%s,cn=kerberos,%s' % (api.env.realm, api.env.basedn)], - mepmanagedentry=[u'cn=%s,cn=groups,cn=accounts,%s' % (manager1, api.env.basedn)], + krbpwdpolicyreference=[DN(('cn', 'global_policy'), ('cn', api.env.realm), ('cn', 'kerberos'), + api.env.basedn)], + mepmanagedentry=[DN(('cn', manager1), ('cn', 'groups'), ('cn', 'accounts'), + api.env.basedn)], memberof_group=[u'defaultgroup1', u'ipausers'], - dn=u'uid=mscott,cn=users,cn=accounts,' + api.env.basedn, + dn=DN(('uid', 'mscott'), ('cn', 'users'), ('cn', 'accounts'), + api.env.basedn), ), ), ), @@ -840,15 +844,18 @@ class test_automember(Declarative): uid=[user1], uidnumber=[fuzzy_digits], gidnumber=[fuzzy_digits], - manager=[u'uid=mscott,cn=users,cn=accounts,%s' % api.env.basedn], + manager=[DN(('uid', 'mscott'), ('cn', 'users'), ('cn', 'accounts'), api.env.basedn)], displayname=[u'Test User1'], cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=[u'cn=global_policy,cn=%s,cn=kerberos,%s' % (api.env.realm, api.env.basedn)], - mepmanagedentry=[u'cn=%s,cn=groups,cn=accounts,%s' % (user1, api.env.basedn)], + krbpwdpolicyreference=[DN(('cn', 'global_policy'), ('cn', api.env.realm), ('cn', 'kerberos'), + api.env.basedn)], + mepmanagedentry=[DN(('cn', user1), ('cn', 'groups'), ('cn', 'accounts'), + api.env.basedn)], memberof_group=[u'group1', u'ipausers'], - dn=u'uid=tuser1,cn=users,cn=accounts,' + api.env.basedn, + dn=DN(('uid', 'tuser1'), ('cn', 'users'), ('cn', 'accounts'), + api.env.basedn), ), ), ), @@ -867,7 +874,7 @@ class test_automember(Declarative): value=fqdn1, summary=u'Added host "%s"' % fqdn1, result=dict( - dn=u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn1, api.env.basedn), + dn=DN(('fqdn', fqdn1), ('cn', 'computers'), ('cn', 'accounts'), api.env.basedn), fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -895,7 +902,7 @@ class test_automember(Declarative): value=fqdn2, summary=u'Added host "%s"' % fqdn2, result=dict( - dn=u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn2, api.env.basedn), + dn=DN(('fqdn', fqdn2), ('cn', 'computers'), ('cn', 'accounts'), api.env.basedn), fqdn=[fqdn2], description=[u'Test host 2'], l=[u'Undisclosed location 1'], @@ -923,7 +930,7 @@ class test_automember(Declarative): value=fqdn3, summary=u'Added host "%s"' % fqdn3, result=dict( - dn=u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn3, api.env.basedn), + dn=DN(('fqdn', fqdn3), ('cn', 'computers'), ('cn', 'accounts'), api.env.basedn), fqdn=[fqdn3], description=[u'Test host 3'], l=[u'Undisclosed location 1'], @@ -951,7 +958,7 @@ class test_automember(Declarative): value=fqdn4, summary=u'Added host "%s"' % fqdn4, result=dict( - dn=u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn4, api.env.basedn), + dn=DN(('fqdn', fqdn4), ('cn', 'computers'), ('cn', 'accounts'), api.env.basedn), fqdn=[fqdn4], description=[u'Test host 4'], l=[u'Undisclosed location 1'], @@ -979,7 +986,7 @@ class test_automember(Declarative): value=fqdn5, summary=u'Added host "%s"' % fqdn5, result=dict( - dn=u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn5, api.env.basedn), + dn=DN(('fqdn', fqdn5), ('cn', 'computers'), ('cn', 'accounts'), api.env.basedn), fqdn=[fqdn5], description=[u'Test host 5'], l=[u'Undisclosed location 1'], @@ -1001,7 +1008,7 @@ class test_automember(Declarative): value=hostgroup1, summary=None, result={ - 'dn': u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup1, api.env.basedn), + 'dn': DN(('cn', hostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn), 'member_host': [u'%s' % fqdn1], 'cn': [hostgroup1], 'description': [u'Test desc'], @@ -1017,7 +1024,7 @@ class test_automember(Declarative): value=defaulthostgroup1, summary=None, result={ - 'dn': u'cn=%s,cn=hostgroups,cn=accounts,%s' % (defaulthostgroup1, api.env.basedn), + 'dn': DN(('cn', defaulthostgroup1), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn), 'member_host': [u'%s' % fqdn2], 'cn': [defaulthostgroup1], 'description': [u'Default test desc'], @@ -1033,7 +1040,7 @@ class test_automember(Declarative): value=hostgroup2, summary=None, result={ - 'dn': u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup2, api.env.basedn), + 'dn': DN(('cn', hostgroup2), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn), 'member_host': [u'%s' % fqdn3], 'cn': [hostgroup2], 'description': [u'Test desc'], @@ -1049,7 +1056,7 @@ class test_automember(Declarative): value=hostgroup3, summary=None, result={ - 'dn': u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup3, api.env.basedn), + 'dn': DN(('cn', hostgroup3), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn), 'member_host': [u'%s' % fqdn4], 'cn': [hostgroup3], 'description': [u'Test desc'], @@ -1065,7 +1072,7 @@ class test_automember(Declarative): value=hostgroup4, summary=None, result={ - 'dn': u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup4, api.env.basedn), + 'dn': DN(('cn', hostgroup4), ('cn', 'hostgroups'), ('cn', 'accounts'), api.env.basedn), 'member_host': [u'%s' % fqdn5], 'cn': [hostgroup4], 'description': [u'Test desc'], diff --git a/tests/test_xmlrpc/test_automount_plugin.py b/tests/test_xmlrpc/test_automount_plugin.py index d6c28997..19968a0d 100644 --- a/tests/test_xmlrpc/test_automount_plugin.py +++ b/tests/test_xmlrpc/test_automount_plugin.py @@ -28,7 +28,7 @@ import shutil from ipalib import api from ipalib import errors -from ipalib.dn import DN +from ipapython.dn import DN from nose.tools import raises, assert_raises # pylint: disable=E0611 from xmlrpc_test import XMLRPC_test, assert_attr_equal @@ -238,40 +238,36 @@ class test_automount(AutomountTest): result=dict( keys={'auto.direct': ()}, orphanmaps=(dict( - dn=lambda dn: DN(dn) == DN( - ('automountmapname', self.mapname), - ('cn', self.locname), - ('cn', 'automount'), api.env.basedn), + dn=DN(('automountmapname', self.mapname), + ('cn', self.locname), + ('cn', 'automount'), api.env.basedn), description=(u'description of map',), automountmapname=(u'testmap',)),), orphankeys=[( dict( - dn=lambda dn: DN(dn) == DN( - ('description', self.keyname2), - ('automountmapname', 'testmap'), - ('cn', self.locname), - ('cn', 'automount'), api.env.basedn), + dn=DN(('description', self.keyname2), + ('automountmapname', 'testmap'), + ('cn', self.locname), + ('cn', 'automount'), api.env.basedn), automountkey=(self.keyname2,), description=(self.keyname2,), automountinformation=(u'ro',), ), dict( - dn=lambda dn: DN(dn) == DN( - ('description', self.keyname_rename), - ('automountmapname', 'testmap'), - ('cn', self.locname), - ('cn', 'automount'), api.env.basedn), + dn=DN(('description', self.keyname_rename), + ('automountmapname', 'testmap'), + ('cn', self.locname), + ('cn', 'automount'), api.env.basedn), automountkey=(self.keyname_rename,), description=(self.keyname_rename,), automountinformation=(u'rw',), ))], maps=( dict( - dn=lambda dn: DN(dn) == DN( - ('description', '/- auto.direct'), - ('automountmapname', 'auto.master'), - ('cn', self.locname), - ('cn', 'automount'), api.env.basedn), + dn=DN(('description', '/- auto.direct'), + ('automountmapname', 'auto.master'), + ('cn', self.locname), + ('cn', 'automount'), api.env.basedn), automountkey=(u'/-',), description=(u'/- auto.direct',), automountinformation=(u'auto.direct',) diff --git a/tests/test_xmlrpc/test_batch_plugin.py b/tests/test_xmlrpc/test_batch_plugin.py index 19728add..55e55705 100644 --- a/tests/test_xmlrpc/test_batch_plugin.py +++ b/tests/test_xmlrpc/test_batch_plugin.py @@ -25,7 +25,7 @@ from ipalib import api, errors from tests.test_xmlrpc import objectclasses from tests.util import assert_equal, Fuzzy, assert_deepequal from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid -from ipalib.dn import DN +from ipapython.dn import DN group1 = u'testgroup1' @@ -96,11 +96,10 @@ class test_batch(Declarative): objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], gidnumber=[fuzzy_digits], - dn=lambda x: DN(x) == \ - DN(('cn', 'testgroup1'), - ('cn', 'groups'), - ('cn', 'accounts'), - api.env.basedn), + dn=DN(('cn', 'testgroup1'), + ('cn', 'groups'), + ('cn', 'accounts'), + api.env.basedn), ), error=None), dict( @@ -159,11 +158,10 @@ class test_batch(Declarative): objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], gidnumber=[fuzzy_digits], - dn=lambda x: DN(x) == \ - DN(('cn', 'testgroup1'), - ('cn', 'groups'), - ('cn', 'accounts'), - api.env.basedn), + dn=DN(('cn', 'testgroup1'), + ('cn', 'groups'), + ('cn', 'accounts'), + api.env.basedn), ), error=None), ), diff --git a/tests/test_xmlrpc/test_cert.py b/tests/test_xmlrpc/test_cert.py index 90809ab3..4f95ffe1 100644 --- a/tests/test_xmlrpc/test_cert.py +++ b/tests/test_xmlrpc/test_cert.py @@ -33,7 +33,7 @@ import tempfile from ipapython import ipautil import nose import base64 -from ipalib.dn import * +from ipapython.dn import DN # So we can save the cert from issuance and compare it later cert = None diff --git a/tests/test_xmlrpc/test_delegation_plugin.py b/tests/test_xmlrpc/test_delegation_plugin.py index 95aa8287..a31fed3e 100644 --- a/tests/test_xmlrpc/test_delegation_plugin.py +++ b/tests/test_xmlrpc/test_delegation_plugin.py @@ -24,6 +24,7 @@ Test the `ipalib/plugins/delegation.py` module. from ipalib import api, errors from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid +from ipapython.dn import DN delegation1 = u'testdelegation' member1 = u'admins' @@ -148,8 +149,9 @@ class test_delegation(Declarative): value=delegation1, summary=None, result={ - 'aci': u'(targetattr = "street || c || l || st || postalcode")(targetfilter = "(memberOf=cn=admins,cn=groups,cn=accounts,%s)")(version 3.0;acl "delegation:testdelegation";allow (write) groupdn = "ldap:///cn=editors,cn=groups,cn=accounts,%s";)' \ - % (api.env.basedn, api.env.basedn) + 'aci': u'(targetattr = "street || c || l || st || postalcode")(targetfilter = "(memberOf=%s)")(version 3.0;acl "delegation:testdelegation";allow (write) groupdn = "ldap:///%s";)' % \ + (DN(('cn', 'admins'), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn), + DN(('cn', 'editors'), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn)) }, ), ), @@ -200,8 +202,9 @@ class test_delegation(Declarative): summary=u'1 delegation matched', result=[ { - 'aci': u'(targetattr = "street || c || l || st || postalcode")(targetfilter = "(memberOf=cn=admins,cn=groups,cn=accounts,%s)")(version 3.0;acl "delegation:testdelegation";allow (write) groupdn = "ldap:///cn=editors,cn=groups,cn=accounts,%s";)' \ - % (api.env.basedn, api.env.basedn), + 'aci': u'(targetattr = "street || c || l || st || postalcode")(targetfilter = "(memberOf=%s)")(version 3.0;acl "delegation:testdelegation";allow (write) groupdn = "ldap:///%s";)' % \ + (DN(('cn', 'admins'), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn), + DN(('cn', 'editors'), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn)), }, ], ), diff --git a/tests/test_xmlrpc/test_dns_plugin.py b/tests/test_xmlrpc/test_dns_plugin.py index 9c9b2239..2b6d53c0 100644 --- a/tests/test_xmlrpc/test_dns_plugin.py +++ b/tests/test_xmlrpc/test_dns_plugin.py @@ -22,7 +22,7 @@ Test the `ipalib/plugins/dns.py` module. import nose from ipalib import api, errors -from ipalib.dn import * +from ipapython.dn import DN from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid @@ -139,7 +139,7 @@ class test_dns(Declarative): 'value': dnszone1, 'summary': None, 'result': { - 'dn': unicode(dnszone1_dn), + 'dn': dnszone1_dn, 'idnsname': [dnszone1], 'idnszoneactive': [u'TRUE'], 'idnssoamname': [dnszone1_mname], @@ -200,7 +200,7 @@ class test_dns(Declarative): 'value': dnszone2, 'summary': None, 'result': { - 'dn': unicode(dnszone2_dn), + 'dn': dnszone2_dn, 'idnsname': [dnszone2], 'idnszoneactive': [u'TRUE'], 'idnssoamname': [dnszone2_mname], @@ -240,7 +240,7 @@ class test_dns(Declarative): 'value': dnszone1, 'summary': None, 'result': { - 'dn': unicode(dnszone1_dn), + 'dn': dnszone1_dn, 'idnsname': [dnszone1], 'idnszoneactive': [u'TRUE'], 'nsrecord': [dnszone1_mname], @@ -295,7 +295,7 @@ class test_dns(Declarative): 'value': revdnszone1, 'summary': None, 'result': { - 'dn': unicode(revdnszone1_dn), + 'dn': revdnszone1_dn, 'idnsname': [revdnszone1], 'idnszoneactive': [u'TRUE'], 'idnssoamname': [dnszone1_mname], @@ -325,7 +325,7 @@ class test_dns(Declarative): 'count': 2, 'truncated': False, 'result': [{ - 'dn': unicode(revdnszone1_dn), + 'dn': revdnszone1_dn, 'idnsname': [revdnszone1], 'idnszoneactive': [u'TRUE'], 'nsrecord': [dnszone1_mname], @@ -340,7 +340,7 @@ class test_dns(Declarative): 'idnsallowquery': [u'any;'], }, { - 'dn': unicode(dnszone1_dn), + 'dn': dnszone1_dn, 'idnsname': [dnszone1], 'idnszoneactive': [u'TRUE'], 'nsrecord': [dnszone1_mname], @@ -366,7 +366,7 @@ class test_dns(Declarative): 'count': 1, 'truncated': False, 'result': [{ - 'dn': unicode(dnszone1_dn), + 'dn': dnszone1_dn, 'idnsname': [dnszone1], 'idnszoneactive': [u'TRUE'], 'nsrecord': [dnszone1_mname], @@ -413,7 +413,7 @@ class test_dns(Declarative): 'value': dnszone1, 'summary': None, 'result': { - 'dn': unicode(dnszone1_dn), + 'dn': dnszone1_dn, 'idnsname': [dnszone1], 'idnszoneactive': [u'FALSE'], 'nsrecord': [dnszone1_mname], @@ -449,7 +449,7 @@ class test_dns(Declarative): 'value': dnszone1, 'summary': None, 'result': { - 'dn': unicode(dnszone1_dn), + 'dn': dnszone1_dn, 'idnsname': [dnszone1], 'idnszoneactive': [u'TRUE'], 'nsrecord': [dnszone1_mname], @@ -507,7 +507,7 @@ class test_dns(Declarative): 'value': dnsres1, 'summary': None, 'result': { - 'dn': unicode(dnsres1_dn), + 'dn': dnsres1_dn, 'idnsname': [dnsres1], 'objectclass': objectclasses.dnsrecord, 'arecord': [u'127.0.0.1'], @@ -525,17 +525,17 @@ class test_dns(Declarative): 'truncated': False, 'result': [ { - 'dn': unicode(dnszone1_dn), + 'dn': dnszone1_dn, 'nsrecord': (dnszone1_mname,), 'idnsname': [u'@'], }, { - 'dn': unicode(dnszone1_mname_dn), + 'dn': dnszone1_mname_dn, 'idnsname': [u'ns1'], 'arecord': [u'1.2.3.4'], }, { - 'dn': unicode(dnsres1_dn), + 'dn': dnsres1_dn, 'idnsname': [dnsres1], 'arecord': [u'127.0.0.1'], }, @@ -551,7 +551,7 @@ class test_dns(Declarative): 'value': dnsres1, 'summary': None, 'result': { - 'dn': unicode(dnsres1_dn), + 'dn': dnsres1_dn, 'idnsname': [dnsres1], 'arecord': [u'127.0.0.1', u'10.10.0.1'], 'objectclass': objectclasses.dnsrecord, @@ -633,7 +633,7 @@ class test_dns(Declarative): 'summary': None, 'result': { 'objectclass': objectclasses.dnszone, - 'dn': unicode(dnszone1_dn), + 'dn': dnszone1_dn, 'idnsname': [u'@'], 'mxrecord': [u"0 %s" % dnszone1_mname], 'nsrecord': [dnszone1_mname], @@ -681,7 +681,7 @@ class test_dns(Declarative): 'summary': None, 'result': { 'objectclass': objectclasses.dnsrecord, - 'dn': unicode(DN(('idnsname', u'_foo._tcp'), dnszone1_dn)), + 'dn': DN(('idnsname', u'_foo._tcp'), dnszone1_dn), 'idnsname': [u'_foo._tcp'], 'srvrecord': [u"0 100 1234 %s" % dnszone1_mname], }, @@ -738,7 +738,7 @@ class test_dns(Declarative): 'summary': None, 'result': { 'objectclass': objectclasses.dnszone, - 'dn': unicode(dnszone1_dn), + 'dn': dnszone1_dn, 'idnsname': [u'@'], 'mxrecord': [u"0 %s" % dnszone1_mname], 'nsrecord': [dnszone1_mname], @@ -770,7 +770,7 @@ class test_dns(Declarative): 'summary': None, 'result': { 'objectclass': objectclasses.dnsrecord, - 'dn': unicode(dnsrescname_dn), + 'dn': dnsrescname_dn, 'idnsname': [dnsrescname], 'cnamerecord': [u'foo-1.example.com.'], }, @@ -821,7 +821,7 @@ class test_dns(Declarative): 'summary': None, 'result': { 'objectclass': objectclasses.dnsrecord, - 'dn': unicode(dnsres1_dn), + 'dn': dnsres1_dn, 'idnsname': [dnsres1], 'arecord': [u'10.10.0.1'], 'kxrecord': [u'1 foo-1'], @@ -837,7 +837,7 @@ class test_dns(Declarative): 'summary': None, 'result': { 'objectclass': objectclasses.dnsrecord, - 'dn': unicode(dnsres1_dn), + 'dn': dnsres1_dn, 'idnsname': [dnsres1], 'arecord': [u'10.10.0.1'], 'kxrecord': [u'1 foo-1'], @@ -856,7 +856,7 @@ class test_dns(Declarative): 'summary': None, 'result': { 'objectclass': objectclasses.dnsrecord, - 'dn': unicode(dnsres1_dn), + 'dn': dnsres1_dn, 'idnsname': [dnsres1], 'arecord': [u'10.10.0.1'], 'kxrecord': [u'1 foo-1'], @@ -887,7 +887,7 @@ class test_dns(Declarative): 'summary': None, 'result': { 'objectclass': objectclasses.dnsrecord, - 'dn': unicode(dnsres1_dn), + 'dn': dnsres1_dn, 'idnsname': [dnsres1], 'arecord': [u'10.10.0.1'], 'kxrecord': [u'1 foo-1'], @@ -962,7 +962,7 @@ class test_dns(Declarative): 'value': revdnszone1, 'summary': None, 'result': { - 'dn': unicode(revdnszone1_dn), + 'dn': revdnszone1_dn, 'idnsname': [revdnszone1], 'idnszoneactive': [u'TRUE'], 'idnssoamname': [dnszone1_mname], @@ -1000,7 +1000,7 @@ class test_dns(Declarative): 'summary': None, 'result': { 'objectclass': objectclasses.dnsrecord, - 'dn': unicode(dnsrev1_dn), + 'dn': dnsrev1_dn, 'idnsname': [dnsrev1], 'ptrrecord': [u'foo-1.example.com.'], }, @@ -1015,7 +1015,7 @@ class test_dns(Declarative): 'summary': None, 'result': { 'objectclass': objectclasses.dnsrecord, - 'dn': unicode(dnsrev1_dn), + 'dn': dnsrev1_dn, 'idnsname': [dnsrev1], 'ptrrecord': [u'foo-1.example.com.'], 'cnamerecord': [u'foo-1.example.com.'], @@ -1120,7 +1120,7 @@ class test_dns(Declarative): 'value': dnsres1, 'summary': None, 'result': { - 'dn': unicode(dnsres1_dn), + 'dn': dnsres1_dn, 'idnsname': [dnsres1], 'objectclass': objectclasses.dnsrecord, 'arecord': [u'80.142.15.81'], @@ -1136,7 +1136,7 @@ class test_dns(Declarative): 'value': dnsrev2, 'summary': None, 'result': { - 'dn': unicode(dnsrev2_dn), + 'dn': dnsrev2_dn, 'idnsname': [dnsrev2], 'ptrrecord': [dnsres1 + '.' + dnszone1 + '.'], }, @@ -1183,7 +1183,7 @@ class test_dns(Declarative): value=dnszone1_permission, summary=None, result={ - 'dn': lambda x: DN(x) == dnszone1_permission_dn, + 'dn': dnszone1_permission_dn, 'cn': [dnszone1_permission], 'ipapermissiontype': [u'SYSTEM'], }, @@ -1232,4 +1232,3 @@ class test_dns(Declarative): ), ] - diff --git a/tests/test_xmlrpc/test_group_plugin.py b/tests/test_xmlrpc/test_group_plugin.py index 08cf7418..de4635d3 100644 --- a/tests/test_xmlrpc/test_group_plugin.py +++ b/tests/test_xmlrpc/test_group_plugin.py @@ -24,7 +24,7 @@ Test the `ipalib/plugins/group.py` module. from ipalib import api, errors from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid -from ipalib.dn import * +from ipapython.dn import DN group1 = u'testgroup1' group2 = u'testgroup2' @@ -48,6 +48,7 @@ class test_group(Declarative): ('group_del', [group1], {}), ('group_del', [group2], {}), ('group_del', [group3], {}), + ('group_del', [renamedgroup1], {}), ('user_del', [user1], {}), ] @@ -96,7 +97,7 @@ class test_group(Declarative): description=[u'Test desc 1'], objectclass=objectclasses.group, ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == get_group_dn('testgroup1'), + dn=get_group_dn('testgroup1'), ), ), ), @@ -121,7 +122,7 @@ class test_group(Declarative): result=dict( cn=[group1], description=[u'Test desc 1'], - dn=lambda x: DN(x) == get_group_dn('testgroup1'), + dn=get_group_dn('testgroup1'), ), ), ), @@ -151,7 +152,7 @@ class test_group(Declarative): result=dict( cn=[group1], description=[u'New desc 1'], - dn=lambda x: DN(x) == get_group_dn('testgroup1'), + dn=get_group_dn('testgroup1'), ), summary=None, ), @@ -184,7 +185,7 @@ class test_group(Declarative): result=dict( cn=[group1], description=(u'New desc 1',), - dn=lambda x: DN(x) == get_group_dn('testgroup1'), + dn=get_group_dn('testgroup1'), gidnumber=[fuzzy_digits], ), summary=None, @@ -200,7 +201,7 @@ class test_group(Declarative): truncated=False, result=[ dict( - dn=lambda x: DN(x) == get_group_dn(group1), + dn=get_group_dn(group1), cn=[group1], description=[u'New desc 1'], gidnumber=[fuzzy_digits], @@ -249,7 +250,7 @@ class test_group(Declarative): gidnumber=[fuzzy_digits], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == get_group_dn('testgroup2'), + dn=get_group_dn('testgroup2'), ), ), ), @@ -275,7 +276,7 @@ class test_group(Declarative): cn=[group2], description=[u'Test desc 2'], gidnumber=[fuzzy_digits], - dn=lambda x: DN(x) == get_group_dn('testgroup2'), + dn=get_group_dn('testgroup2'), ), ), ), @@ -307,7 +308,7 @@ class test_group(Declarative): cn=[group2], description=[u'New desc 2'], gidnumber=[fuzzy_digits], - dn=lambda x: DN(x) == get_group_dn('testgroup2'), + dn=get_group_dn('testgroup2'), ), summary=None, ), @@ -322,7 +323,7 @@ class test_group(Declarative): truncated=False, result=[ dict( - dn=lambda x: DN(x) == get_group_dn('testgroup2'), + dn=get_group_dn('testgroup2'), cn=[group2], description=[u'New desc 2'], gidnumber=[fuzzy_digits], @@ -342,37 +343,37 @@ class test_group(Declarative): truncated=False, result=[ { - 'dn': lambda x: DN(x) == get_group_dn('admins'), + 'dn': get_group_dn('admins'), 'member_user': [u'admin'], 'gidnumber': [fuzzy_digits], 'cn': [u'admins'], 'description': [u'Account administrators group'], }, { - 'dn': lambda x: DN(x) == get_group_dn('editors'), + 'dn': get_group_dn('editors'), 'gidnumber': [fuzzy_digits], 'cn': [u'editors'], 'description': [u'Limited admins who can edit other users'], }, { - 'dn': lambda x: DN(x) == get_group_dn('ipausers'), + 'dn': get_group_dn('ipausers'), 'cn': [u'ipausers'], 'description': [u'Default group for all users'], }, dict( - dn=lambda x: DN(x) == get_group_dn(group1), + dn=get_group_dn(group1), cn=[group1], description=[u'New desc 1'], gidnumber=[fuzzy_digits], ), dict( - dn=lambda x: DN(x) == get_group_dn(group2), + dn=get_group_dn(group2), cn=[group2], description=[u'New desc 2'], gidnumber=[fuzzy_digits], ), { - 'dn': lambda x: DN(x) == get_group_dn('trust admins'), + 'dn': get_group_dn('trust admins'), 'member_user': [u'admin'], 'cn': [u'trust admins'], 'description': [u'Trusts administrators group'], @@ -396,7 +397,7 @@ class test_group(Declarative): description=[u'Test desc 3'], objectclass=objectclasses.externalgroup, ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == get_group_dn(group3), + dn=get_group_dn(group3), ), ), ), @@ -456,7 +457,7 @@ class test_group(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == get_group_dn(group1), + 'dn': get_group_dn(group1), 'member_group': (group2,), 'gidnumber': [fuzzy_digits], 'cn': [group1], @@ -480,7 +481,7 @@ class test_group(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == get_group_dn(group1), + 'dn': get_group_dn(group1), 'member_group': (group2,), 'gidnumber': [fuzzy_digits], 'cn': [group1], @@ -503,7 +504,7 @@ class test_group(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == get_group_dn(group1), + 'dn': get_group_dn(group1), 'cn': [group1], 'gidnumber': [fuzzy_digits], 'description': [u'New desc 1'], @@ -526,7 +527,7 @@ class test_group(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == get_group_dn(group1), + 'dn': get_group_dn(group1), 'cn': [group1], 'gidnumber': [fuzzy_digits], 'description': [u'New desc 1'], @@ -691,15 +692,12 @@ class test_group(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [get_group_dn(user1)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[get_group_dn(user1)], memberof_group=[u'ipausers'], - dn=lambda x: DN(x) == \ - DN(('uid',user1),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid',user1),('cn','users'),('cn','accounts'), + api.env.basedn), has_keytab=False, has_password=False, ), @@ -717,7 +715,7 @@ class test_group(Declarative): cn=[user1], description=[u'User private group for %s' % user1], gidnumber=[fuzzy_digits], - dn=lambda x: DN(x) == get_group_dn(user1), + dn=get_group_dn(user1), ), ), ), @@ -731,7 +729,7 @@ class test_group(Declarative): truncated=False, result=[ dict( - dn=lambda x: DN(x) == get_group_dn(user1), + dn=get_group_dn(user1), cn=[user1], description=[u'User private group for %s' % user1], gidnumber=[fuzzy_digits], @@ -810,12 +808,10 @@ class test_group(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, @@ -848,7 +844,7 @@ class test_group(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == get_group_dn('admins'), + 'dn': get_group_dn('admins'), 'member_user': [u'admin', user1], 'gidnumber': [fuzzy_digits], 'cn': [u'admins'], diff --git a/tests/test_xmlrpc/test_hbacsvcgroup_plugin.py b/tests/test_xmlrpc/test_hbacsvcgroup_plugin.py index 1552f46c..591c8a96 100644 --- a/tests/test_xmlrpc/test_hbacsvcgroup_plugin.py +++ b/tests/test_xmlrpc/test_hbacsvcgroup_plugin.py @@ -24,7 +24,7 @@ Test the `ipalib.plugins.hbacsvcgroup` module. from ipalib import api, errors from tests.test_xmlrpc.xmlrpc_test import Declarative, fuzzy_uuid from tests.test_xmlrpc import objectclasses -from ipalib.dn import * +from ipapython.dn import DN hbacsvcgroup1 = u'testhbacsvcgroup1' dn1 = DN(('cn',hbacsvcgroup1),('cn','hbacservicegroups'),('cn','hbac'), @@ -79,7 +79,7 @@ class test_hbacsvcgroup(Declarative): value=hbacsvcgroup1, summary=u'Added HBAC service group "testhbacsvcgroup1"', result=dict( - dn=lambda x: DN(x) == dn1, + dn=dn1, cn=[hbacsvcgroup1], objectclass=objectclasses.hbacsvcgroup, description=[u'Test hbacsvcgroup 1'], @@ -111,7 +111,7 @@ class test_hbacsvcgroup(Declarative): value=hbacsvc1, summary=u'Added HBAC service "%s"' % hbacsvc1, result=dict( - dn=lambda x: DN(x) == hbacsvc_dn1, + dn=hbacsvc_dn1, cn=[hbacsvc1], description=[u'Test service 1'], objectclass=objectclasses.hbacsvc, @@ -134,7 +134,7 @@ class test_hbacsvcgroup(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == dn1, + 'dn': dn1, 'cn': [hbacsvcgroup1], 'description': [u'Test hbacsvcgroup 1'], 'member_hbacsvc': [hbacsvc1], @@ -150,7 +150,7 @@ class test_hbacsvcgroup(Declarative): value=hbacsvcgroup1, summary=None, result={ - 'dn': lambda x: DN(x) == dn1, + 'dn': dn1, 'member_hbacsvc': [hbacsvc1], 'cn': [hbacsvcgroup1], 'description': [u'Test hbacsvcgroup 1'], @@ -168,7 +168,7 @@ class test_hbacsvcgroup(Declarative): summary=u'1 HBAC service group matched', result=[ { - 'dn': lambda x: DN(x) == dn1, + 'dn': dn1, 'member_hbacsvc': [hbacsvc1], 'cn': [hbacsvcgroup1], 'description': [u'Test hbacsvcgroup 1'], @@ -202,7 +202,7 @@ class test_hbacsvcgroup(Declarative): value=hbacsvcgroup1, summary=None, result={ - 'dn': lambda x: DN(x) == dn1, + 'dn': dn1, 'member_hbacsvc': [hbacsvc1], 'cn': [hbacsvcgroup1], 'description': [u'Updated hbacsvcgroup 1'], @@ -224,7 +224,7 @@ class test_hbacsvcgroup(Declarative): ), completed=1, result={ - 'dn': lambda x: DN(x) == dn1, + 'dn': dn1, 'cn': [hbacsvcgroup1], 'description': [u'Updated hbacsvcgroup 1'], }, diff --git a/tests/test_xmlrpc/test_host_plugin.py b/tests/test_xmlrpc/test_host_plugin.py index c9ec6a2b..27d3adb0 100644 --- a/tests/test_xmlrpc/test_host_plugin.py +++ b/tests/test_xmlrpc/test_host_plugin.py @@ -26,7 +26,7 @@ import os import tempfile from ipapython import ipautil from ipalib import api, errors, x509 -from ipalib.dn import * +from ipapython.dn import DN from nose.tools import raises, assert_raises from nose.plugins.skip import Skip, SkipTest from tests.test_xmlrpc.xmlrpc_test import (Declarative, XMLRPC_test, @@ -111,7 +111,7 @@ class test_host(Declarative): value=fqdn1, summary=u'Added host "%s"' % fqdn1, result=dict( - dn=lambda x: DN(x) == dn1, + dn=dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -147,7 +147,7 @@ class test_host(Declarative): value=fqdn1, summary=None, result=dict( - dn=lambda x: DN(x) == dn1, + dn=dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -167,7 +167,7 @@ class test_host(Declarative): value=fqdn1, summary=None, result=dict( - dn=lambda x: DN(x) == dn1, + dn=dn1, cn=[fqdn1], fqdn=[fqdn1], description=[u'Test host 1'], @@ -198,7 +198,7 @@ class test_host(Declarative): summary=u'1 host matched', result=[ dict( - dn=lambda x: DN(x) == dn1, + dn=dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -221,7 +221,7 @@ class test_host(Declarative): summary=u'1 host matched', result=[ dict( - dn=lambda x: DN(x) == dn1, + dn=dn1, cn=[fqdn1], fqdn=[fqdn1], description=[u'Test host 1'], @@ -260,8 +260,7 @@ class test_host(Declarative): usercertificate=[base64.b64decode(servercert)], valid_not_before=fuzzy_date, valid_not_after=fuzzy_date, - subject=lambda x: DN(x) == \ - DN(('CN',api.env.host),x509.subject_base()), + subject=DN(('CN',api.env.host),x509.subject_base()), serial_number=fuzzy_digits, serial_number_hex=fuzzy_hex, md5_fingerprint=fuzzy_hash, @@ -281,7 +280,7 @@ class test_host(Declarative): value=fqdn1, summary=None, result=dict( - dn=lambda x: DN(x) == dn1, + dn=dn1, fqdn=[fqdn1], description=[u'Updated host 1'], l=[u'Undisclosed location 1'], @@ -292,8 +291,7 @@ class test_host(Declarative): usercertificate=[base64.b64decode(servercert)], valid_not_before=fuzzy_date, valid_not_after=fuzzy_date, - subject=lambda x: DN(x) == \ - DN(('CN',api.env.host),x509.subject_base()), + subject=DN(('CN',api.env.host),x509.subject_base()), serial_number=fuzzy_digits, serial_number_hex=fuzzy_hex, md5_fingerprint=fuzzy_hash, @@ -316,7 +314,7 @@ class test_host(Declarative): value=fqdn3, summary=u'Added host "%s"' % fqdn3, result=dict( - dn=lambda x: DN(x) == dn3, + dn=dn3, fqdn=[fqdn3], description=[u'Test host 2'], l=[u'Undisclosed location 2'], @@ -344,7 +342,7 @@ class test_host(Declarative): value=fqdn4, summary=u'Added host "%s"' % fqdn4, result=dict( - dn=lambda x: DN(x) == dn4, + dn=dn4, fqdn=[fqdn4], description=[u'Test host 4'], l=[u'Undisclosed location 4'], @@ -374,7 +372,7 @@ class test_host(Declarative): ), ), result=dict( - dn=lambda x: DN(x) == dn3, + dn=dn3, fqdn=[fqdn3], description=[u'Test host 2'], l=[u'Undisclosed location 2'], @@ -391,7 +389,7 @@ class test_host(Declarative): value=fqdn3, summary=None, result=dict( - dn=lambda x: DN(x) == dn3, + dn=dn3, fqdn=[fqdn3], description=[u'Test host 2'], l=[u'Undisclosed location 2'], @@ -412,7 +410,7 @@ class test_host(Declarative): summary=u'1 host matched', result=[ dict( - dn=lambda x: DN(x) == dn3, + dn=dn3, fqdn=[fqdn3], description=[u'Test host 2'], l=[u'Undisclosed location 2'], @@ -451,7 +449,7 @@ class test_host(Declarative): ), ), result=dict( - dn=lambda x: DN(x) == dn3, + dn=dn3, fqdn=[fqdn3], description=[u'Test host 2'], l=[u'Undisclosed location 2'], @@ -491,8 +489,7 @@ class test_host(Declarative): usercertificate=[base64.b64decode(servercert)], valid_not_before=fuzzy_date, valid_not_after=fuzzy_date, - subject=lambda x: DN(x) == \ - DN(('CN',api.env.host),x509.subject_base()), + subject=DN(('CN',api.env.host),x509.subject_base()), serial_number=fuzzy_digits, serial_number_hex=fuzzy_hex, md5_fingerprint=fuzzy_hash, @@ -521,8 +518,7 @@ class test_host(Declarative): usercertificate=[base64.b64decode(servercert)], valid_not_before=fuzzy_date, valid_not_after=fuzzy_date, - subject=lambda x: DN(x) == \ - DN(('CN',api.env.host),x509.subject_base()), + subject=DN(('CN',api.env.host),x509.subject_base()), serial_number=fuzzy_digits, serial_number_hex=fuzzy_hex, md5_fingerprint=fuzzy_hash, @@ -591,7 +587,7 @@ class test_host(Declarative): value=fqdn1, summary=u'Added host "%s"' % fqdn1, result=dict( - dn=lambda x: DN(x) == dn1, + dn=dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -612,7 +608,7 @@ class test_host(Declarative): value=service1, summary=u'Added service "%s"' % service1, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], objectclass=objectclasses.service, managedby_host=[fqdn1], @@ -666,7 +662,7 @@ class test_host(Declarative): value=fqdn2, summary=u'Added host "%s"' % fqdn2, result=dict( - dn=lambda x: DN(x) == dn2, + dn=dn2, fqdn=[fqdn2], description=[u'Test host 2'], l=[u'Undisclosed location 2'], diff --git a/tests/test_xmlrpc/test_hostgroup_plugin.py b/tests/test_xmlrpc/test_hostgroup_plugin.py index 5642b109..36c497ba 100644 --- a/tests/test_xmlrpc/test_hostgroup_plugin.py +++ b/tests/test_xmlrpc/test_hostgroup_plugin.py @@ -23,10 +23,9 @@ Test the `ipalib.plugins.hostgroup` module. """ from ipalib import api, errors -from ipalib.dn import * from tests.test_xmlrpc.xmlrpc_test import Declarative, fuzzy_uuid from tests.test_xmlrpc import objectclasses -from ipalib.dn import * +from ipapython.dn import DN hostgroup1 = u'testhostgroup1' dn1 = DN(('cn',hostgroup1),('cn','hostgroups'),('cn','accounts'), @@ -95,14 +94,13 @@ class test_hostgroup(Declarative): value=hostgroup1, summary=u'Added hostgroup "testhostgroup1"', result=dict( - dn=lambda x: DN(x) == dn1, + dn=dn1, cn=[hostgroup1], objectclass=objectclasses.hostgroup, description=[u'Test hostgroup 1'], ipauniqueid=[fuzzy_uuid], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',hostgroup1),('cn','ng'),('cn','alt'), - api.env.basedn)], + mepmanagedentry=[DN(('cn',hostgroup1),('cn','ng'),('cn','alt'), + api.env.basedn)], ), ), ), @@ -131,7 +129,7 @@ class test_hostgroup(Declarative): value=fqdn1, summary=u'Added host "%s"' % fqdn1, result=dict( - dn=lambda x: DN(x) == host_dn1, + dn=host_dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -160,7 +158,7 @@ class test_hostgroup(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == dn1, + 'dn': dn1, 'cn': [hostgroup1], 'description': [u'Test hostgroup 1'], 'member_host': [fqdn1], @@ -176,7 +174,7 @@ class test_hostgroup(Declarative): value=hostgroup1, summary=None, result={ - 'dn': lambda x: DN(x) == dn1, + 'dn': dn1, 'member_host': [u'testhost1.%s' % api.env.domain], 'cn': [hostgroup1], 'description': [u'Test hostgroup 1'], @@ -194,7 +192,7 @@ class test_hostgroup(Declarative): summary=u'1 hostgroup matched', result=[ { - 'dn': lambda x: DN(x) == dn1, + 'dn': dn1, 'member_host': [u'testhost1.%s' % api.env.domain], 'cn': [hostgroup1], 'description': [u'Test hostgroup 1'], @@ -228,7 +226,7 @@ class test_hostgroup(Declarative): value=hostgroup1, summary=None, result={ - 'dn': lambda x: DN(x) == dn1, + 'dn': dn1, 'member_host': [u'testhost1.%s' % api.env.domain], 'cn': [hostgroup1], 'description': [u'Updated hostgroup 1'], @@ -251,7 +249,7 @@ class test_hostgroup(Declarative): ), completed=1, result={ - 'dn': lambda x: DN(x) == dn1, + 'dn': dn1, 'cn': [hostgroup1], 'description': [u'Updated hostgroup 1'], }, @@ -279,14 +277,13 @@ class test_hostgroup(Declarative): value=hostgroup_single, summary=u'Added hostgroup "a"', result=dict( - dn=lambda x: DN(x) == dn_single, + dn=dn_single, cn=[hostgroup_single], objectclass=objectclasses.hostgroup, description=[u'Test hostgroup with single letter in name'], ipauniqueid=[fuzzy_uuid], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',hostgroup_single),('cn','ng'),('cn','alt'), - api.env.basedn)], + mepmanagedentry=[DN(('cn',hostgroup_single),('cn','ng'),('cn','alt'), + api.env.basedn)], ), ), ), diff --git a/tests/test_xmlrpc/test_krbtpolicy.py b/tests/test_xmlrpc/test_krbtpolicy.py index 26ba87c4..fc2bf54c 100644 --- a/tests/test_xmlrpc/test_krbtpolicy.py +++ b/tests/test_xmlrpc/test_krbtpolicy.py @@ -23,7 +23,7 @@ Test kerberos ticket policy from ipalib import api, errors from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid -from ipalib.dn import * +from ipapython.dn import DN user1 = u'tuser1' @@ -61,9 +61,8 @@ class test_krbtpolicy(Declarative): value=u'', summary=None, result=dict( - dn=lambda x: DN(x) == \ - DN(('cn',api.env.domain),('cn','kerberos'), - api.env.basedn), + dn=DN(('cn',api.env.domain),('cn','kerberos'), + api.env.basedn), krbmaxticketlife=[u'86400'], krbmaxrenewableage=[u'604800'], ), @@ -110,18 +109,14 @@ class test_krbtpolicy(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid',user1),('cn','users'),('cn','accounts'), - api.env.basedn) + dn=DN(('uid',user1),('cn','users'),('cn','accounts'), api.env.basedn) ), ), ), diff --git a/tests/test_xmlrpc/test_nesting.py b/tests/test_xmlrpc/test_nesting.py index a855960a..c28b7096 100644 --- a/tests/test_xmlrpc/test_nesting.py +++ b/tests/test_xmlrpc/test_nesting.py @@ -23,7 +23,7 @@ Test group nexting an indirect members from ipalib import api, errors from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid -from ipalib.dn import * +from ipapython.dn import DN group1 = u'testgroup1' group2 = u'testgroup2' @@ -80,9 +80,8 @@ class test_nesting(Declarative): objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], gidnumber=[fuzzy_digits], - dn=lambda x: DN(x) == \ - DN(('cn','testgroup1'),('cn','groups'), - ('cn','accounts'),api.env.basedn), + dn=DN(('cn','testgroup1'),('cn','groups'), + ('cn','accounts'),api.env.basedn), ), ), ), @@ -104,9 +103,8 @@ class test_nesting(Declarative): gidnumber=[fuzzy_digits], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == \ - DN(('cn','testgroup2'),('cn','groups'), - ('cn','accounts'),api.env.basedn), + dn=DN(('cn','testgroup2'),('cn','groups'), + ('cn','accounts'),api.env.basedn), ), ), ), @@ -126,9 +124,8 @@ class test_nesting(Declarative): gidnumber=[fuzzy_digits], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == \ - DN(('cn','testgroup3'),('cn','groups'), - ('cn','accounts'),api.env.basedn), + dn=DN(('cn','testgroup3'),('cn','groups'), + ('cn','accounts'),api.env.basedn), ), ), ), @@ -148,9 +145,8 @@ class test_nesting(Declarative): gidnumber=[fuzzy_digits], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == \ - DN(('cn','testgroup4'),('cn','groups'), - ('cn','accounts'),api.env.basedn), + dn=DN(('cn','testgroup4'),('cn','groups'), + ('cn','accounts'),api.env.basedn), ), ), ), @@ -179,18 +175,15 @@ class test_nesting(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid',user1),('cn','users'),('cn','accounts'), - api.env.basedn) + dn=DN(('uid',user1),('cn','users'),('cn','accounts'), + api.env.basedn) ), ), ), @@ -219,18 +212,15 @@ class test_nesting(Declarative): cn=[u'Test User2'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user2),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user2),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid',user2),('cn','users'),('cn','accounts'), - api.env.basedn) + dn=DN(('uid',user2),('cn','users'),('cn','accounts'), + api.env.basedn) ), ), ), @@ -259,18 +249,15 @@ class test_nesting(Declarative): cn=[u'Test User3'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user3),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user3),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid',user3),('cn','users'),('cn','accounts'), - api.env.basedn) + dn=DN(('uid',user3),('cn','users'),('cn','accounts'), + api.env.basedn) ), ), ), @@ -299,18 +286,15 @@ class test_nesting(Declarative): cn=[u'Test User4'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user4),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user4),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid',user4),('cn','users'),('cn','accounts'), - api.env.basedn) + dn=DN(('uid',user4),('cn','users'),('cn','accounts'), + api.env.basedn) ), ), ), @@ -375,9 +359,8 @@ class test_nesting(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',group1),('cn','groups'),('cn','accounts'), - api.env.basedn), + 'dn': DN(('cn',group1),('cn','groups'),('cn','accounts'), + api.env.basedn), 'member_group': (group2,), 'gidnumber': [fuzzy_digits], 'cn': [group1], @@ -401,9 +384,8 @@ class test_nesting(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',group1),('cn','groups'),('cn','accounts'), - api.env.basedn), + 'dn': DN(('cn',group1),('cn','groups'),('cn','accounts'), + api.env.basedn), 'member_group': [group2, group3,], 'gidnumber': [fuzzy_digits], 'cn': [group1], @@ -427,9 +409,8 @@ class test_nesting(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',group2),('cn','groups'),('cn','accounts'), - api.env.basedn), + 'dn': DN(('cn',group2),('cn','groups'),('cn','accounts'), + api.env.basedn), 'member_user': (u'tuser1',), 'memberof_group': (u'testgroup1',), 'gidnumber': [fuzzy_digits], @@ -454,9 +435,8 @@ class test_nesting(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',group2),('cn','groups'),('cn','accounts'), - api.env.basedn), + 'dn': DN(('cn',group2),('cn','groups'),('cn','accounts'), + api.env.basedn), 'member_user': [user1, user2], 'memberof_group': [group1], 'gidnumber': [fuzzy_digits], @@ -481,9 +461,8 @@ class test_nesting(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',group3),('cn','groups'),('cn','accounts'), - api.env.basedn), + 'dn': DN(('cn',group3),('cn','groups'),('cn','accounts'), + api.env.basedn), 'member_user': [user3], 'memberof_group': [group1], 'gidnumber': [fuzzy_digits], @@ -508,9 +487,8 @@ class test_nesting(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',group3),('cn','groups'),('cn','accounts'), - api.env.basedn), + 'dn': DN(('cn',group3),('cn','groups'),('cn','accounts'), + api.env.basedn), 'member_user': [user3], 'memberof_group': [group1], 'member_group': [group4], @@ -536,9 +514,8 @@ class test_nesting(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',group4),('cn','groups'),('cn','accounts'), - api.env.basedn), + 'dn': DN(('cn',group4),('cn','groups'),('cn','accounts'), + api.env.basedn), 'member_user': [user1], 'memberof_group': [group3], 'memberofindirect_group': [group1], @@ -564,9 +541,8 @@ class test_nesting(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',group4),('cn','groups'),('cn','accounts'), - api.env.basedn), + 'dn': DN(('cn',group4),('cn','groups'),('cn','accounts'), + api.env.basedn), 'member_user': [user1, user4], 'memberof_group': [group3], 'memberofindirect_group': [group1], @@ -591,9 +567,8 @@ class test_nesting(Declarative): memberindirect_group = [group4], member_group = [group2, group3], memberindirect_user = [user1, user2, user3, user4], - dn=lambda x: DN(x) == \ - DN(('cn','testgroup1'),('cn','groups'), - ('cn','accounts'),api.env.basedn), + dn=DN(('cn','testgroup1'),('cn','groups'), + ('cn','accounts'),api.env.basedn), ), ), ), @@ -611,9 +586,8 @@ class test_nesting(Declarative): gidnumber= [fuzzy_digits], memberof_group = [group1], member_user = [user1, user2], - dn=lambda x: DN(x) == \ - DN(('cn','testgroup2'),('cn','groups'), - ('cn','accounts'),api.env.basedn), + dn=DN(('cn','testgroup2'),('cn','groups'), + ('cn','accounts'),api.env.basedn), ), ), ), @@ -633,9 +607,8 @@ class test_nesting(Declarative): member_user = [user3], member_group = [group4], memberindirect_user = [user1, user4], - dn=lambda x: DN(x) == \ - DN(('cn','testgroup3'),('cn','groups'), - ('cn','accounts'),api.env.basedn), + dn=DN(('cn','testgroup3'),('cn','groups'), + ('cn','accounts'),api.env.basedn), ), ), ), @@ -654,9 +627,8 @@ class test_nesting(Declarative): memberof_group = [group3], member_user = [user1, user4], memberofindirect_group = [group1], - dn=lambda x: DN(x) == \ - DN(('cn','testgroup4'),('cn','groups'), - ('cn','accounts'),api.env.basedn), + dn=DN(('cn','testgroup4'),('cn','groups'), + ('cn','accounts'),api.env.basedn), ), ), ), @@ -676,7 +648,7 @@ class test_nesting(Declarative): value=fqdn1, summary=u'Added host "%s"' % fqdn1, result=dict( - dn=lambda x: DN(x) == host_dn1, + dn=host_dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -700,14 +672,13 @@ class test_nesting(Declarative): value=hostgroup1, summary=u'Added hostgroup "testhostgroup1"', result=dict( - dn=lambda x: DN(x) == hgdn1, + dn=hgdn1, cn=[hostgroup1], objectclass=objectclasses.hostgroup, description=[u'Test hostgroup 1'], ipauniqueid=[fuzzy_uuid], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',hostgroup1),('cn','ng'),('cn','alt'), - api.env.basedn)], + mepmanagedentry=[DN(('cn',hostgroup1),('cn','ng'),('cn','alt'), + api.env.basedn)], ), ), ), @@ -722,14 +693,13 @@ class test_nesting(Declarative): value=hostgroup2, summary=u'Added hostgroup "testhostgroup2"', result=dict( - dn=lambda x: DN(x) == hgdn2, + dn=hgdn2, cn=[hostgroup2], objectclass=objectclasses.hostgroup, description=[u'Test hostgroup 2'], ipauniqueid=[fuzzy_uuid], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',hostgroup2),('cn','ng'),('cn','alt'), - api.env.basedn)], + mepmanagedentry=[DN(('cn',hostgroup2),('cn','ng'),('cn','alt'), + api.env.basedn)], ), ), ), @@ -749,7 +719,7 @@ class test_nesting(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == hgdn2, + 'dn': hgdn2, 'cn': [hostgroup2], 'description': [u'Test hostgroup 2'], 'member_host': [fqdn1], @@ -772,7 +742,7 @@ class test_nesting(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == hgdn1, + 'dn': hgdn1, 'cn': [hostgroup1], 'description': [u'Test hostgroup 1'], 'member_hostgroup': [hostgroup2], @@ -788,7 +758,7 @@ class test_nesting(Declarative): value=hostgroup1, summary=None, result={ - 'dn': lambda x: DN(x) == hgdn1, + 'dn': hgdn1, 'memberindirect_host': [u'testhost1.%s' % api.env.domain], 'member_hostgroup': [hostgroup2], 'cn': [hostgroup1], @@ -805,7 +775,7 @@ class test_nesting(Declarative): value=fqdn1, summary=None, result=dict( - dn=lambda x: DN(x) == host_dn1, + dn=host_dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], diff --git a/tests/test_xmlrpc/test_netgroup_plugin.py b/tests/test_xmlrpc/test_netgroup_plugin.py index 951bc77a..b54291a6 100644 --- a/tests/test_xmlrpc/test_netgroup_plugin.py +++ b/tests/test_xmlrpc/test_netgroup_plugin.py @@ -28,7 +28,7 @@ from ipalib import errors from ipaserver.plugins.ldap2 import ldap2 from tests.test_xmlrpc.xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid, fuzzy_netgroupdn from tests.test_xmlrpc import objectclasses -from ipalib.dn import * +from ipapython.dn import DN # Global so we can save the value between tests netgroup_dn = None @@ -142,7 +142,6 @@ class test_netgroup(Declarative): value=netgroup1, summary=u'Added netgroup "%s"' % netgroup1, result=dict( -# dn=u'ipauniqueid=%s,cn=ng,cn=alt,%s' % (fuzzy_uuid, api.env.basedn), dn=fuzzy_netgroupdn, cn=[netgroup1], objectclass=objectclasses.netgroup, @@ -163,7 +162,6 @@ class test_netgroup(Declarative): value=netgroup2, summary=u'Added netgroup "%s"' % netgroup2, result=dict( -# dn=u'ipauniqueid=%s,cn=ng,cn=alt,%s' % (fuzzy_uuid, api.env.basedn), dn=fuzzy_netgroupdn, cn=[netgroup2], objectclass=objectclasses.netgroup, @@ -229,7 +227,7 @@ class test_netgroup(Declarative): value=host1, summary=u'Added host "%s"' % host1, result=dict( - dn=lambda x: DN(x) == host_dn1, + dn=host_dn1, fqdn=[host1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -253,13 +251,12 @@ class test_netgroup(Declarative): value=hostgroup1, summary=u'Added hostgroup "%s"' % hostgroup1, result=dict( - dn=lambda x: DN(x) == hostgroup_dn1, + dn=hostgroup_dn1, cn=[hostgroup1], objectclass=objectclasses.hostgroup, description=[u'Test hostgroup 1'], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',hostgroup1),('cn','ng'),('cn','alt'), - api.env.basedn)], + mepmanagedentry=[DN(('cn',hostgroup1),('cn','ng'),('cn','alt'), + api.env.basedn)], ipauniqueid=[fuzzy_uuid], ), ), @@ -289,18 +286,15 @@ class test_netgroup(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid',user1),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid',user1),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -328,18 +322,15 @@ class test_netgroup(Declarative): cn=[u'Test User2'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user2),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user2),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid',user2),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid',user2),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -359,9 +350,8 @@ class test_netgroup(Declarative): gidnumber=[fuzzy_digits], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == \ - DN(('cn',group1),('cn','groups'),('cn','accounts'), - api.env.basedn), + dn=DN(('cn',group1),('cn','groups'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -381,9 +371,8 @@ class test_netgroup(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',group1),('cn','groups'),('cn','accounts'), - api.env.basedn), + 'dn': DN(('cn',group1),('cn','groups'),('cn','accounts'), + api.env.basedn), 'member_user': (user2,), 'gidnumber': [fuzzy_digits], 'cn': [group1], diff --git a/tests/test_xmlrpc/test_permission_plugin.py b/tests/test_xmlrpc/test_permission_plugin.py index 8aaa4a99..a1062f08 100644 --- a/tests/test_xmlrpc/test_permission_plugin.py +++ b/tests/test_xmlrpc/test_permission_plugin.py @@ -25,7 +25,7 @@ Test the `ipalib/plugins/permission.py` module. from ipalib import api, errors from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid -from ipalib.dn import * +from ipapython.dn import DN permission1 = u'testperm' permission1_dn = DN(('cn',permission1), @@ -110,7 +110,7 @@ class test_permission(Declarative): value=permission1, summary=u'Added permission "%s"' % permission1, result=dict( - dn=lambda x: DN(x) == permission1_dn, + dn=permission1_dn, cn=[permission1], objectclass=objectclasses.permission, type=u'user', @@ -141,7 +141,7 @@ class test_permission(Declarative): value=privilege1, summary=u'Added privilege "%s"' % privilege1, result=dict( - dn=lambda x: DN(x) == privilege1_dn, + dn=privilege1_dn, cn=[privilege1], description=[u'privilege desc. 1'], objectclass=objectclasses.privilege, @@ -163,7 +163,7 @@ class test_permission(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'privilege desc. 1'], 'memberof_permission': [permission1], @@ -179,7 +179,7 @@ class test_permission(Declarative): value=permission1, summary=None, result={ - 'dn': lambda x: DN(x) == permission1_dn, + 'dn': permission1_dn, 'cn': [permission1], 'member_privilege': [privilege1], 'type': u'user', @@ -196,11 +196,12 @@ class test_permission(Declarative): value=permission1, summary=None, result={ - 'dn': unicode(permission1_dn), + 'dn': permission1_dn, 'cn': [permission1], - 'member': [unicode(privilege1_dn)], - 'aci': u'(target = "ldap:///uid=*,cn=users,cn=accounts,%s")(version 3.0;acl "permission:testperm";allow (write) groupdn = "ldap:///cn=testperm,cn=permissions,cn=pbac,%s";)' \ - % (api.env.basedn, api.env.basedn), + 'member': [privilege1_dn], + 'aci': u'(target = "ldap:///%s")(version 3.0;acl "permission:testperm";allow (write) groupdn = "ldap:///%s";)' % \ + (DN(('uid', '*'), ('cn', 'users'), ('cn', 'accounts'), api.env.basedn), + DN(('cn', 'testperm'), ('cn', 'permissions'), ('cn', 'pbac'), api.env.basedn)) }, ), ), @@ -215,7 +216,7 @@ class test_permission(Declarative): summary=u'1 permission matched', result=[ { - 'dn': lambda x: DN(x) == permission1_dn, + 'dn': permission1_dn, 'cn': [permission1], 'member_privilege': [privilege1], 'type': u'user', @@ -235,7 +236,7 @@ class test_permission(Declarative): summary=u'1 permission matched', result=[ { - 'dn': lambda x: DN(x) == permission1_dn, + 'dn': permission1_dn, 'cn': [permission1], 'member_privilege': [privilege1], 'type': u'user', @@ -267,7 +268,7 @@ class test_permission(Declarative): summary=u'1 permission matched', result=[ { - 'dn': lambda x: DN(x) == permission1_dn, + 'dn': permission1_dn, 'cn': [permission1], 'member_privilege': [privilege1], 'type': u'user', @@ -287,11 +288,12 @@ class test_permission(Declarative): summary=u'1 permission matched', result=[ { - 'dn': unicode(permission1_dn), + 'dn': permission1_dn, 'cn': [permission1], - 'member': [unicode(privilege1_dn)], - 'aci': u'(target = "ldap:///uid=*,cn=users,cn=accounts,%s")(version 3.0;acl "permission:testperm";allow (write) groupdn = "ldap:///cn=testperm,cn=permissions,cn=pbac,%s";)' \ - % (api.env.basedn, api.env.basedn), + 'member': [privilege1_dn], + 'aci': u'(target = "ldap:///%s")(version 3.0;acl "permission:testperm";allow (write) groupdn = "ldap:///%s";)' % \ + (DN(('uid', '*'), ('cn', 'users'), ('cn', 'accounts'), api.env.basedn), + DN(('cn', 'testperm'), ('cn', 'permissions'), ('cn', 'pbac'), api.env.basedn)), }, ], ), @@ -312,7 +314,7 @@ class test_permission(Declarative): value=permission2, summary=u'Added permission "%s"' % permission2, result=dict( - dn=lambda x: DN(x) == permission2_dn, + dn=permission2_dn, cn=[permission2], objectclass=objectclasses.permission, type=u'user', @@ -332,14 +334,14 @@ class test_permission(Declarative): summary=u'2 permissions matched', result=[ { - 'dn': lambda x: DN(x) == permission1_dn, + 'dn': permission1_dn, 'cn': [permission1], 'member_privilege': [privilege1], 'type': u'user', 'permissions': [u'write'], }, { - 'dn': lambda x: DN(x) == permission2_dn, + 'dn': permission2_dn, 'cn': [permission2], 'type': u'user', 'permissions': [u'write'], @@ -358,11 +360,11 @@ class test_permission(Declarative): summary=u'2 permissions matched', result=[ { - 'dn': lambda x: DN(x) == permission1_dn, + 'dn': permission1_dn, 'cn': [permission1], }, { - 'dn': lambda x: DN(x) == permission2_dn, + 'dn': permission2_dn, 'cn': [permission2], }, ], @@ -380,8 +382,8 @@ class test_permission(Declarative): summary=u'1 permission matched', result=[ { - 'dn': lambda x: DN(x) == DN(('cn','Modify Group Password Policy'), - api.env.container_permission,api.env.basedn), + 'dn': DN(('cn','Modify Group Password Policy'), + api.env.container_permission, api.env.basedn), 'cn': [u'Modify Group Password Policy'], }, ], @@ -398,7 +400,7 @@ class test_permission(Declarative): summary=u'1 privilege matched', result=[ { - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'privilege desc. 1'], 'memberof_permission': [permission1], @@ -417,7 +419,7 @@ class test_permission(Declarative): summary=u'1 permission matched', result=[ { - 'dn': lambda x: DN(x) == permission1_dn, + 'dn': permission1_dn, 'cn': [permission1], 'member_privilege': [privilege1], 'type': u'user', @@ -437,14 +439,14 @@ class test_permission(Declarative): summary=u'2 permissions matched', result=[ { - 'dn': lambda x: DN(x) == permission1_dn, + 'dn': permission1_dn, 'cn': [permission1], 'member_privilege': [privilege1], 'type': u'user', 'permissions': [u'write'], }, { - 'dn': lambda x: DN(x) == permission2_dn, + 'dn': permission2_dn, 'cn': [permission2], 'type': u'user', 'permissions': [u'write'], @@ -468,14 +470,14 @@ class test_permission(Declarative): summary=u'1 permission matched', result=[ { - 'dn': lambda x: DN(x) == DN(('cn', 'Modify HBAC rule'), - api.env.container_permission,api.env.basedn), + 'dn': DN(('cn', 'Modify HBAC rule'), + api.env.container_permission, api.env.basedn), 'cn': [u'Modify HBAC rule'], 'member_privilege': [u'HBAC Administrator'], 'permissions' : [u'write'], 'attrs': [u'servicecategory', u'sourcehostcategory', u'cn', u'description', u'ipaenabledflag', u'accesstime', u'usercategory', u'hostcategory', u'accessruletype', u'sourcehost'], - 'subtree' : u'ldap:///ipauniqueid=*,cn=hbac,%s' % api.env.basedn, - 'memberindirect': [u'cn=hbac administrator,cn=privileges,cn=pbac,%s' % api.env.basedn, u'cn=it security specialist,cn=roles,cn=accounts,%s' % api.env.basedn], + 'subtree' : u'ldap:///%s' % DN(('ipauniqueid', '*'), ('cn', 'hbac'), api.env.basedn), + 'memberindirect': [DN(('cn', 'it security specialist'), ('cn', 'roles'), ('cn', 'accounts'), api.env.basedn)], }, ], ), @@ -496,7 +498,7 @@ class test_permission(Declarative): value=permission1, summary=u'Modified permission "%s"' % permission1, result=dict( - dn=lambda x: DN(x) == permission1_dn, + dn=permission1_dn, cn=[permission1], member_privilege=[privilege1], type=u'user', @@ -515,7 +517,7 @@ class test_permission(Declarative): value=permission1, summary=None, result={ - 'dn': lambda x: DN(x) == permission1_dn, + 'dn': permission1_dn, 'cn': [permission1], 'member_privilege': [privilege1], 'type': u'user', @@ -556,7 +558,7 @@ class test_permission(Declarative): value=permission1, summary=None, result={ - 'dn': lambda x: DN(x) == permission1_dn, + 'dn': permission1_dn, 'cn': [permission1], 'member_privilege': [privilege1], 'type': u'user', @@ -578,7 +580,7 @@ class test_permission(Declarative): value=permission1, summary=u'Modified permission "%s"' % permission1, result={ - 'dn': lambda x: DN(x) == permission1_renamed_dn, + 'dn': permission1_renamed_dn, 'cn': [permission1_renamed], 'member_privilege': [privilege1], 'type': u'user', @@ -600,7 +602,7 @@ class test_permission(Declarative): value=permission1_renamed, summary=u'Modified permission "%s"' % permission1_renamed, result={ - 'dn': lambda x: DN(x) == permission1_renamed_ucase_dn, + 'dn': permission1_renamed_ucase_dn, 'cn': [permission1_renamed_ucase], 'member_privilege': [privilege1], 'type': u'user', @@ -614,16 +616,18 @@ class test_permission(Declarative): dict( desc='Change %r to a subtree type' % permission1_renamed_ucase, command=( - 'permission_mod', [permission1_renamed_ucase], dict(subtree=u'ldap:///cn=*,cn=test,cn=accounts,%s' % api.env.basedn, type=None) + 'permission_mod', [permission1_renamed_ucase], + dict(subtree=u'ldap:///%s' % DN(('cn', '*'), ('cn', 'test'), ('cn', 'accounts'), api.env.basedn), + type=None) ), expected=dict( value=permission1_renamed_ucase, summary=u'Modified permission "%s"' % permission1_renamed_ucase, result=dict( - dn=lambda x: DN(x) == permission1_renamed_ucase_dn, + dn=permission1_renamed_ucase_dn, cn=[permission1_renamed_ucase], member_privilege=[privilege1], - subtree=u'ldap:///cn=*,cn=test,cn=accounts,%s' % api.env.basedn, + subtree=u'ldap:///%s' % DN(('cn', '*'), ('cn', 'test'), ('cn', 'accounts'), api.env.basedn), permissions=[u'write'], memberof=u'ipausers', ), @@ -633,17 +637,18 @@ class test_permission(Declarative): dict( desc='Search for %r using --subtree' % permission1, - command=('permission_find', [], {'subtree': 'ldap:///cn=*,cn=test,cn=accounts,%s' % api.env.basedn}), + command=('permission_find', [], + {'subtree': u'ldap:///%s' % DN(('cn', '*'), ('cn', 'test'), ('cn', 'accounts'), api.env.basedn)}), expected=dict( count=1, truncated=False, summary=u'1 permission matched', result=[ { - 'dn':lambda x: DN(x) == permission1_renamed_ucase_dn, + 'dn':permission1_renamed_ucase_dn, 'cn':[permission1_renamed_ucase], 'member_privilege':[privilege1], - 'subtree':u'ldap:///cn=*,cn=test,cn=accounts,%s' % api.env.basedn, + 'subtree':u'ldap:///%s' % DN(('cn', '*'), ('cn', 'test'), ('cn', 'accounts'), api.env.basedn), 'permissions':[u'write'], 'memberof':u'ipausers', }, @@ -756,7 +761,7 @@ class test_permission(Declarative): value=permission1, summary=u'Added permission "%s"' % permission1, result=dict( - dn=lambda x: DN(x) == permission1_dn, + dn=permission1_dn, cn=[permission1], objectclass=objectclasses.permission, memberof=u'editors', @@ -784,7 +789,7 @@ class test_permission(Declarative): value=permission1, summary=u'Modified permission "%s"' % permission1, result=dict( - dn=lambda x: DN(x) == permission1_dn, + dn=permission1_dn, cn=[permission1], memberof=u'admins', permissions=[u'write'], @@ -804,7 +809,7 @@ class test_permission(Declarative): summary=u'Modified permission "%s"' % permission1, value=permission1, result=dict( - dn=lambda x: DN(x) == permission1_dn, + dn=permission1_dn, cn=[permission1], permissions=[u'write'], type=u'user', @@ -836,7 +841,7 @@ class test_permission(Declarative): value=permission1, summary=u'Added permission "%s"' % permission1, result=dict( - dn=lambda x: DN(x) == permission1_dn, + dn=permission1_dn, cn=[permission1], objectclass=objectclasses.permission, targetgroup=u'editors', diff --git a/tests/test_xmlrpc/test_privilege_plugin.py b/tests/test_xmlrpc/test_privilege_plugin.py index d8d9b22a..d4784af8 100644 --- a/tests/test_xmlrpc/test_privilege_plugin.py +++ b/tests/test_xmlrpc/test_privilege_plugin.py @@ -24,7 +24,7 @@ Test the `ipalib/plugins/privilege.py` module. from ipalib import api, errors from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid -from ipalib.dn import * +from ipapython.dn import DN permission1 = u'testperm' permission1_dn = DN(('cn',permission1), @@ -97,7 +97,7 @@ class test_privilege(Declarative): value=permission1, summary=u'Added permission "%s"' % permission1, result=dict( - dn=lambda x: DN(x) == permission1_dn, + dn=permission1_dn, cn=[permission1], objectclass=objectclasses.permission, type=u'user', @@ -116,7 +116,7 @@ class test_privilege(Declarative): value=privilege1, summary=u'Added privilege "%s"' % privilege1, result=dict( - dn=lambda x: DN(x) == privilege1_dn, + dn=privilege1_dn, cn=[privilege1], description=[u'privilege desc. 1'], objectclass=objectclasses.privilege, @@ -138,7 +138,7 @@ class test_privilege(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'privilege desc. 1'], 'memberof_permission': [permission1], @@ -154,7 +154,7 @@ class test_privilege(Declarative): value=privilege1, summary=None, result={ - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'privilege desc. 1'], 'memberof_permission': [permission1], @@ -172,7 +172,7 @@ class test_privilege(Declarative): summary=u'1 privilege matched', result=[ { - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'privilege desc. 1'], 'memberof_permission': [permission1], @@ -191,7 +191,7 @@ class test_privilege(Declarative): summary=u'1 privilege matched', result=[ { - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'privilege desc. 1'], 'memberof_permission': [permission1], @@ -213,7 +213,7 @@ class test_privilege(Declarative): value=permission2, summary=u'Added permission "%s"' % permission2, result=dict( - dn=lambda x: DN(x) == permission2_dn, + dn=permission2_dn, cn=[permission2], objectclass=objectclasses.permission, type=u'user', @@ -236,7 +236,7 @@ class test_privilege(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'privilege desc. 1'], 'memberof_permission': [permission1, permission2], @@ -258,7 +258,7 @@ class test_privilege(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'privilege desc. 1'], 'memberof_permission': [permission1, permission2], @@ -276,7 +276,7 @@ class test_privilege(Declarative): summary=u'1 privilege matched', result=[ { - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'privilege desc. 1'], 'memberof_permission': [permission1, permission2], @@ -316,7 +316,7 @@ class test_privilege(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'New desc 1'], 'memberof_permission': [permission2], @@ -338,7 +338,7 @@ class test_privilege(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'New desc 1'], 'memberof_permission': [permission2], @@ -360,7 +360,7 @@ class test_privilege(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'New desc 1'], 'memberof_permission': [permission2], @@ -382,7 +382,7 @@ class test_privilege(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == privilege1_dn, + 'dn': privilege1_dn, 'cn': [privilege1], 'description': [u'New desc 1'], 'memberof_permission': [permission2], diff --git a/tests/test_xmlrpc/test_range_plugin.py b/tests/test_xmlrpc/test_range_plugin.py index 76ffc58b..ea4bc2b2 100644 --- a/tests/test_xmlrpc/test_range_plugin.py +++ b/tests/test_xmlrpc/test_range_plugin.py @@ -24,7 +24,7 @@ Test the `ipalib/plugins/range.py` module, and XML-RPC in general. from ipalib import api, errors, _ from tests.util import assert_equal, Fuzzy from xmlrpc_test import Declarative -from ipalib.dn import * +from ipapython.dn import * testrange1 = u't-range-1' @@ -41,9 +41,8 @@ class test_range(Declarative): ipabaserid=1000, ipasecondarybaserid=20000)), expected=dict( result=dict( - dn=lambda x: DN(x) == \ - DN(('cn',testrange1),('cn','ranges'),('cn','etc'), - api.env.basedn), + dn=DN(('cn',testrange1),('cn','ranges'),('cn','etc'), + api.env.basedn), cn=[testrange1], objectclass=[u'ipaIDrange', u'ipadomainidrange'], ipabaseid=[u'900000'], @@ -62,9 +61,8 @@ class test_range(Declarative): command=('range_show', [testrange1], dict()), expected=dict( result=dict( - dn=lambda x: DN(x) == \ - DN(('cn',testrange1),('cn','ranges'),('cn','etc'), - api.env.basedn), + dn=DN(('cn',testrange1),('cn','ranges'),('cn','etc'), + api.env.basedn), cn=[testrange1], ipabaseid=[u'900000'], ipabaserid=[u'1000'], diff --git a/tests/test_xmlrpc/test_replace.py b/tests/test_xmlrpc/test_replace.py index f5203607..434f71d7 100644 --- a/tests/test_xmlrpc/test_replace.py +++ b/tests/test_xmlrpc/test_replace.py @@ -28,7 +28,7 @@ gen_modlist code. from ipalib import api, errors from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid -from ipalib.dn import * +from ipapython.dn import DN user1=u'tuser1' @@ -66,18 +66,15 @@ class test_replace(Declarative): initials=[u'TU'], mail=[u'test1@example.com', u'test2@example.com'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm),('cn','kerberos'), - api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm),('cn','kerberos'), + api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), diff --git a/tests/test_xmlrpc/test_role_plugin.py b/tests/test_xmlrpc/test_role_plugin.py index e2bd28cd..b847ca9e 100644 --- a/tests/test_xmlrpc/test_role_plugin.py +++ b/tests/test_xmlrpc/test_role_plugin.py @@ -25,7 +25,7 @@ Test the `ipalib/plugins/role.py` module. from ipalib import api, errors from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid -from ipalib.dn import * +from ipapython.dn import DN search = u'test-role' @@ -117,7 +117,7 @@ class test_role(Declarative): value=role1, summary=u'Added role "%s"' % role1, result=dict( - dn=lambda x: DN(x) == role1_dn, + dn=role1_dn, cn=[role1], description=[u'role desc 1'], objectclass=objectclasses.role, @@ -133,7 +133,7 @@ class test_role(Declarative): value=role1, summary=None, result=dict( - dn=lambda x: DN(x) == role1_dn, + dn=role1_dn, cn=[role1], description=[u'role desc 1'], ), @@ -151,7 +151,7 @@ class test_role(Declarative): value=group1, summary=u'Added group "testgroup1"', result=dict( - dn=lambda x: DN(x) == group1_dn, + dn=group1_dn, cn=[group1], description=[u'group desc 1'], objectclass=objectclasses.group, @@ -170,7 +170,7 @@ class test_role(Declarative): value=privilege1, summary=u'Added privilege "%s"' % privilege1, result=dict( - dn=lambda x: DN(x) == privilege1_dn, + dn=privilege1_dn, cn=[privilege1], description=[u'privilege desc. 1'], objectclass=objectclasses.privilege, @@ -192,7 +192,7 @@ class test_role(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'role desc 1'], 'memberof_privilege': [privilege1], @@ -213,7 +213,7 @@ class test_role(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'role desc 1'], 'memberof_privilege': [privilege1], @@ -234,7 +234,7 @@ class test_role(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'role desc 1'], 'memberof_privilege': [privilege1], @@ -257,7 +257,7 @@ class test_role(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'role desc 1'], 'member_group': [group1], @@ -274,7 +274,7 @@ class test_role(Declarative): value=role1, summary=None, result={ - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'role desc 1'], 'member_group': [group1], @@ -293,7 +293,7 @@ class test_role(Declarative): summary=u'1 role matched', result=[ { - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'role desc 1'], 'member_group': [group1], @@ -313,7 +313,7 @@ class test_role(Declarative): summary=u'1 role matched', result=[ { - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'role desc 1'], 'member_group': [group1], @@ -333,7 +333,7 @@ class test_role(Declarative): value=role2, summary=u'Added role "%s"' % role2, result=dict( - dn=lambda x: DN(x) == role2_dn, + dn=role2_dn, cn=[role2], description=[u'role desc 2'], objectclass=objectclasses.role, @@ -351,7 +351,7 @@ class test_role(Declarative): summary=u'1 role matched', result=[ { - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'role desc 1'], 'member_group': [group1], @@ -371,14 +371,14 @@ class test_role(Declarative): summary=u'2 roles matched', result=[ { - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'role desc 1'], 'member_group': [group1], 'memberof_privilege': [privilege1], }, { - 'dn': lambda x: DN(x) == role2_dn, + 'dn': role2_dn, 'cn': [role2], 'description': [u'role desc 2'], }, @@ -412,7 +412,7 @@ class test_role(Declarative): value=role1, summary=None, result={ - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'New desc 1'], 'member_group': [group1], @@ -436,7 +436,7 @@ class test_role(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'New desc 1'], 'memberof_privilege': [privilege1], @@ -452,7 +452,7 @@ class test_role(Declarative): value=role1, summary=None, result={ - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'New desc 1'], 'memberof_privilege': [privilege1], @@ -515,7 +515,7 @@ class test_role(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'New desc 1'], } @@ -536,7 +536,7 @@ class test_role(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == role1_dn, + 'dn': role1_dn, 'cn': [role1], 'description': [u'New desc 1'], } @@ -586,7 +586,7 @@ class test_role(Declarative): summary=u'1 role matched', result=[ { - 'dn': lambda x: DN(x) == role2_dn, + 'dn': role2_dn, 'cn': [role2], 'description': [u'role desc 2'], }, diff --git a/tests/test_xmlrpc/test_selinuxusermap_plugin.py b/tests/test_xmlrpc/test_selinuxusermap_plugin.py index 2f6f52c6..c1bee54d 100644 --- a/tests/test_xmlrpc/test_selinuxusermap_plugin.py +++ b/tests/test_xmlrpc/test_selinuxusermap_plugin.py @@ -23,7 +23,7 @@ Test the `ipalib/plugins/selinuxusermap.py` module. from ipalib import api, errors from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid -from ipalib.dn import * +from ipapython.dn import DN from tests.util import Fuzzy rule1 = u'selinuxrule1' @@ -34,15 +34,16 @@ user1 = u'tuser1' group1 = u'testgroup1' host1 = u'testhost1.%s' % api.env.domain hostdn1 = DN(('fqdn',host1),('cn','computers'),('cn','accounts'), - api.env.basedn) + api.env.basedn) hbacrule1 = u'testhbacrule1' hbacrule2 = u'testhbacrule12' +# Note (?i) at the beginning of the regexp is the ingnore case flag fuzzy_selinuxusermapdn = Fuzzy( - 'ipauniqueid=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12},%s,%s' % (api.env.container_selinux, api.env.basedn) + '(?i)ipauniqueid=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12},%s,%s' % (api.env.container_selinux, api.env.basedn) ) fuzzy_hbacruledn = Fuzzy( - 'ipauniqueid=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12},%s,%s' % (api.env.container_hbac, api.env.basedn) + '(?i)ipauniqueid=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12},%s,%s' % (api.env.container_hbac, api.env.basedn) ) class test_selinuxusermap(Declarative): @@ -204,16 +205,13 @@ class test_selinuxusermap(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], - dn=lambda x: DN(x) == \ - DN(('uid',user1),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid',user1),('cn','users'),('cn','accounts'), + api.env.basedn), has_keytab=False, has_password=False, ), @@ -234,9 +232,8 @@ class test_selinuxusermap(Declarative): gidnumber=[fuzzy_digits], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == \ - DN(('cn',group1),('cn','groups'),('cn','accounts'), - api.env.basedn), + dn=DN(('cn',group1),('cn','groups'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -256,9 +253,8 @@ class test_selinuxusermap(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',group1),('cn','groups'),('cn','accounts'), - api.env.basedn), + 'dn': DN(('cn',group1),('cn','groups'),('cn','accounts'), + api.env.basedn), 'member_user': (user1,), 'gidnumber': [fuzzy_digits], 'cn': [group1], @@ -281,7 +277,7 @@ class test_selinuxusermap(Declarative): value=host1, summary=u'Added host "%s"' % host1, result=dict( - dn=lambda x: DN(x) == hostdn1, + dn=hostdn1, fqdn=[host1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], diff --git a/tests/test_xmlrpc/test_service_plugin.py b/tests/test_xmlrpc/test_service_plugin.py index 28c6bb66..e06132fe 100644 --- a/tests/test_xmlrpc/test_service_plugin.py +++ b/tests/test_xmlrpc/test_service_plugin.py @@ -27,7 +27,7 @@ from tests.test_xmlrpc.xmlrpc_test import fuzzy_digits, fuzzy_date, fuzzy_issuer from tests.test_xmlrpc.xmlrpc_test import fuzzy_hex from tests.test_xmlrpc import objectclasses import base64 -from ipalib.dn import * +from ipapython.dn import DN fqdn1 = u'testhost1.%s' % api.env.domain fqdn2 = u'testhost2.%s' % api.env.domain @@ -93,7 +93,7 @@ class test_service(Declarative): value=fqdn1, summary=u'Added host "%s"' % fqdn1, result=dict( - dn=lambda x: DN(x) == host1dn, + dn=host1dn, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -121,7 +121,7 @@ class test_service(Declarative): value=fqdn2, summary=u'Added host "%s"' % fqdn2, result=dict( - dn=lambda x: DN(x) == host2dn, + dn=host2dn, fqdn=[fqdn2], description=[u'Test host 2'], l=[u'Undisclosed location 2'], @@ -149,7 +149,7 @@ class test_service(Declarative): value=fqdn3.lower(), summary=u'Added host "%s"' % fqdn3.lower(), result=dict( - dn=lambda x: DN(x) == host3dn, + dn=host3dn, fqdn=[fqdn3.lower()], description=[u'Test host 3'], l=[u'Undisclosed location 3'], @@ -175,7 +175,7 @@ class test_service(Declarative): value=service1, summary=u'Added service "%s"' % service1, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], objectclass=objectclasses.service, ipauniqueid=[fuzzy_uuid], @@ -205,7 +205,7 @@ class test_service(Declarative): value=service1, summary=None, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], has_keytab=False, ipakrbauthzdata=[u'MS-PAC'], @@ -222,7 +222,7 @@ class test_service(Declarative): value=service1, summary=None, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], ipakrbprincipalalias=[service1], objectclass=objectclasses.service, @@ -244,7 +244,7 @@ class test_service(Declarative): summary=u'1 service matched', result=[ dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], managedby_host=[fqdn1], ipakrbauthzdata=[u'MS-PAC'], @@ -264,7 +264,7 @@ class test_service(Declarative): summary=u'1 service matched', result=[ dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], ipakrbprincipalalias=[service1], objectclass=objectclasses.service, @@ -285,7 +285,7 @@ class test_service(Declarative): failed=dict(managedby=dict(host=[(u'notfound', u'no such entry')])), completed=0, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], ipakrbauthzdata=[u'MS-PAC'], managedby_host=[fqdn1], @@ -301,7 +301,7 @@ class test_service(Declarative): failed=dict(managedby=dict(host=[(u'notfound', u'This entry is not a member')])), completed=0, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], ipakrbauthzdata=[u'MS-PAC'], managedby_host=[fqdn1], @@ -317,7 +317,7 @@ class test_service(Declarative): failed=dict(managedby=dict(host=[])), completed=1, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], ipakrbauthzdata=[u'MS-PAC'], managedby_host=[fqdn1, fqdn2], @@ -333,7 +333,7 @@ class test_service(Declarative): failed=dict(managedby=dict(host=[])), completed=1, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], ipakrbauthzdata=[u'MS-PAC'], managedby_host=[fqdn1], @@ -349,7 +349,7 @@ class test_service(Declarative): failed=dict(managedby=dict(host=[])), completed=1, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], ipakrbauthzdata=[u'MS-PAC'], managedby_host=[fqdn1, fqdn3.lower()], @@ -365,7 +365,7 @@ class test_service(Declarative): failed=dict(managedby=dict(host=[])), completed=1, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, krbprincipalname=[service1], ipakrbauthzdata=[u'MS-PAC'], managedby_host=[fqdn1], @@ -396,8 +396,7 @@ class test_service(Declarative): managedby_host=[fqdn1], valid_not_before=fuzzy_date, valid_not_after=fuzzy_date, - subject=lambda x: DN(x) == \ - DN(('CN',api.env.host),x509.subject_base()), + subject=DN(('CN',api.env.host),x509.subject_base()), serial_number=fuzzy_digits, serial_number_hex=fuzzy_hex, md5_fingerprint=fuzzy_hash, @@ -415,7 +414,7 @@ class test_service(Declarative): value=service1, summary=None, result=dict( - dn=lambda x: DN(x) == service1dn, + dn=service1dn, usercertificate=[base64.b64decode(servercert)], krbprincipalname=[service1], has_keytab=False, @@ -425,8 +424,7 @@ class test_service(Declarative): # test case. valid_not_before=fuzzy_date, valid_not_after=fuzzy_date, - subject=lambda x: DN(x) == \ - DN(('CN',api.env.host),x509.subject_base()), + subject=DN(('CN',api.env.host),x509.subject_base()), serial_number=fuzzy_digits, serial_number_hex=fuzzy_hex, md5_fingerprint=fuzzy_hash, diff --git a/tests/test_xmlrpc/test_sudocmd_plugin.py b/tests/test_xmlrpc/test_sudocmd_plugin.py index 4574f774..75b6bbcc 100644 --- a/tests/test_xmlrpc/test_sudocmd_plugin.py +++ b/tests/test_xmlrpc/test_sudocmd_plugin.py @@ -24,7 +24,7 @@ Test the `ipalib/plugins/sudocmd.py` module. from ipalib import api, errors from tests.test_xmlrpc.xmlrpc_test import Declarative, fuzzy_uuid from tests.test_xmlrpc import objectclasses -from ipalib.dn import * +from ipapython.dn import DN sudocmd1 = u'/usr/bin/sudotestcmd1' @@ -72,9 +72,8 @@ class test_sudocmd(Declarative): value=sudocmd1, summary=u'Added Sudo Command "%s"' % sudocmd1, result=dict( - dn=lambda x: DN(x) == \ - DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), - api.env.basedn), + dn=DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), + api.env.basedn), sudocmd=[sudocmd1], description=[u'Test sudo command 1'], objectclass=objectclasses.sudocmd, @@ -103,9 +102,8 @@ class test_sudocmd(Declarative): value=sudocmd1, summary=None, result=dict( - dn=lambda x: DN(x) == \ - DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), - api.env.basedn), + dn=DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), + api.env.basedn), sudocmd=[sudocmd1], description=[u'Test sudo command 1'], ), @@ -122,9 +120,8 @@ class test_sudocmd(Declarative): summary=u'1 Sudo Command matched', result=[ dict( - dn=lambda x: DN(x) == \ - DN(('sudocmd',sudocmd1),('cn','sudocmds'), - ('cn','sudo'),api.env.basedn), + dn=DN(('sudocmd',sudocmd1),('cn','sudocmds'), + ('cn','sudo'),api.env.basedn), sudocmd=[sudocmd1], description=[u'Test sudo command 1'], ), @@ -155,9 +152,8 @@ class test_sudocmd(Declarative): value=sudocmd1, summary=None, result=dict( - dn=lambda x: DN(x) == \ - DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), - api.env.basedn), + dn=DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), + api.env.basedn), sudocmd=[sudocmd1], description=[u'Updated sudo command 1'], ), diff --git a/tests/test_xmlrpc/test_sudocmdgroup_plugin.py b/tests/test_xmlrpc/test_sudocmdgroup_plugin.py index 2bfbb625..b8c15737 100644 --- a/tests/test_xmlrpc/test_sudocmdgroup_plugin.py +++ b/tests/test_xmlrpc/test_sudocmdgroup_plugin.py @@ -23,7 +23,7 @@ Test the `ipalib/plugins/sudocmdgroup.py` module. from ipalib import api, errors from tests.test_xmlrpc import objectclasses from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid -from ipalib.dn import * +from ipapython.dn import DN sudocmdgroup1 = u'testsudocmdgroup1' sudocmdgroup2 = u'testsudocmdgroup2' @@ -45,9 +45,8 @@ def create_command(sudocmd): sudocmd=[sudocmd], ipauniqueid=[fuzzy_uuid], description=[u'Test sudo command'], - dn=lambda x: DN(x) == \ - DN(('sudocmd',sudocmd),('cn','sudocmds'),('cn','sudo'), - api.env.basedn), + dn=DN(('sudocmd',sudocmd),('cn','sudocmds'),('cn','sudo'), + api.env.basedn), ), ), ) @@ -77,9 +76,8 @@ class test_sudocmdgroup(Declarative): sudocmd=[u'/usr/bin/sudotestcmd1'], ipauniqueid=[fuzzy_uuid], description=[u'Test sudo command 1'], - dn=lambda x: DN(x) == \ - DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), - api.env.basedn), + dn=DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), + api.env.basedn), ), ), ), @@ -94,9 +92,8 @@ class test_sudocmdgroup(Declarative): result=dict( sudocmd=[sudocmd1], description=[u'Test sudo command 1'], - dn=lambda x: DN(x) == \ - DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), - api.env.basedn), + dn=DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), + api.env.basedn), ), ), ), @@ -143,9 +140,8 @@ class test_sudocmdgroup(Declarative): description=[u'Test desc 1'], objectclass=objectclasses.sudocmdgroup, ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == \ - DN(('cn','testsudocmdgroup1'),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + dn=DN(('cn','testsudocmdgroup1'),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), ), ), ), @@ -171,9 +167,8 @@ class test_sudocmdgroup(Declarative): result=dict( cn=[sudocmdgroup1], description=[u'Test desc 1'], - dn=lambda x: DN(x) == \ - DN(('cn','testsudocmdgroup1'),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + dn=DN(('cn','testsudocmdgroup1'),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), ), ), ), @@ -204,9 +199,8 @@ class test_sudocmdgroup(Declarative): result=dict( cn=[sudocmdgroup1], description=[u'New desc 1'], - dn=lambda x: DN(x) == \ - DN(('cn','testsudocmdgroup1'),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + dn=DN(('cn','testsudocmdgroup1'),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), ), summary=None, ), @@ -221,9 +215,8 @@ class test_sudocmdgroup(Declarative): truncated=False, result=[ dict( - dn=lambda x: DN(x) == \ - DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + dn=DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), cn=[sudocmdgroup1], description=[u'New desc 1'], ), @@ -275,9 +268,8 @@ class test_sudocmdgroup(Declarative): description=[u'Test desc 2'], objectclass=objectclasses.sudocmdgroup, ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == \ - DN(('cn','testsudocmdgroup2'),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + dn=DN(('cn','testsudocmdgroup2'),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), ), ), ), @@ -304,9 +296,8 @@ class test_sudocmdgroup(Declarative): result=dict( cn=[sudocmdgroup2], description=[u'Test desc 2'], - dn=lambda x: DN(x) == \ - DN(('cn','testsudocmdgroup2'),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + dn=DN(('cn','testsudocmdgroup2'),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), ), ), ), @@ -337,9 +328,8 @@ class test_sudocmdgroup(Declarative): result=dict( cn=[sudocmdgroup2], description=[u'New desc 2'], - dn=lambda x: DN(x) == \ - DN(('cn','testsudocmdgroup2'),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + dn=DN(('cn','testsudocmdgroup2'),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), ), summary=None, ), @@ -354,9 +344,8 @@ class test_sudocmdgroup(Declarative): truncated=False, result=[ dict( - dn=lambda x: DN(x) == \ - DN(('cn',sudocmdgroup2),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + dn=DN(('cn',sudocmdgroup2),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), cn=[sudocmdgroup2], description=[u'New desc 2'], ), @@ -375,16 +364,14 @@ class test_sudocmdgroup(Declarative): truncated=False, result=[ dict( - dn=lambda x: DN(x) == \ - DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + dn=DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), cn=[sudocmdgroup1], description=[u'New desc 1'], ), dict( - dn=lambda x: DN(x) == \ - DN(('cn',sudocmdgroup2),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + dn=DN(('cn',sudocmdgroup2),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), cn=[sudocmdgroup2], description=[u'New desc 2'], ), @@ -410,9 +397,8 @@ class test_sudocmdgroup(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + 'dn': DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), 'member_sudocmd': (sudocmd1,), 'cn': [sudocmdgroup1], 'description': [u'New desc 1'], @@ -427,9 +413,8 @@ class test_sudocmdgroup(Declarative): value=sudocmd1, summary=None, result=dict( - dn=lambda x: DN(x) == \ - DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), - api.env.basedn), + dn=DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'), + api.env.basedn), sudocmd=[sudocmd1], description=[u'Test sudo command 1'], memberof_sudocmdgroup = [u'testsudocmdgroup1'], @@ -451,9 +436,8 @@ class test_sudocmdgroup(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + 'dn': DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), 'member_sudocmd': (u'/usr/bin/sudotestcmd1',), 'cn': [sudocmdgroup1], 'description': [u'New desc 1'], @@ -474,9 +458,8 @@ class test_sudocmdgroup(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + 'dn': DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), 'cn': [sudocmdgroup1], 'description': [u'New desc 1'], }, @@ -497,9 +480,8 @@ class test_sudocmdgroup(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + 'dn': DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), 'cn': [sudocmdgroup1], 'description': [u'New desc 1'], }, @@ -523,9 +505,8 @@ class test_sudocmdgroup(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + 'dn': DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), 'member_sudocmd': (sudocmd_plus,), 'cn': [sudocmdgroup1], 'description': [u'New desc 1'], @@ -546,9 +527,8 @@ class test_sudocmdgroup(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), - ('cn','sudo'),api.env.basedn), + 'dn': DN(('cn',sudocmdgroup1),('cn','sudocmdgroups'), + ('cn','sudo'),api.env.basedn), 'cn': [sudocmdgroup1], 'description': [u'New desc 1'], }, diff --git a/tests/test_xmlrpc/test_user_plugin.py b/tests/test_xmlrpc/test_user_plugin.py index b257a90a..4a4c69c1 100644 --- a/tests/test_xmlrpc/test_user_plugin.py +++ b/tests/test_xmlrpc/test_user_plugin.py @@ -27,7 +27,7 @@ from ipalib import api, errors from tests.test_xmlrpc import objectclasses from tests.util import assert_equal, assert_not_equal from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid, fuzzy_password, fuzzy_string, fuzzy_dergeneralizedtime -from ipalib.dn import * +from ipapython.dn import DN user1=u'tuser1' user2=u'tuser2' @@ -52,7 +52,7 @@ def not_upg_check(response): class test_user(Declarative): cleanup_commands = [ - ('user_del', [user1, user2], {}), + ('user_del', [user1, user2, renameduser1], {}), ('group_del', [group1], {}), ] @@ -81,7 +81,7 @@ class test_user(Declarative): dict( desc='Try to rename non-existent %r' % user1, - command=('user_mod', [user1], dict(setattr=u'uid=tuser')), + command=('user_mod', [user1], dict(setattr=u'uid=%s' % renameduser1)), expected=errors.NotFound(reason=u'%s: user not found' % user1), ), @@ -109,18 +109,15 @@ class test_user(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), extra_check = upg_check, @@ -144,9 +141,8 @@ class test_user(Declarative): ), expected=dict( result=dict( - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), givenname=[u'Test'], homedirectory=[u'/home/tuser1'], loginshell=[u'/bin/sh'], @@ -173,9 +169,8 @@ class test_user(Declarative): expected=dict( result=[ { - 'dn': lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'), - ('cn','accounts'),api.env.basedn), + 'dn': DN(('uid','tuser1'),('cn','users'), + ('cn','accounts'),api.env.basedn), 'cn': [u'Test User1'], 'gecos': [u'Test User1'], 'givenname': [u'Test'], @@ -189,12 +184,10 @@ class test_user(Declarative): 'uidnumber': [fuzzy_digits], 'gidnumber': [fuzzy_digits], 'ipauniqueid': [fuzzy_uuid], - 'mepmanagedentry': lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], - 'krbpwdpolicyreference': lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], + 'mepmanagedentry': [DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], + 'krbpwdpolicyreference': [DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], 'nsaccountlock': False, 'has_keytab': False, 'has_password': False, @@ -217,9 +210,8 @@ class test_user(Declarative): expected=dict( result=[ { - 'dn':lambda x: DN(x) == \ - DN(('uid',user1),('cn','users'), - ('cn','accounts'),api.env.basedn), + 'dn':DN(('uid',user1),('cn','users'), + ('cn','accounts'),api.env.basedn), 'uid': [user1], }, ], @@ -237,9 +229,8 @@ class test_user(Declarative): expected=dict( result=[ dict( - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'), - ('cn','accounts'),api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'), + ('cn','accounts'),api.env.basedn), givenname=[u'Test'], homedirectory=[u'/home/tuser1'], loginshell=[u'/bin/sh'], @@ -267,9 +258,8 @@ class test_user(Declarative): expected=dict( result=[ dict( - dn=lambda x: DN(x) == \ - DN(('uid','admin'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','admin'),('cn','users'),('cn','accounts'), + api.env.basedn), homedirectory=[u'/home/admin'], loginshell=[u'/bin/bash'], sn=[u'Administrator'], @@ -281,9 +271,8 @@ class test_user(Declarative): gidnumber=[fuzzy_digits], ), dict( - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'), - ('cn','accounts'),api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'), + ('cn','accounts'),api.env.basedn), givenname=[u'Test'], homedirectory=[u'/home/tuser1'], loginshell=[u'/bin/sh'], @@ -311,9 +300,8 @@ class test_user(Declarative): expected=dict( result=[ dict( - dn=lambda x: DN(x) == \ - DN(('uid','admin'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','admin'),('cn','users'),('cn','accounts'), + api.env.basedn), homedirectory=[u'/home/admin'], loginshell=[u'/bin/bash'], sn=[u'Administrator'], @@ -465,9 +453,8 @@ class test_user(Declarative): command=('user_show', [user1], {}), expected=dict( result=dict( - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), givenname=[u'Finkle'], homedirectory=[u'/home/tuser1'], loginshell=[u'/bin/sh'], @@ -591,18 +578,15 @@ class test_user(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), extra_check = upg_check, @@ -632,18 +616,15 @@ class test_user(Declarative): cn=[u'Test User2'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user2),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user2),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser2'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser2'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), extra_check = upg_check, @@ -783,9 +764,8 @@ class test_user(Declarative): gidnumber=[fuzzy_digits], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], - dn=lambda x: DN(x) == \ - DN(('cn',group1),('cn','groups'),('cn','accounts'), - api.env.basedn), + dn=DN(('cn',group1),('cn','groups'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -830,18 +810,15 @@ class test_user(Declarative): postalcode=[u'01234-5678'], telephonenumber=[u'410-555-1212'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -880,12 +857,10 @@ class test_user(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=True, has_password=True, @@ -893,9 +868,8 @@ class test_user(Declarative): krbextradata=[fuzzy_string], krbpasswordexpiration=[fuzzy_dergeneralizedtime], krblastpwdchange=[fuzzy_dergeneralizedtime], - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -933,18 +907,15 @@ class test_user(Declarative): cn=[u'Test User2'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user2),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user2),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser2'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser2'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -1008,18 +979,15 @@ class test_user(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -1085,18 +1053,15 @@ class test_user(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -1151,18 +1116,15 @@ class test_user(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], - mepmanagedentry=lambda x: [DN(i) for i in x] == \ - [DN(('cn',user1),('cn','groups'),('cn','accounts'), - api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], + mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'), + api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -1217,15 +1179,13 @@ class test_user(Declarative): cn=[u'Test User2'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], memberof_group=[u'ipausers'], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser2'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser2'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -1272,15 +1232,13 @@ class test_user(Declarative): cn=[u'Test User1'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], memberof_group=[group1], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser1'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser1'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), extra_check = not_upg_check, @@ -1310,15 +1268,13 @@ class test_user(Declarative): cn=[u'Test User2'], initials=[u'TU'], ipauniqueid=[fuzzy_uuid], - krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \ - [DN(('cn','global_policy'),('cn',api.env.realm), - ('cn','kerberos'),api.env.basedn)], + krbpwdpolicyreference=[DN(('cn','global_policy'),('cn',api.env.realm), + ('cn','kerberos'),api.env.basedn)], memberof_group=[group1], has_keytab=False, has_password=False, - dn=lambda x: DN(x) == \ - DN(('uid','tuser2'),('cn','users'),('cn','accounts'), - api.env.basedn), + dn=DN(('uid','tuser2'),('cn','users'),('cn','accounts'), + api.env.basedn), ), ), ), @@ -1350,9 +1306,8 @@ class test_user(Declarative): ), ), result={ - 'dn': lambda x: DN(x) == \ - DN(('cn', 'admins'), ('cn', 'groups'), - ('cn', 'accounts'), api.env.basedn), + 'dn': DN(('cn', 'admins'), ('cn', 'groups'), + ('cn', 'accounts'), api.env.basedn), 'member_user': [u'admin', user2], 'gidnumber': [fuzzy_digits], 'cn': [u'admins'], diff --git a/tests/test_xmlrpc/xmlrpc_test.py b/tests/test_xmlrpc/xmlrpc_test.py index cfba35fc..7c32be0d 100644 --- a/tests/test_xmlrpc/xmlrpc_test.py +++ b/tests/test_xmlrpc/xmlrpc_test.py @@ -40,9 +40,9 @@ fuzzy_uuid = Fuzzy( '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' ) -# Matches netgroup dn +# Matches netgroup dn. Note (?i) at the beginning of the regexp is the ingnore case flag fuzzy_netgroupdn = Fuzzy( - 'ipauniqueid=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12},cn=ng,cn=alt,%s' % api.env.basedn + '(?i)ipauniqueid=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12},cn=ng,cn=alt,%s' % api.env.basedn ) # Matches a hash signature, not enforcing length diff --git a/tests/util.py b/tests/util.py index 54a8dd14..ed62a223 100644 --- a/tests/util.py +++ b/tests/util.py @@ -30,6 +30,7 @@ import re import ipalib from ipalib.plugable import Plugin from ipalib.request import context +from ipapython.dn import DN class TempDir(object): def __init__(self): @@ -303,6 +304,9 @@ def assert_deepequal(expected, got, doc='', stack=tuple()): expected = list(expected) if isinstance(got, tuple): got = list(got) + if isinstance(expected, DN): + if isinstance(got, basestring): + got = DN(got) if not (isinstance(expected, Fuzzy) or callable(expected) or type(expected) is type(got)): raise AssertionError( TYPE % (doc, type(expected), type(got), expected, got, stack) |