summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-02-21 09:43:20 -0800
committerDylan Baker <dylan@pnwbakers.com>2018-03-01 10:34:56 -0800
commit7805f34f55f7143e1ebfca982b0654a3ef42e1d0 (patch)
tree508e38cc7de1c0777e122918cdcd157b88526491 /tests
parent62c0e7354d64ddbfbb0130f690a5768185e3eb92 (diff)
Fix crypto
This makes me a little nervous. I wonder if we're better off leaving the bits that gpg works with as bytes while gpg is working with them and do the string transformation later.
Diffstat (limited to 'tests')
-rw-r--r--tests/crypto_test.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/tests/crypto_test.py b/tests/crypto_test.py
index d481d64e..b059cc82 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):
@@ -113,12 +115,12 @@ class TestDetachedSignatureFor(unittest.TestCase):
with gpg.core.Context() as ctx:
_, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)])
- with tempfile.NamedTemporaryFile(delete=False) as f:
+ with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f:
f.write(detached)
sig = f.name
self.addCleanup(os.unlink, f.name)
- with tempfile.NamedTemporaryFile(delete=False) as f:
+ with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f:
f.write(to_sign)
text = f.name
self.addCleanup(os.unlink, f.name)
@@ -363,13 +365,13 @@ class TestEncrypt(unittest.TestCase):
to_encrypt = "this is a string\nof data."
encrypted = crypto.encrypt(to_encrypt, keys=[crypto.get_key(FPR)])
- with tempfile.NamedTemporaryFile(delete=False) as f:
+ with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f:
f.write(encrypted)
enc_file = f.name
self.addCleanup(os.unlink, enc_file)
- dec = subprocess.check_output(['gpg', '--decrypt', enc_file],
- stderr=DEVNULL)
+ dec = helper.try_decode(subprocess.check_output(
+ ['gpg', '--decrypt', enc_file], stderr=DEVNULL))
self.assertEqual(to_encrypt, dec)