summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/resources/mails_resource.py6
-rw-r--r--service/test/unit/adapter/services/test_mail_sender.py20
2 files changed, 23 insertions, 3 deletions
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py
index 79b8ae4d..93070dd6 100644
--- a/service/pixelated/resources/mails_resource.py
+++ b/service/pixelated/resources/mails_resource.py
@@ -67,7 +67,7 @@ class MailsDeleteResource(Resource):
def render_POST(self, request):
def response_failed(failure):
- log.error(failure, 'something failed')
+ log.error('something failed: %s' % failure.getErrorMessage())
request.finish()
idents = json.loads(request.content.read())['idents']
@@ -175,7 +175,7 @@ class MailsResource(BaseResource):
if isinstance(error.value, SMTPDownException):
respond_json_deferred({'message': str(error.value)}, request, status_code=503)
else:
- log.error(error, 'error occurred while sending')
+ log.error('error occurred while sending: %s' % error.getErrorMessage())
respond_json_deferred({'message': 'an error occurred while sending'}, request, status_code=422)
deferred = self._handle_post(request)
@@ -185,7 +185,7 @@ class MailsResource(BaseResource):
def render_PUT(self, request):
def onError(error):
- log.error(error, 'error saving draft')
+ log.error('error saving draft: %s' % error.getErrorMessage())
respond_json_deferred("", request, status_code=422)
deferred = self._handle_put(request)
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 <http://www.gnu.org/licenses/>.
from leap.bitmask.mail.outgoing.service import OutgoingMail
+from mock import patch
from twisted.mail.smtp import User
from twisted.trial import unittest
@@ -104,6 +105,25 @@ class MailSenderTest(unittest.TestCase):
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')
bccs = input_mail.bcc