Imported Upstream version 4.3.1

This commit is contained in:
Mario Fetka
2021-08-10 02:37:58 +02:00
parent a791de49a2
commit 2f177da8f2
2056 changed files with 421730 additions and 1668138 deletions

View File

@@ -20,7 +20,3 @@
"""
Package containing LDAP updates unit tests.
"""
import ipatests.util
ipatests.util.check_ipaclient_unittests()

View File

@@ -1,50 +0,0 @@
# Copyright (C) 2018 FreeIPA Contributors see COPYING for license
from __future__ import absolute_import
import pytest
from ipaclient.install.ipachangeconf import IPAChangeConf
@pytest.fixture(scope='function')
def config_filename(tmpdir):
filename = tmpdir.mkdir('data').join('config_file.conf')
filename.write('SOME_CONF /some/user/defined/path\n')
return filename
def test_addifnotset_action(config_filename):
"""Test if addifnotset action adds a comment about the modified conf.
IPA doesn't want to break existing configuration, if a value already exists
it adds a comment to the modified setting and a note about that on the line
above.
New settings will be added without any note.
"""
ipa_conf = IPAChangeConf('IPA Installer Test')
ipa_conf.setOptionAssignment(' ')
opts = [
{
'action': 'addifnotset',
'name': 'SOME_CONF',
'type': 'option',
'value': '/path/defined/by/ipa',
},
{
'action': 'addifnotset',
'name': 'NEW_CONF',
'type': 'option',
'value': '/path/to/somewhere',
},
]
ipa_conf.changeConf(str(config_filename), opts)
assert config_filename.readlines() == [
'# SOME_CONF modified by IPA\n',
'#SOME_CONF /path/defined/by/ipa\n',
'SOME_CONF /some/user/defined/path\n',
'NEW_CONF /path/to/somewhere\n',
]

View File

@@ -1,37 +0,0 @@
# Copyright (C) 2018 FreeIPA Contributors see COPYING for license
from __future__ import absolute_import
import tempfile
import pytest
from ipaclient.install.client import check_ldap_conf
from ipapython.admintool import ScriptError
@pytest.mark.parametrize("lines,expected", [
(["PORT 389"], "PORT"),
(["HOST example.org"], "HOST"),
(["HOST example.org", "# PORT 389"], "HOST"),
(["\tHOST example.org", "# PORT 389"], "HOST"),
(["HOST example.org", "PORT 389"], "HOST, PORT"),
(["# HOST example.org", "# PORT 389"], None),
(["URI PORT"], None),
([], None),
])
def test_check_ldap(lines, expected):
with tempfile.NamedTemporaryFile('w+') as f:
for line in lines:
f.write(line)
f.write('\n')
f.write('\n')
f.flush()
if expected is None:
assert check_ldap_conf(f.name) is True
else:
with pytest.raises(ScriptError) as e:
check_ldap_conf(f.name)
msg = e.value.msg
assert msg.endswith(expected)

View File

