summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/mail/incoming/service.py5
-rw-r--r--src/leap/mail/incoming/tests/test_incoming_mail.py24
2 files changed, 26 insertions, 3 deletions
diff --git a/src/leap/mail/incoming/service.py b/src/leap/mail/incoming/service.py
index 2a3a86a..8d8f3c2 100644
--- a/src/leap/mail/incoming/service.py
+++ b/src/leap/mail/incoming/service.py
@@ -686,6 +686,10 @@ class IncomingMail(Service):
"""
MIME_KEY = "application/pgp-keys"
+ def failed_put_key(failure):
+ logger.info("An error has ocurred adding attached key for %s: %s"
+ % (address, failure.getErrorMessage()))
+
deferreds = []
for attachment in attachments:
if MIME_KEY == attachment.get_content_type():
@@ -694,6 +698,7 @@ class IncomingMail(Service):
attachment.get_payload(),
OpenPGPKey,
address=address)
+ d.addErrback(failed_put_key)
deferreds.append(d)
return defer.gatherResults(deferreds)
diff --git a/src/leap/mail/incoming/tests/test_incoming_mail.py b/src/leap/mail/incoming/tests/test_incoming_mail.py
index 033799d..589ddad 100644
--- a/src/leap/mail/incoming/tests/test_incoming_mail.py
+++ b/src/leap/mail/incoming/tests/test_incoming_mail.py
@@ -30,6 +30,7 @@ from email.parser import Parser
from mock import Mock
from twisted.internet import defer
+from leap.keymanager.errors import KeyAddressMismatch
from leap.keymanager.openpgp import OpenPGPKey
from leap.mail.adaptors import soledad_indexes as fields
from leap.mail.constants import INBOX_NAME
@@ -154,9 +155,6 @@ subject: independence of cyberspace
return d
def testExtractAttachedKey(self):
- """
- Test the OpenPGP header key extraction
- """
KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n..."
message = MIMEMultipart()
@@ -176,6 +174,26 @@ subject: independence of cyberspace
d.addCallback(put_raw_key_called)
return d
+ def testExtractInvalidAttachedKey(self):
+ KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n..."
+
+ message = MIMEMultipart()
+ message.add_header("from", ADDRESS_2)
+ key = MIMEApplication("", "pgp-keys")
+ key.set_payload(KEY)
+ message.attach(key)
+ self.fetcher._keymanager.put_raw_key = Mock(
+ return_value=defer.fail(KeyAddressMismatch()))
+ self.fetcher._keymanager.fetch_key = Mock()
+
+ def put_raw_key_called(_):
+ self.fetcher._keymanager.put_raw_key.assert_called_once_with(
+ KEY, OpenPGPKey, address=ADDRESS_2)
+
+ d = self._do_fetch(message.as_string())
+ d.addCallback(put_raw_key_called)
+ return d
+
def testAddDecryptedHeader(self):
class DummyMsg():
def __init__(self):