summaryrefslogtreecommitdiff
path: root/keymanager/src/leap
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2014-12-29 00:27:27 -0600
committerRuben Pollan <meskio@sindominio.net>2015-01-15 13:10:57 -0600
commitfb74dafe063683441108a198fc09d85b4d68c276 (patch)
tree047b312ffa560a1a81002ef3f022689ad2e13b6c /keymanager/src/leap
parent69d9e05711f138d06b63189eb0fb74b305b1578a (diff)
Return a valid error from gatherResults
Diffstat (limited to 'keymanager/src/leap')
-rw-r--r--keymanager/src/leap/keymanager/__init__.py11
-rw-r--r--keymanager/src/leap/keymanager/tests/test_keymanager.py8
2 files changed, 15 insertions, 4 deletions
diff --git a/keymanager/src/leap/keymanager/__init__.py b/keymanager/src/leap/keymanager/__init__.py
index 5324d429..c4050fa8 100644
--- a/keymanager/src/leap/keymanager/__init__.py
+++ b/keymanager/src/leap/keymanager/__init__.py
@@ -485,8 +485,8 @@ class KeyManager(object):
dpriv = defer.succeed(None)
if sign is not None:
dpriv = self.get_key(sign, ktype, private=True)
- d = defer.gatherResults([dpub, dpriv])
- d.addCallback(encrypt)
+ d = defer.gatherResults([dpub, dpriv], consumeErrors=True)
+ d.addCallbacks(encrypt, self._extract_first_error)
return d
def decrypt(self, data, address, ktype, passphrase=None, verify=None,
@@ -542,10 +542,13 @@ class KeyManager(object):
dpub = self.get_key(verify, ktype, private=False,
fetch_remote=fetch_remote)
dpub.addErrback(lambda f: None if f.check(KeyNotFound) else f)
- d = defer.gatherResults([dpub, dpriv])
- d.addCallback(decrypt)
+ d = defer.gatherResults([dpub, dpriv], consumeErrors=True)
+ d.addCallbacks(decrypt, self._extract_first_error)
return d
+ def _extract_first_error(self, failure):
+ return failure.value.subFailure
+
def sign(self, data, address, ktype, digest_algo='SHA512', clearsign=False,
detach=True, binary=False):
"""
diff --git a/keymanager/src/leap/keymanager/tests/test_keymanager.py b/keymanager/src/leap/keymanager/tests/test_keymanager.py
index dca89e8e..86832bab 100644
--- a/keymanager/src/leap/keymanager/tests/test_keymanager.py
+++ b/keymanager/src/leap/keymanager/tests/test_keymanager.py
@@ -375,6 +375,14 @@ class KeyManagerCryptoTestCase(KeyManagerWithSoledadTestCase):
fetch_remote=False)
self.assertEqual(signingkey.fingerprint, key.fingerprint)
+ def test_keymanager_encrypt_key_not_found(self):
+ km = self._key_manager()
+ d = km._wrapper_map[OpenPGPKey].put_ascii_key(PRIVATE_KEY, ADDRESS)
+ d.addCallback(
+ lambda _: km.encrypt(self.RAW_DATA, ADDRESS_2, OpenPGPKey,
+ sign=ADDRESS, fetch_remote=False))
+ return self.assertFailure(d, KeyNotFound)
+
import unittest
if __name__ == "__main__":