summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Boeckel <mathstuf@gmail.com>2015-09-25 01:37:53 -0400
committerLars Wirzenius <liw@liw.fi>2015-10-11 11:41:59 +0300
commit88363ebc8e1f01c7179811da7a11b8ff2b5cd9bb (patch)
tree63679e644840739aab102baf96675277ec55e603
parentefa5dbc284d6fcd07165db283a9736f0796b4edd (diff)
downloadobnam-88363ebc8e1f01c7179811da7a11b8ff2b5cd9bb.tar.gz
encryption_tests: make robust against bad default keyrings
If the default keyring is not pristine, the test suite fails with errors related to gpg not being able to read the keyring. Since the symmetric encryption tests can use an empty keyring, make an empty directory for it. Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
-rw-r--r--obnamlib/encryption_tests.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/obnamlib/encryption_tests.py b/obnamlib/encryption_tests.py
index c695b731..86fd2fa0 100644
--- a/obnamlib/encryption_tests.py
+++ b/obnamlib/encryption_tests.py
@@ -37,6 +37,12 @@ class SymmetricEncryptionTests(unittest.TestCase):
# In these tests, we care about making sure we use the tools right,
# not that the tools themselves work right.
+ def setUp(self):
+ self.gpghome = tempfile.mkdtemp()
+
+ def tearDown(self):
+ shutil.rmtree(self.gpghome)
+
def test_generates_key_of_correct_length(self):
numbits = 16
key = obnamlib.generate_symmetric_key(numbits, filename='/dev/zero')
@@ -50,14 +56,17 @@ class SymmetricEncryptionTests(unittest.TestCase):
def test_encrypts_into_different_string_than_cleartext(self):
cleartext = 'hello world'
key = 'sekr1t'
- encrypted = obnamlib.encrypt_symmetric(cleartext, key)
+ encrypted = obnamlib.encrypt_symmetric(cleartext, key,
+ gpghome=self.gpghome)
self.assertNotEqual(cleartext, encrypted)
def test_encrypt_decrypt_round_trip(self):
cleartext = 'hello, world'
key = 'sekr1t'
- encrypted = obnamlib.encrypt_symmetric(cleartext, key)
- decrypted = obnamlib.decrypt_symmetric(encrypted, key)
+ encrypted = obnamlib.encrypt_symmetric(cleartext, key,
+ gpghome=self.gpghome)
+ decrypted = obnamlib.decrypt_symmetric(encrypted, key,
+ gpghome=self.gpghome)
self.assertEqual(decrypted, cleartext)