diff options
Diffstat (limited to 'tests/crypto_test.py')
-rw-r--r-- | tests/crypto_test.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/tests/crypto_test.py b/tests/crypto_test.py index d481d64e..f6c02a7e 100644 --- a/tests/crypto_test.py +++ b/tests/crypto_test.py @@ -14,6 +14,7 @@ import gpg import mock from alot import crypto +from alot import helper from alot.errors import GPGProblem, GPGCode from . import utilities @@ -57,7 +58,8 @@ def tearDownModule(): # Kill any gpg-agent's that have been opened lookfor = 'gpg-agent --homedir {}'.format(os.environ['GNUPGHOME']) - out = subprocess.check_output(['ps', 'xo', 'pid,cmd'], stderr=DEVNULL) + out = helper.try_decode( + subprocess.check_output(['ps', 'xo', 'pid,cmd'], stderr=DEVNULL)) for each in out.strip().split('\n'): pid, cmd = each.strip().split(' ', 1) if cmd.startswith(lookfor): @@ -109,7 +111,7 @@ class TestHashAlgorithmHelper(unittest.TestCase): class TestDetachedSignatureFor(unittest.TestCase): def test_valid_signature_generated(self): - to_sign = "this is some text.\nit is more than nothing.\n" + to_sign = b"this is some text.\nit is more than nothing.\n" with gpg.core.Context() as ctx: _, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)]) @@ -131,7 +133,7 @@ class TestDetachedSignatureFor(unittest.TestCase): class TestVerifyDetached(unittest.TestCase): def test_verify_signature_good(self): - to_sign = "this is some text.\nIt's something\n." + to_sign = b"this is some text.\nIt's something\n." with gpg.core.Context() as ctx: _, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)]) @@ -141,8 +143,8 @@ class TestVerifyDetached(unittest.TestCase): raise AssertionError def test_verify_signature_bad(self): - to_sign = "this is some text.\nIt's something\n." - similar = "this is some text.\r\n.It's something\r\n." + to_sign = b"this is some text.\nIt's something\n." + similar = b"this is some text.\r\n.It's something\r\n." with gpg.core.Context() as ctx: _, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)]) @@ -360,7 +362,7 @@ class TestGetKey(unittest.TestCase): class TestEncrypt(unittest.TestCase): def test_encrypt(self): - to_encrypt = "this is a string\nof data." + to_encrypt = b"this is a string\nof data." encrypted = crypto.encrypt(to_encrypt, keys=[crypto.get_key(FPR)]) with tempfile.NamedTemporaryFile(delete=False) as f: @@ -368,15 +370,14 @@ class TestEncrypt(unittest.TestCase): enc_file = f.name self.addCleanup(os.unlink, enc_file) - dec = subprocess.check_output(['gpg', '--decrypt', enc_file], - stderr=DEVNULL) + dec = subprocess.check_output(['gpg', '--decrypt', enc_file], stderr=DEVNULL) self.assertEqual(to_encrypt, dec) class TestDecrypt(unittest.TestCase): def test_decrypt(self): - to_encrypt = "this is a string\nof data." + to_encrypt = b"this is a string\nof data." encrypted = crypto.encrypt(to_encrypt, keys=[crypto.get_key(FPR)]) _, dec = crypto.decrypt_verify(encrypted) self.assertEqual(to_encrypt, dec) |