summaryrefslogtreecommitdiffstats
path: root/testsuite/Testsrc/Testlib/TestServer/TestEncryption.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-08-08 14:51:35 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-08-09 08:54:01 -0400
commitb228b295546aa82d2dfe588e3e52817e392ddb6a (patch)
tree7e27ac32710fd80bf05b7a4e4465ffb1e1af42b4 /testsuite/Testsrc/Testlib/TestServer/TestEncryption.py
parent2538670ac8cc983be15a2d81494ea82f58cd839b (diff)
downloadbcfg2-b228b295546aa82d2dfe588e3e52817e392ddb6a.tar.gz
bcfg2-b228b295546aa82d2dfe588e3e52817e392ddb6a.tar.bz2
bcfg2-b228b295546aa82d2dfe588e3e52817e392ddb6a.zip
testsuite: Fixed base plugin tests
Diffstat (limited to 'testsuite/Testsrc/Testlib/TestServer/TestEncryption.py')
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestEncryption.py37
1 files changed, 6 insertions, 31 deletions
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestEncryption.py b/testsuite/Testsrc/Testlib/TestServer/TestEncryption.py
index 8f69f3bf0..2267e9d6c 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestEncryption.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestEncryption.py
@@ -35,7 +35,7 @@ baz
@skipUnless(HAS_CRYPTO, "Encryption libraries not found")
def setUp(self):
- pass
+ Bcfg2.Options.setup.algorithm = "aes_256_cbc"
def test_str_crypt(self):
""" test str_encrypt/str_decrypt """
@@ -110,66 +110,41 @@ baz
self.assertRaises(EVPError, ssl_decrypt,
crypted, passwd) # bogus algorithm
- @patch("Bcfg2.Options.get_option_parser")
- def test_get_passphrases(self, mock_get_option_parser):
- setup = Mock()
- setup.cfp.has_section.return_value = False
- mock_get_option_parser.return_value = setup
- self.assertEqual(get_passphrases(), dict())
-
- setup.cfp.has_section.return_value = True
- setup.cfp.options.return_value = ["foo", "bar", CFG_ALGORITHM]
- setup.cfp.get.return_value = "passphrase"
- self.assertItemsEqual(get_passphrases(),
- dict(foo="passphrase",
- bar="passphrase"))
-
- @patch("Bcfg2.Server.Encryption.get_passphrases")
- def test_bruteforce_decrypt(self, mock_passphrases):
+ def test_bruteforce_decrypt(self):
passwd = "a simple passphrase"
crypted = ssl_encrypt(self.plaintext, passwd)
# test with no passphrases given nor in config
- mock_passphrases.return_value = dict()
+ Bcfg2.Options.setup.passphrases = dict()
self.assertRaises(EVPError,
bruteforce_decrypt, crypted)
- mock_passphrases.assert_called_with()
# test with good passphrase given in function call
- mock_passphrases.reset_mock()
self.assertEqual(self.plaintext,
bruteforce_decrypt(crypted,
passphrases=["bogus pass",
passwd,
"also bogus"]))
- self.assertFalse(mock_passphrases.called)
# test with no good passphrase given nor in config
- mock_passphrases.reset_mock()
self.assertRaises(EVPError,
bruteforce_decrypt,
crypted, passphrases=["bogus", "also bogus"])
- self.assertFalse(mock_passphrases.called)
# test with good passphrase in config file
- mock_passphrases.reset_mock()
- mock_passphrases.return_value = dict(bogus="bogus",
- real=passwd,
- bogus2="also bogus")
+ Bcfg2.Options.setup.passphrases = dict(bogus="bogus",
+ real=passwd,
+ bogus2="also bogus")
self.assertEqual(self.plaintext,
bruteforce_decrypt(crypted))
- mock_passphrases.assert_called_with()
# test that passphrases given in function call take
# precedence over config
- mock_passphrases.reset_mock()
self.assertRaises(EVPError,
bruteforce_decrypt, crypted,
passphrases=["bogus", "also bogus"])
- self.assertFalse(mock_passphrases.called)
# test that different algorithms are used
- mock_passphrases.reset_mock()
crypted = ssl_encrypt(self.plaintext, passwd, algorithm=self.algo)
self.assertEqual(self.plaintext,
bruteforce_decrypt(crypted, algorithm=self.algo))