@@ -20,18 +20,17 @@
Test the `ipaserver/install/ldapupdate.py` module.
"""
from __future__ import absolute_import
import os
import unittest
import os
import nose
import pytest
from ipalib import api
from ipalib import errors
from ipaserver.install.ldapupdate import LDAPUpdate, BadSyntax
from ipaserver.install import installutils
from ipapython import ipaldap
from ipapython import ipautil, ipaldap
from ipaplatform.paths import paths
from ipapython.dn import DN
@@ -49,7 +48,6 @@ The DM password needs to be set in ~/.ipa/.dmpw
@pytest.mark.tier0
@pytest.mark.needs_ipaapi
class test_update(unittest.TestCase):
"""
Test the LDAP updater.
@@ -58,21 +56,21 @@ class test_update(unittest.TestCase):
def setUp(self):
fqdn = installutils.get_fqdn()
pwfile = api.env.dot_ipa + os.sep + ".dmpw"
if os.path.isfile(pwfile):
if ipautil.file_exists(pwfile):
fp = open(pwfile, "r")
self.dm_password = fp.read().rstrip()
fp.close()
else:
raise unittest.SkipTest("No directory manager password")
raise nose.SkipTest("No directory manager password")
self.updater = LDAPUpdate(dm_password=self.dm_password, sub_dict={})
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")):
raise unittest.SkipTest("Unable to find test update files")
self.ld = ipaldap.IPAdmin(fqdn)
self.ld.do_simple_bind(bindpw=self.dm_password)
if ipautil.file_exists("0_reset.update"):
self.testdir="./"
elif ipautil.file_exists("ipatests/test_install/0_reset.update"):
self.testdir= "./ipatests/test_install/"
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'))
@@ -86,8 +84,7 @@ class test_update(unittest.TestCase):
Reset the updater test data to a known initial state (test_0_reset)
"""
try:
modified = self.updater.update([os.path.join(self.testdir,
"0_reset.update")])
modified = self.updater.update([self.testdir + "0_reset.update"])
except errors.NotFound:
# Just means the entry doesn't exist yet
modified = True
@@ -95,19 +92,18 @@ class test_update(unittest.TestCase):
self.assertTrue(modified)
with self.assertRaises(errors.NotFound):
self.ld.get_entries(
entries = self.ld.get_entries(
self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
with self.assertRaises(errors.NotFound):
self.ld.get_entries(
entries = self.ld.get_entries(
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
def test_1_add(self):
"""
Test the updater with an add directive (test_1_add)
"""
modified = self.updater.update([os.path.join(self.testdir,
"1_add.update")])
modified = self.updater.update([self.testdir + "1_add.update"])
self.assertTrue(modified)
@@ -141,8 +137,7 @@ class test_update(unittest.TestCase):
"""
Test the updater when adding an attribute to an existing entry (test_2_update)
"""
modified = self.updater.update([os.path.join(self.testdir,
"2_update.update")])
modified = self.updater.update([self.testdir + "2_update.update"])
self.assertTrue(modified)
entries = self.ld.get_entries(
@@ -155,8 +150,7 @@ class test_update(unittest.TestCase):
"""
Test the updater forcing an attribute to a given value (test_3_update)
"""
modified = self.updater.update([os.path.join(self.testdir,
"3_update.update")])
modified = self.updater.update([self.testdir + "3_update.update"])
self.assertTrue(modified)
entries = self.ld.get_entries(
@@ -169,8 +163,7 @@ class test_update(unittest.TestCase):
"""
Test the updater adding a new value to a single-valued attribute (test_4_update)
"""
modified = self.updater.update([os.path.join(self.testdir,
"4_update.update")])
modified = self.updater.update([self.testdir + "4_update.update"])
self.assertTrue(modified)
entries = self.ld.get_entries(
@@ -183,8 +176,7 @@ class test_update(unittest.TestCase):
"""
Test the updater adding a new value to a multi-valued attribute (test_5_update)
"""
modified = self.updater.update([os.path.join(self.testdir,
"5_update.update")])
modified = self.updater.update([self.testdir + "5_update.update"])
self.assertTrue(modified)
entries = self.ld.get_entries(
@@ -197,8 +189,7 @@ class test_update(unittest.TestCase):
"""
Test the updater removing a value from a multi-valued attribute (test_6_update)
"""
modified = self.updater.update([os.path.join(self.testdir,
"6_update.update")])
modified = self.updater.update([self.testdir + "6_update.update"])
self.assertTrue(modified)
entries = self.ld.get_entries(
@@ -211,8 +202,7 @@ class test_update(unittest.TestCase):
"""
Test the updater removing a non-existent value from a multi-valued attribute (test_6_update_1)
"""
modified = self.updater.update([os.path.join(self.testdir,
"6_update.update")])
modified = self.updater.update([self.testdir + "6_update.update"])
self.assertFalse(modified)
entries = self.ld.get_entries(
@@ -226,8 +216,7 @@ class test_update(unittest.TestCase):
Reset the test data to a known initial state (test_7_cleanup)
"""
try:
modified = self.updater.update([os.path.join(self.testdir,
"0_reset.update")])
modified = self.updater.update([self.testdir + "0_reset.update"])
except errors.NotFound:
# Just means the entry doesn't exist yet
modified = True
@@ -235,11 +224,11 @@ class test_update(unittest.TestCase):
self.assertTrue(modified)
with self.assertRaises(errors.NotFound):
self.ld.get_entries(
entries = self.ld.get_entries(
self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
with self.assertRaises(errors.NotFound):
self.ld.get_entries(
entries = self.ld.get_entries(
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
def test_8_badsyntax(self):
@@ -247,13 +236,106 @@ class test_update(unittest.TestCase):
Test the updater with an unknown keyword (test_8_badsyntax)
"""
with self.assertRaises(BadSyntax):
self.updater.update(
[os.path.join(self.testdir, "8_badsyntax.update")])
modified = self.updater.update([self.testdir + "8_badsyntax.update"])
def test_9_badsyntax(self):
"""
Test the updater with an incomplete line (test_9_badsyntax)
"""
with self.assertRaises(BadSyntax):
self.updater.update(
[os.path.join(self.testdir, "9_badsyntax.update")])
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.
"""
# First make sure we're clean
with self.assertRaises(errors.NotFound):
entries = self.ld.get_entries(
self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
with self.assertRaises(errors.NotFound):
entries = self.ld.get_entries(
self.user_dn, self.ld.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.get_entries(
self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
self.assertEqual(len(entries), 1)
entry = entries[0]
objectclasses = entry.get('objectclass')
for item in ('top', 'nsContainer'):
self.assertTrue(item in objectclasses)
self.assertEqual(entry.single_value['cn'], 'test')
entries = self.ld.get_entries(
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
self.assertEqual(len(entries), 1)
entry = entries[0]
objectclasses = entry.get('objectclass')
for item in ('top', 'person', 'posixaccount', 'krbprincipalaux', 'inetuser'):
self.assertTrue(item in objectclasses)
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')
# 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.get_entries(
self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
with self.assertRaises(errors.NotFound):
entries = self.ld.get_entries(
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])