From 0dd71ff7c3a895e774205231c23720ee7313ad39 Mon Sep 17 00:00:00 2001 From: NavaL Date: Fri, 2 Dec 2016 16:44:36 +0100 Subject: [#625, #851] fixing log typo and adding test making sure encryption error does propagate to mails resources --- .../test/unit/adapter/services/test_mail_sender.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'service/test/unit/adapter') diff --git a/service/test/unit/adapter/services/test_mail_sender.py b/service/test/unit/adapter/services/test_mail_sender.py index 4daa7f24..23951214 100644 --- a/service/test/unit/adapter/services/test_mail_sender.py +++ b/service/test/unit/adapter/services/test_mail_sender.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . from leap.bitmask.mail.outgoing.service import OutgoingMail +from mock import patch from twisted.mail.smtp import User from twisted.trial import unittest @@ -103,6 +104,25 @@ class MailSenderTest(unittest.TestCase): for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]): self.assertTrue(recipient in e.email_error_map) + @defer.inlineCallbacks + def test_keymanager_encrypt_problem_raises_exception(self): + input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org') + + when(OutgoingMail)._maybe_attach_key(any(), any(), any()).thenReturn( + defer.succeed(None)) + when(OutgoingMail)._fix_headers(any(), any(), any()).thenReturn( + defer.succeed((None, mock()))) + when(self._keymanager_mock).encrypt(any(), any(), sign=any(), + fetch_remote=any()).thenReturn(defer.fail(Exception('pretend key expired'))) + + with patch('leap.bitmask.mail.outgoing.service.emit_async'): + try: + yield self.sender.sendmail(input_mail) + self.fail('Exception expected!') + except MailSenderException, e: + for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]): + self.assertTrue(recipient in e.email_error_map) + @defer.inlineCallbacks def test_iterates_over_recipients_and_send_whitout_bcc_field(self): input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org') -- cgit v1.2.3