diff options
Diffstat (limited to 'testsuite/Testsrc/Testlib/TestServer/TestPlugin')
-rw-r--r-- | testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py index 81c4837e1..37beaa26c 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py @@ -8,6 +8,7 @@ import genshi.core from Bcfg2.Compat import reduce from mock import Mock, MagicMock, patch from Bcfg2.Server.Plugin.helpers import * +from Bcfg2.Server.Plugin.exceptions import PluginInitError # add all parent testsuite directories to sys.path to allow (most) # relative imports in python 2.4 @@ -34,6 +35,7 @@ def tostring(el): class FakeElementTree(lxml.etree._ElementTree): xinclude = Mock() + parse = Mock class TestFunctions(Bcfg2TestCase): @@ -71,7 +73,7 @@ class TestDatabaseBacked(TestPlugin): self.assertFalse(db._use_db) setattr(Bcfg2.Options.setup, attr, True) - self.assertFalse(db._use_db) + self.assertRaises(PluginInitError, self.get_obj, core) class TestPluginDatabaseModel(Bcfg2TestCase): @@ -771,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 @@ -794,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() @@ -1135,6 +1121,25 @@ class TestInfoXML(TestStructFile): self.assertTrue(inc("Path", name="/etc/bar.conf", negate="true")) self.assertTrue(inc("Path", name="/etc/bar.conf", negate="tRUe")) + def test_include_element_altsrc(self): + ix = self.get_obj() + metadata = Mock() + entry = lxml.etree.Element("Path", name="/etc/bar.conf", + realname="/etc/foo.conf") + inc = lambda tag, **attrs: \ + ix._include_element(lxml.etree.Element(tag, **attrs), + metadata, entry) + + self.assertFalse(inc("Path", name="/etc/bar.conf")) + self.assertFalse(inc("Path", name="/etc/foo.conf", negate="true")) + self.assertFalse(inc("Path", name="/etc/foo.conf", negate="tRuE")) + self.assertTrue(inc("Path", name="/etc/foo.conf")) + self.assertTrue(inc("Path", name="/etc/foo.conf", negate="false")) + self.assertTrue(inc("Path", name="/etc/foo.conf", negate="faLSe")) + self.assertTrue(inc("Path", name="/etc/bar.conf", negate="true")) + self.assertTrue(inc("Path", name="/etc/bar.conf", negate="tRUe")) + + def test_BindEntry(self): ix = self.get_obj() entry = lxml.etree.Element("Path", name=self.path) |