Imported Debian patch 4.7.2-3
This commit is contained in:
committed by
Mario Fetka
parent
27edeba051
commit
8bc559c5a1
@@ -3,7 +3,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import pytest
|
||||
from ipapython.ipachangeconf import IPAChangeConf
|
||||
from ipaclient.install.ipachangeconf import IPAChangeConf
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
|
||||
@@ -23,6 +23,7 @@ Test the `ipaserver/install/ldapupdate.py` module.
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -31,7 +32,7 @@ from ipalib import errors
|
||||
from ipaserver.install.ldapupdate import LDAPUpdate, BadSyntax
|
||||
from ipaserver.install import installutils
|
||||
from ipapython import ipaldap
|
||||
from ipaplatform.constants import constants as platformconstants
|
||||
from ipaplatform.paths import paths
|
||||
from ipapython.dn import DN
|
||||
|
||||
"""
|
||||
@@ -49,36 +50,36 @@ The DM password needs to be set in ~/.ipa/.dmpw
|
||||
|
||||
@pytest.mark.tier0
|
||||
@pytest.mark.needs_ipaapi
|
||||
class TestUpdate:
|
||||
class test_update(unittest.TestCase):
|
||||
"""
|
||||
Test the LDAP updater.
|
||||
"""
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def update_setup(self, request):
|
||||
def setUp(self):
|
||||
fqdn = installutils.get_fqdn()
|
||||
pwfile = api.env.dot_ipa + os.sep + ".dmpw"
|
||||
if os.path.isfile(pwfile):
|
||||
with open(pwfile, "r") as fp:
|
||||
self.dm_password = fp.read().rstrip()
|
||||
fp = open(pwfile, "r")
|
||||
self.dm_password = fp.read().rstrip()
|
||||
fp.close()
|
||||
else:
|
||||
pytest.skip("No directory manager password")
|
||||
raise unittest.SkipTest("No directory manager password")
|
||||
self.updater = LDAPUpdate(dm_password=self.dm_password, sub_dict={})
|
||||
self.ld = ipaldap.LDAPClient.from_hostname_secure(fqdn)
|
||||
ldap_uri = ipaldap.get_ldap_uri(fqdn)
|
||||
self.ld = ipaldap.LDAPClient(ldap_uri)
|
||||
self.ld.simple_bind(bind_dn=ipaldap.DIRMAN_DN,
|
||||
bind_password=self.dm_password)
|
||||
self.testdir = os.path.abspath(os.path.dirname(__file__))
|
||||
if not os.path.isfile(os.path.join(self.testdir,
|
||||
"0_reset.update")):
|
||||
pytest.skip("Unable to find test update files")
|
||||
raise unittest.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 fin():
|
||||
if self.ld:
|
||||
self.ld.unbind()
|
||||
request.addfinalizer(fin)
|
||||
def tearDown(self):
|
||||
if self.ld:
|
||||
self.ld.unbind()
|
||||
|
||||
def test_0_reset(self):
|
||||
"""
|
||||
@@ -91,13 +92,13 @@ class TestUpdate:
|
||||
# Just means the entry doesn't exist yet
|
||||
modified = True
|
||||
|
||||
assert modified
|
||||
self.assertTrue(modified)
|
||||
|
||||
with pytest.raises(errors.NotFound):
|
||||
with self.assertRaises(errors.NotFound):
|
||||
self.ld.get_entries(
|
||||
self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
|
||||
with pytest.raises(errors.NotFound):
|
||||
with self.assertRaises(errors.NotFound):
|
||||
self.ld.get_entries(
|
||||
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
|
||||
@@ -108,33 +109,32 @@ class TestUpdate:
|
||||
modified = self.updater.update([os.path.join(self.testdir,
|
||||
"1_add.update")])
|
||||
|
||||
assert modified
|
||||
self.assertTrue(modified)
|
||||
|
||||
entries = self.ld.get_entries(
|
||||
self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
assert len(entries) == 1
|
||||
self.assertEqual(len(entries), 1)
|
||||
entry = entries[0]
|
||||
|
||||
objectclasses = entry.get('objectclass')
|
||||
for item in ('top', 'nsContainer'):
|
||||
assert item in objectclasses
|
||||
self.assertTrue(item in objectclasses)
|
||||
|
||||
assert entry.single_value['cn'] == 'test'
|
||||
self.assertEqual(entry.single_value['cn'], 'test')
|
||||
|
||||
entries = self.ld.get_entries(
|
||||
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
assert len(entries) == 1
|
||||
self.assertEqual(len(entries), 1)
|
||||
entry = entries[0]
|
||||
|
||||
objectclasses = entry.get('objectclass')
|
||||
for item in ('top', 'person', 'posixaccount', 'krbprincipalaux', 'inetuser'):
|
||||
assert item in objectclasses
|
||||
self.assertTrue(item in objectclasses)
|
||||
|
||||
actual = entry.single_value['loginshell']
|
||||
assert actual == platformconstants.DEFAULT_ADMIN_SHELL
|
||||
assert entry.single_value['sn'] == 'User'
|
||||
assert entry.single_value['uid'] == 'tuser'
|
||||
assert entry.single_value['cn'] == 'Test User'
|
||||
self.assertEqual(entry.single_value['loginshell'], paths.BASH)
|
||||
self.assertEqual(entry.single_value['sn'], 'User')
|
||||
self.assertEqual(entry.single_value['uid'], 'tuser')
|
||||
self.assertEqual(entry.single_value['cn'], 'Test User')
|
||||
|
||||
|
||||
def test_2_update(self):
|
||||
@@ -143,13 +143,13 @@ class TestUpdate:
|
||||
"""
|
||||
modified = self.updater.update([os.path.join(self.testdir,
|
||||
"2_update.update")])
|
||||
assert modified
|
||||
self.assertTrue(modified)
|
||||
|
||||
entries = self.ld.get_entries(
|
||||
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
assert len(entries) == 1
|
||||
self.assertEqual(len(entries), 1)
|
||||
entry = entries[0]
|
||||
assert entry.single_value['gecos'] == 'Test User'
|
||||
self.assertEqual(entry.single_value['gecos'], 'Test User')
|
||||
|
||||
def test_3_update(self):
|
||||
"""
|
||||
@@ -157,13 +157,13 @@ class TestUpdate:
|
||||
"""
|
||||
modified = self.updater.update([os.path.join(self.testdir,
|
||||
"3_update.update")])
|
||||
assert modified
|
||||
self.assertTrue(modified)
|
||||
|
||||
entries = self.ld.get_entries(
|
||||
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
assert len(entries) == 1
|
||||
self.assertEqual(len(entries), 1)
|
||||
entry = entries[0]
|
||||
assert entry.single_value['gecos'] == 'Test User New'
|
||||
self.assertEqual(entry.single_value['gecos'], 'Test User New')
|
||||
|
||||
def test_4_update(self):
|
||||
"""
|
||||
@@ -171,13 +171,13 @@ class TestUpdate:
|
||||
"""
|
||||
modified = self.updater.update([os.path.join(self.testdir,
|
||||
"4_update.update")])
|
||||
assert modified
|
||||
self.assertTrue(modified)
|
||||
|
||||
entries = self.ld.get_entries(
|
||||
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
assert len(entries) == 1
|
||||
self.assertEqual(len(entries), 1)
|
||||
entry = entries[0]
|
||||
assert entry.single_value['gecos'] == 'Test User New2'
|
||||
self.assertEqual(entry.single_value['gecos'], 'Test User New2')
|
||||
|
||||
def test_5_update(self):
|
||||
"""
|
||||
@@ -185,15 +185,13 @@ class TestUpdate:
|
||||
"""
|
||||
modified = self.updater.update([os.path.join(self.testdir,
|
||||
"5_update.update")])
|
||||
assert modified
|
||||
self.assertTrue(modified)
|
||||
|
||||
entries = self.ld.get_entries(
|
||||
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
assert len(entries) == 1
|
||||
self.assertEqual(len(entries), 1)
|
||||
entry = entries[0]
|
||||
actual = sorted(entry.get('cn'))
|
||||
expected = sorted(['Test User', 'Test User New'])
|
||||
assert actual == expected
|
||||
self.assertEqual(sorted(entry.get('cn')), sorted(['Test User', 'Test User New']))
|
||||
|
||||
def test_6_update(self):
|
||||
"""
|
||||
@@ -201,13 +199,13 @@ class TestUpdate:
|
||||
"""
|
||||
modified = self.updater.update([os.path.join(self.testdir,
|
||||
"6_update.update")])
|
||||
assert modified
|
||||
self.assertTrue(modified)
|
||||
|
||||
entries = self.ld.get_entries(
|
||||
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
assert len(entries) == 1
|
||||
self.assertEqual(len(entries), 1)
|
||||
entry = entries[0]
|
||||
assert sorted(entry.get('cn')) == sorted(['Test User'])
|
||||
self.assertEqual(sorted(entry.get('cn')), sorted(['Test User']))
|
||||
|
||||
def test_6_update_1(self):
|
||||
"""
|
||||
@@ -215,13 +213,13 @@ class TestUpdate:
|
||||
"""
|
||||
modified = self.updater.update([os.path.join(self.testdir,
|
||||
"6_update.update")])
|
||||
assert not modified
|
||||
self.assertFalse(modified)
|
||||
|
||||
entries = self.ld.get_entries(
|
||||
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
assert len(entries) == 1
|
||||
self.assertEqual(len(entries), 1)
|
||||
entry = entries[0]
|
||||
assert sorted(entry.get('cn')) == sorted(['Test User'])
|
||||
self.assertEqual(sorted(entry.get('cn')), sorted(['Test User']))
|
||||
|
||||
def test_7_cleanup(self):
|
||||
"""
|
||||
@@ -234,13 +232,13 @@ class TestUpdate:
|
||||
# Just means the entry doesn't exist yet
|
||||
modified = True
|
||||
|
||||
assert modified
|
||||
self.assertTrue(modified)
|
||||
|
||||
with pytest.raises(errors.NotFound):
|
||||
with self.assertRaises(errors.NotFound):
|
||||
self.ld.get_entries(
|
||||
self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
|
||||
with pytest.raises(errors.NotFound):
|
||||
with self.assertRaises(errors.NotFound):
|
||||
self.ld.get_entries(
|
||||
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
|
||||
|
||||
@@ -248,7 +246,7 @@ class TestUpdate:
|
||||
"""
|
||||
Test the updater with an unknown keyword (test_8_badsyntax)
|
||||
"""
|
||||
with pytest.raises(BadSyntax):
|
||||
with self.assertRaises(BadSyntax):
|
||||
self.updater.update(
|
||||
[os.path.join(self.testdir, "8_badsyntax.update")])
|
||||
|
||||
@@ -256,6 +254,6 @@ class TestUpdate:
|
||||
"""
|
||||
Test the updater with an incomplete line (test_9_badsyntax)
|
||||
"""
|
||||
with pytest.raises(BadSyntax):
|
||||
with self.assertRaises(BadSyntax):
|
||||
self.updater.update(
|
||||
[os.path.join(self.testdir, "9_badsyntax.update")])
|
||||
|
||||
Reference in New Issue
Block a user