diff options
-rw-r--r-- | src/leap/bitmask/mail/outgoing/service.py | 20 | ||||
-rw-r--r-- | tests/integration/mail/outgoing/test_outgoing.py | 31 |
2 files changed, 14 insertions, 37 deletions
diff --git a/src/leap/bitmask/mail/outgoing/service.py b/src/leap/bitmask/mail/outgoing/service.py index 18d266ef..4f39691b 100644 --- a/src/leap/bitmask/mail/outgoing/service.py +++ b/src/leap/bitmask/mail/outgoing/service.py @@ -315,23 +315,14 @@ class OutgoingMail(object): emit_async(catalog.SMTP_START_ENCRYPT_AND_SIGN, self._from_address, "%s,%s" % (self._from_address, to_address)) - d = self._maybe_attach_key(origmsg, from_address, to_address) + d = self._attach_key(origmsg, from_address) d.addCallback(maybe_encrypt_and_sign) return d - def _maybe_attach_key(self, origmsg, from_address, to_address): + def _attach_key(self, origmsg, from_address): filename = "%s-email-key.asc" % (from_address,) - def attach_if_address_hasnt_encrypted(to_key): - # if the sign_used flag is true that means that we got an encrypted - # email from this address, because we conly check signatures on - # encrypted emails. In this case we don't attach. - # XXX: this might not be true some time in the future - if to_key.sign_used: - return origmsg - return get_key_and_attach(None) - - def get_key_and_attach(_): + def get_key_and_attach(): d = self._keymanager.get_key(from_address, fetch_remote=False) d.addCallback(attach_key) return d @@ -352,8 +343,9 @@ class OutgoingMail(object): msg.attach(keymsg) return msg - d = self._keymanager.get_key(to_address, fetch_remote=False) - d.addCallbacks(attach_if_address_hasnt_encrypted, get_key_and_attach) + self.log.info("Will send %s public key as an attachment." + % (from_address)) + d = get_key_and_attach() d.addErrback(lambda _: origmsg) return d diff --git a/tests/integration/mail/outgoing/test_outgoing.py b/tests/integration/mail/outgoing/test_outgoing.py index 1a4a7cc0..72731925 100644 --- a/tests/integration/mail/outgoing/test_outgoing.py +++ b/tests/integration/mail/outgoing/test_outgoing.py @@ -96,15 +96,12 @@ class TestOutgoingMail(KeyManagerWithSoledadTestCase): """ def check_decryption(res): decrypted, _ = res - self.assertEqual( - '\n' + self.expected_body, + self.assertIn( + self.expected_body, decrypted, - 'Decrypted text differs from plaintext.') + 'Decrypted text does not contain the original text.') - d = self._set_sign_used(ADDRESS) - d.addCallback( - lambda _: - self.outgoing_mail._maybe_encrypt_and_sign(self.raw, self.dest)) + d = self.outgoing_mail._maybe_encrypt_and_sign(self.raw, self.dest) d.addCallback(self._assert_encrypted) d.addCallback(lambda message: self.km.decrypt( message.get_payload(1).get_payload(), ADDRESS)) @@ -118,17 +115,14 @@ class TestOutgoingMail(KeyManagerWithSoledadTestCase): '""" def check_decryption_and_verify(res): decrypted, signkey = res - self.assertEqual( - '\n' + self.expected_body, + self.assertIn( + self.expected_body, decrypted, - 'Decrypted text differs from plaintext.') + 'Decrypted text does not contain the original text.') self.assertTrue(ADDRESS_2 in signkey.address, "Verification failed") - d = self._set_sign_used(ADDRESS) - d.addCallback( - lambda _: - self.outgoing_mail._maybe_encrypt_and_sign(self.raw, self.dest)) + d = self.outgoing_mail._maybe_encrypt_and_sign(self.raw, self.dest) d.addCallback(self._assert_encrypted) d.addCallback(lambda message: self.km.decrypt( message.get_payload(1).get_payload(), ADDRESS, verify=ADDRESS_2)) @@ -242,15 +236,6 @@ class TestOutgoingMail(KeyManagerWithSoledadTestCase): return self.fail("No public key attachment found") - def _set_sign_used(self, address): - def set_sign(key): - key.sign_used = True - return self.km.put_key(key) - - d = self.km.get_key(address, fetch_remote=False) - d.addCallback(set_sign) - return d - def _assert_encrypted(self, res): message, _ = res self.assertTrue('Content-Type' in message) |