summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2014-04-25 10:55:41 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2014-04-25 10:55:41 -0400
commitcc27d0525f40ae5a7896992f4e42b8b9037d5b22 (patch)
treea8ca451a6fb356b305e56eefd193f2d6b3023898 /testsuite
parent1ed010e2af5df7544dc316984736159de0c8a8ec (diff)
parentc3edef5bd2b55266fee96327f17a093a0fb9cce4 (diff)
downloadbcfg2-cc27d0525f40ae5a7896992f4e42b8b9037d5b22.tar.gz
bcfg2-cc27d0525f40ae5a7896992f4e42b8b9037d5b22.tar.bz2
bcfg2-cc27d0525f40ae5a7896992f4e42b8b9037d5b22.zip
Merge branch 'maint'
Conflicts: misc/bcfg2.spec src/lib/Bcfg2/Client/Client.py src/lib/Bcfg2/Client/Tools/APK.py src/lib/Bcfg2/Client/Tools/MacPorts.py src/lib/Bcfg2/Client/Tools/Pacman.py src/lib/Bcfg2/Client/Tools/YUM.py src/lib/Bcfg2/Server/Admin/Minestruct.py src/lib/Bcfg2/Server/Admin/Pull.py src/lib/Bcfg2/Server/Admin/Viz.py src/lib/Bcfg2/Server/Core.py src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py src/lib/Bcfg2/Server/Plugins/Properties.py src/lib/Bcfg2/settings.py src/sbin/bcfg2-crypt src/sbin/bcfg2-info src/sbin/bcfg2-lint src/sbin/bcfg2-yum-helper testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenerator.py testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py394
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py8
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py24
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenerator.py5
-rw-r--r--testsuite/Testsrc/test_code_checks.py2
5 files changed, 207 insertions, 226 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
index b8534f5a8..500016c9d 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
@@ -48,200 +48,200 @@ test_data = """<Test>
test_xdata = lxml.etree.XML(test_data)
-if can_skip or HAS_AUGEAS:
- class TestPOSIXAugeas(TestPOSIXTool):
- test_obj = POSIXAugeas
-
- applied_commands = dict(
- insert=lxml.etree.Element(
- "Insert", label="Thing",
- path='Test/Children[#attribute/identical = "true"]/Thing'),
- set=lxml.etree.Element("Set", path="Test/Text/#text",
- value="content with spaces"),
- move=lxml.etree.Element(
- "Move", source="Test/Foo",
- destination='Test/Children[#attribute/identical = "false"]/Foo'),
- remove=lxml.etree.Element("Remove", path="Test/Bar"),
- clear=lxml.etree.Element("Clear", path="Test/Empty/#text"),
- setm=lxml.etree.Element(
- "SetMulti", sub="#text", value="same",
- base='Test/Children[#attribute/multi = "true"]/Thing'))
-
- @skipUnless(HAS_AUGEAS, "Python Augeas libraries not found")
- def setUp(self):
- fd, self.tmpfile = tempfile.mkstemp()
- os.fdopen(fd, 'w').write(test_data)
-
- def tearDown(self):
- tmpfile = getattr(self, "tmpfile", None)
- if tmpfile and os.path.exists(tmpfile):
- os.unlink(tmpfile)
-
- def test_fully_specified(self):
- ptool = self.get_obj()
-
- entry = lxml.etree.Element("Path", name="/test", type="augeas")
- self.assertFalse(ptool.fully_specified(entry))
-
- lxml.etree.SubElement(entry, "Set", path="/test", value="test")
- self.assertTrue(ptool.fully_specified(entry))
-
- def test_install(self):
- # this is tested adequately by the other tests
- pass
-
- def test_verify(self):
- # this is tested adequately by the other tests
- pass
-
- @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.verify")
- def _verify(self, commands, mock_verify):
- ptool = self.get_obj()
- mock_verify.return_value = True
-
- entry = lxml.etree.Element("Path", name=self.tmpfile,
- type="augeas", lens="Xml")
- entry.extend(commands)
-
- modlist = []
- self.assertTrue(ptool.verify(entry, modlist))
- mock_verify.assert_called_with(ptool, entry, modlist)
- self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
- test_xdata)
-
- def test_verify_insert(self):
- """ Test successfully verifying an Insert command """
- self._verify([self.applied_commands['insert']])
-
- def test_verify_set(self):
- """ Test successfully verifying a Set command """
- self._verify([self.applied_commands['set']])
-
- def test_verify_move(self):
- """ Test successfully verifying a Move command """
- self._verify([self.applied_commands['move']])
-
- def test_verify_remove(self):
- """ Test successfully verifying a Remove command """
- self._verify([self.applied_commands['remove']])
-
- def test_verify_clear(self):
- """ Test successfully verifying a Clear command """
- self._verify([self.applied_commands['clear']])
-
- def test_verify_set_multi(self):
- """ Test successfully verifying a SetMulti command """
- self._verify([self.applied_commands['setm']])
-
- def test_verify_all(self):
- """ Test successfully verifying multiple commands """
- self._verify(self.applied_commands.values())
-
- @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.install")
- def _install(self, commands, expected, mock_install, **attrs):
- ptool = self.get_obj()
- mock_install.return_value = True
-
- entry = lxml.etree.Element("Path", name=self.tmpfile,
- type="augeas", lens="Xml")
- for key, val in attrs.items():
- entry.set(key, val)
- entry.extend(commands)
-
- self.assertTrue(ptool.install(entry))
- mock_install.assert_called_with(ptool, entry)
- self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
- expected)
-
- def test_install_set_existing(self):
- """ Test setting the value of an existing node """
- expected = copy.deepcopy(test_xdata)
- expected.find("Text").text = "Changed content"
- self._install([lxml.etree.Element("Set", path="Test/Text/#text",
- value="Changed content")],
- expected)
-
- def test_install_set_new(self):
- """ Test setting the value of an new node """
- expected = copy.deepcopy(test_xdata)
- newtext = lxml.etree.SubElement(expected, "NewText")
- newtext.text = "new content"
- self._install([lxml.etree.Element("Set", path="Test/NewText/#text",
- value="new content")],
- expected)
-
- def test_install_remove(self):
- """ Test removing a node """
- expected = copy.deepcopy(test_xdata)
- expected.remove(expected.find("Attrs"))
- self._install(
- [lxml.etree.Element("Remove",
- path='Test/*[#attribute/foo = "foo"]')],
- expected)
-
- def test_install_move(self):
- """ Test moving a node """
- expected = copy.deepcopy(test_xdata)
- foo = expected.xpath("//Foo")[0]
- expected.append(foo)
- self._install(
- [lxml.etree.Element("Move", source='Test/Children/Foo',
- destination='Test/Foo')],
- expected)
-
- def test_install_clear(self):
- """ Test clearing a node """
- # TODO: clearing a node doesn't seem to work with the XML lens
- #
- # % augtool -b
- # augtool> set /augeas/load/Xml/incl[3] "/tmp/test.xml"
- # augtool> load
- # augtool> clear '/files/tmp/test.xml/Test/Text/#text'
- # augtool> save
- # error: Failed to execute command
- # saving failed (run 'print /augeas//error' for details)
- # augtool> print /augeas//error
- #
- # The error isn't useful.
- pass
-
- def test_install_set_multi(self):
- """ Test setting multiple nodes at once """
- expected = copy.deepcopy(test_xdata)
- for thing in expected.xpath("Children[@identical='true']/Thing"):
- thing.text = "same"
- self._install(
- [lxml.etree.Element(
- "SetMulti", value="same",
- base='Test/Children[#attribute/identical = "true"]',
- sub="Thing/#text")],
- expected)
-
- def test_install_insert(self):
- """ Test inserting a node """
- expected = copy.deepcopy(test_xdata)
- children = expected.xpath("Children[@identical='true']")[0]
- thing = lxml.etree.Element("Thing")
- thing.text = "three"
- children.append(thing)
- self._install(
- [lxml.etree.Element(
- "Insert",
- path='Test/Children[#attribute/identical = "true"]/Thing[2]',
- label="Thing", where="after"),
- lxml.etree.Element(
- "Set",
- path='Test/Children[#attribute/identical = "true"]/Thing[3]/#text',
- value="three")],
- expected)
-
- def test_install_initial(self):
- """ Test creating initial content and then modifying it """
- os.unlink(self.tmpfile)
- expected = copy.deepcopy(test_xdata)
- expected.find("Text").text = "Changed content"
- initial = lxml.etree.Element("Initial")
- initial.text = test_data
- modify = lxml.etree.Element("Set", path="Test/Text/#text",
- value="Changed content")
- self._install([initial, modify], expected, current_exists="false")
+class TestPOSIXAugeas(TestPOSIXTool):
+ test_obj = POSIXAugeas
+
+ applied_commands = dict(
+ insert=lxml.etree.Element(
+ "Insert", label="Thing",
+ path='Test/Children[#attribute/identical = "true"]/Thing'),
+ set=lxml.etree.Element("Set", path="Test/Text/#text",
+ value="content with spaces"),
+ move=lxml.etree.Element(
+ "Move", source="Test/Foo",
+ destination='Test/Children[#attribute/identical = "false"]/Foo'),
+ remove=lxml.etree.Element("Remove", path="Test/Bar"),
+ clear=lxml.etree.Element("Clear", path="Test/Empty/#text"),
+ setm=lxml.etree.Element(
+ "SetMulti", sub="#text", value="same",
+ base='Test/Children[#attribute/multi = "true"]/Thing'))
+
+ @skipUnless(HAS_AUGEAS, "Python Augeas libraries not found")
+ def setUp(self):
+ TestPOSIXTool.setUp(self)
+ fd, self.tmpfile = tempfile.mkstemp()
+ os.fdopen(fd, 'w').write(test_data)
+
+ def tearDown(self):
+ tmpfile = getattr(self, "tmpfile", None)
+ if tmpfile and os.path.exists(tmpfile):
+ os.unlink(tmpfile)
+
+ def test_fully_specified(self):
+ ptool = self.get_obj()
+
+ entry = lxml.etree.Element("Path", name="/test", type="augeas")
+ self.assertFalse(ptool.fully_specified(entry))
+
+ lxml.etree.SubElement(entry, "Set", path="/test", value="test")
+ self.assertTrue(ptool.fully_specified(entry))
+
+ def test_install(self):
+ # this is tested adequately by the other tests
+ pass
+
+ def test_verify(self):
+ # this is tested adequately by the other tests
+ pass
+
+ @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.verify")
+ def _verify(self, commands, mock_verify):
+ ptool = self.get_obj()
+ mock_verify.return_value = True
+
+ entry = lxml.etree.Element("Path", name=self.tmpfile,
+ type="augeas", lens="Xml")
+ entry.extend(commands)
+
+ modlist = []
+ self.assertTrue(ptool.verify(entry, modlist))
+ mock_verify.assert_called_with(ptool, entry, modlist)
+ self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
+ test_xdata)
+
+ def test_verify_insert(self):
+ """ Test successfully verifying an Insert command """
+ self._verify([self.applied_commands['insert']])
+
+ def test_verify_set(self):
+ """ Test successfully verifying a Set command """
+ self._verify([self.applied_commands['set']])
+
+ def test_verify_move(self):
+ """ Test successfully verifying a Move command """
+ self._verify([self.applied_commands['move']])
+
+ def test_verify_remove(self):
+ """ Test successfully verifying a Remove command """
+ self._verify([self.applied_commands['remove']])
+
+ def test_verify_clear(self):
+ """ Test successfully verifying a Clear command """
+ self._verify([self.applied_commands['clear']])
+
+ def test_verify_set_multi(self):
+ """ Test successfully verifying a SetMulti command """
+ self._verify([self.applied_commands['setm']])
+
+ def test_verify_all(self):
+ """ Test successfully verifying multiple commands """
+ self._verify(self.applied_commands.values())
+
+ @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.install")
+ def _install(self, commands, expected, mock_install, **attrs):
+ ptool = self.get_obj()
+ mock_install.return_value = True
+
+ entry = lxml.etree.Element("Path", name=self.tmpfile,
+ type="augeas", lens="Xml")
+ for key, val in attrs.items():
+ entry.set(key, val)
+ entry.extend(commands)
+
+ self.assertTrue(ptool.install(entry))
+ mock_install.assert_called_with(ptool, entry)
+ self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
+ expected)
+
+ def test_install_set_existing(self):
+ """ Test setting the value of an existing node """
+ expected = copy.deepcopy(test_xdata)
+ expected.find("Text").text = "Changed content"
+ self._install([lxml.etree.Element("Set", path="Test/Text/#text",
+ value="Changed content")],
+ expected)
+
+ def test_install_set_new(self):
+ """ Test setting the value of an new node """
+ expected = copy.deepcopy(test_xdata)
+ newtext = lxml.etree.SubElement(expected, "NewText")
+ newtext.text = "new content"
+ self._install([lxml.etree.Element("Set", path="Test/NewText/#text",
+ value="new content")],
+ expected)
+
+ def test_install_remove(self):
+ """ Test removing a node """
+ expected = copy.deepcopy(test_xdata)
+ expected.remove(expected.find("Attrs"))
+ self._install(
+ [lxml.etree.Element("Remove",
+ path='Test/*[#attribute/foo = "foo"]')],
+ expected)
+
+ def test_install_move(self):
+ """ Test moving a node """
+ expected = copy.deepcopy(test_xdata)
+ foo = expected.xpath("//Foo")[0]
+ expected.append(foo)
+ self._install(
+ [lxml.etree.Element("Move", source='Test/Children/Foo',
+ destination='Test/Foo')],
+ expected)
+
+ def test_install_clear(self):
+ """ Test clearing a node """
+ # TODO: clearing a node doesn't seem to work with the XML lens
+ #
+ # % augtool -b
+ # augtool> set /augeas/load/Xml/incl[3] "/tmp/test.xml"
+ # augtool> load
+ # augtool> clear '/files/tmp/test.xml/Test/Text/#text'
+ # augtool> save
+ # error: Failed to execute command
+ # saving failed (run 'print /augeas//error' for details)
+ # augtool> print /augeas//error
+ #
+ # The error isn't useful.
+ pass
+
+ def test_install_set_multi(self):
+ """ Test setting multiple nodes at once """
+ expected = copy.deepcopy(test_xdata)
+ for thing in expected.xpath("Children[@identical='true']/Thing"):
+ thing.text = "same"
+ self._install(
+ [lxml.etree.Element(
+ "SetMulti", value="same",
+ base='Test/Children[#attribute/identical = "true"]',
+ sub="Thing/#text")],
+ expected)
+
+ def test_install_insert(self):
+ """ Test inserting a node """
+ expected = copy.deepcopy(test_xdata)
+ children = expected.xpath("Children[@identical='true']")[0]
+ thing = lxml.etree.Element("Thing")
+ thing.text = "three"
+ children.append(thing)
+ self._install(
+ [lxml.etree.Element(
+ "Insert",
+ path='Test/Children[#attribute/identical = "true"]/Thing[2]',
+ label="Thing", where="after"),
+ lxml.etree.Element(
+ "Set",
+ path='Test/Children[#attribute/identical = "true"]/Thing[3]/#text',
+ value="three")],
+ expected)
+
+ def test_install_initial(self):
+ """ Test creating initial content and then modifying it """
+ os.unlink(self.tmpfile)
+ expected = copy.deepcopy(test_xdata)
+ expected.find("Text").text = "Changed content"
+ initial = lxml.etree.Element("Initial")
+ initial.text = test_data
+ modify = lxml.etree.Element("Set", path="Test/Text/#text",
+ value="Changed content")
+ self._install([initial, modify], expected, current_exists="false")
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
index 9647413b6..cc1ea6fd7 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
@@ -26,10 +26,10 @@ class TestPOSIXUsers(TestTool):
def setUp(self):
TestTool.setUp(self)
- set_setup_default('uid_whitelist')
- set_setup_default('uid_blacklist')
- set_setup_default('gid_whitelist')
- set_setup_default('gid_blacklist')
+ set_setup_default('uid_whitelist', [])
+ set_setup_default('uid_blacklist', [])
+ set_setup_default('gid_whitelist', [])
+ set_setup_default('gid_blacklist', [])
set_setup_default('encoding', 'UTF-8')
def get_obj(self, config=None):
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py
index 75bd4ec95..1f8449bb6 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py
@@ -773,19 +773,15 @@ class TestStructFile(TestXMLFileBacked):
@skipUnless(HAS_CRYPTO, "No crypto libraries found, skipping")
@patchIf(HAS_CRYPTO, "Bcfg2.Server.Encryption.ssl_decrypt")
- @patchIf(HAS_CRYPTO, "Bcfg2.Server.Encryption.bruteforce_decrypt")
- def test_decrypt(self, mock_bruteforce, mock_ssl):
+ def test_decrypt(self, mock_ssl):
sf = self.get_obj()
def reset():
- mock_bruteforce.reset_mock()
mock_ssl.reset_mock()
-
# test element without text contents
Bcfg2.Options.setup.passphrases = dict()
self.assertIsNone(sf._decrypt(lxml.etree.Element("Test")))
- self.assertFalse(mock_bruteforce.called)
self.assertFalse(mock_ssl.called)
# test element with a passphrase in the config file
@@ -796,29 +792,17 @@ class TestStructFile(TestXMLFileBacked):
mock_ssl.return_value = "decrypted with ssl"
self.assertEqual(sf._decrypt(el), mock_ssl.return_value)
mock_ssl.assert_called_with(el.text, "foopass")
- self.assertFalse(mock_bruteforce.called)
-
- # test failure to decrypt element with a passphrase in the config
- reset()
- mock_ssl.side_effect = EVPError
- self.assertRaises(EVPError, sf._decrypt, el)
- mock_ssl.assert_called_with(el.text, "foopass")
- self.assertFalse(mock_bruteforce.called)
# test element without valid passphrase
reset()
el.set("encrypted", "true")
- mock_bruteforce.return_value = "decrypted with bruteforce"
- self.assertEqual(sf._decrypt(el), mock_bruteforce.return_value)
- mock_bruteforce.assert_called_with(el.text)
+ self.assertRaises(EVPError, sf._decrypt, el)
self.assertFalse(mock_ssl.called)
- # test failure to decrypt element without valid passphrase
+ # test failure to decrypt element with a passphrase in the config
reset()
- mock_bruteforce.side_effect = EVPError
+ mock_ssl.side_effect = EVPError
self.assertRaises(EVPError, sf._decrypt, el)
- mock_bruteforce.assert_called_with(el.text)
- self.assertFalse(mock_ssl.called)
def test_include_element(self):
sf = self.get_obj()
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenerator.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenerator.py
index 03b9fb0f4..7989bf514 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenerator.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenerator.py
@@ -22,14 +22,11 @@ from TestServer.TestPlugins.TestCfg.Test_init import TestCfgGenerator
class TestCfgEncryptedGenerator(TestCfgGenerator):
test_obj = CfgEncryptedGenerator
- @skipUnless(HAS_CRYPTO, "Encryption libraries not found, skipping")
- def setUp(self):
- TestCfgGenerator.setUp(self)
-
@patchIf(HAS_CRYPTO,
"Bcfg2.Server.Plugins.Cfg.CfgEncryptedGenerator.bruteforce_decrypt")
def test_handle_event(self, mock_decrypt):
@patch("Bcfg2.Server.Plugins.Cfg.CfgGenerator.handle_event")
+ @patch("Bcfg2.Options.setup.lax_decryption", False)
def inner(mock_handle_event):
def reset():
mock_decrypt.reset_mock()
diff --git a/testsuite/Testsrc/test_code_checks.py b/testsuite/Testsrc/test_code_checks.py
index 17fac4fe4..2b8b05926 100644
--- a/testsuite/Testsrc/test_code_checks.py
+++ b/testsuite/Testsrc/test_code_checks.py
@@ -327,7 +327,7 @@ class TestPylint(CodeTestCase):
class TestPEP8(CodeTestCase):
__test__ = True
- command = ["pep8", "--ignore=E125,E501"]
+ command = ["pep8", "--ignore=E125,E129,E501"]
def _test_errors(self, files, extra_args=None):
pass