diff options
author | Ruben Pollan <meskio@sindominio.net> | 2014-11-03 22:54:15 -0600 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2014-11-04 12:37:01 -0600 |
commit | 6102c35586bb925de2624d3164e6b9e7d8838a0e (patch) | |
tree | 5b11bcbdffd66c6f000aa3bcb6ac4feaeece35fc /src/leap/mail/imap/tests | |
parent | 0f6a093bfbbac2cd738c32287b2316d481ed67f3 (diff) |
Discover public key via attachment
Diffstat (limited to 'src/leap/mail/imap/tests')
-rw-r--r-- | src/leap/mail/imap/tests/test_incoming_mail.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/leap/mail/imap/tests/test_incoming_mail.py b/src/leap/mail/imap/tests/test_incoming_mail.py index 5b72fac..ce6d56a 100644 --- a/src/leap/mail/imap/tests/test_incoming_mail.py +++ b/src/leap/mail/imap/tests/test_incoming_mail.py @@ -24,6 +24,8 @@ Test case for leap.email.imap.fetch import json +from email.mime.application import MIMEApplication +from email.mime.multipart import MIMEMultipart from email.parser import Parser from mock import Mock from twisted.trial import unittest @@ -105,13 +107,13 @@ subject: independence of cyberspace email = self._create_incoming_email(message.as_string()) self._mock_soledad_get_from_index(fields.JUST_MAIL_IDX, [email]) self.fetcher._keymanager.fetch_key = Mock() - d = self.fetcher.fetch() def fetch_key_called(ret): self.fetcher._keymanager.fetch_key.assert_called_once_with( self.FROM_ADDRESS, KEYURL, OpenPGPKey) - d.addCallback(fetch_key_called) + d = self.fetcher.fetch() + d.addCallback(fetch_key_called) return d def testExtractOpenPGPHeaderInvalidUrl(self): @@ -126,12 +128,35 @@ subject: independence of cyberspace email = self._create_incoming_email(message.as_string()) self._mock_soledad_get_from_index(fields.JUST_MAIL_IDX, [email]) self.fetcher._keymanager.fetch_key = Mock() - d = self.fetcher.fetch() def fetch_key_called(ret): self.assertFalse(self.fetcher._keymanager.fetch_key.called) + + d = self.fetcher.fetch() d.addCallback(fetch_key_called) + return d + def testExtractAttachedKey(self): + """ + Test the OpenPGP header key extraction + """ + KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n..." + + message = MIMEMultipart() + message.add_header("from", self.FROM_ADDRESS) + key = MIMEApplication("", "pgp-keys") + key.set_payload(KEY) + message.attach(key) + email = self._create_incoming_email(message.as_string()) + self._mock_soledad_get_from_index(fields.JUST_MAIL_IDX, [email]) + self.fetcher._keymanager.put_raw_key = Mock() + + def put_raw_key_called(ret): + self.fetcher._keymanager.put_raw_key.assert_called_once_with( + KEY, OpenPGPKey, address=self.FROM_ADDRESS) + + d = self.fetcher.fetch() + d.addCallback(put_raw_key_called) return d def _create_incoming_email(self, email_str): |