summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-12-16 21:04:01 +0200
committerKali Kaneko <kali@leap.se>2017-12-22 20:03:30 +0100
commit90503627ef5047cd7e6e253266f0b25f2b1daa4d (patch)
treec4e5908db4d5e81e97a4d0f920af7ef44b5ab971 /tests
parentf4a3c23be148a822352d484c263ead0e4fd2b907 (diff)
[refactor] Use sender interface in outgoing service
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/mail/outgoing/test_outgoing.py21
-rw-r--r--tests/integration/mail/smtp/test_gateway.py9
-rw-r--r--tests/unit/mail/outgoing/test_service.py2
3 files changed, 16 insertions, 16 deletions
diff --git a/tests/integration/mail/outgoing/test_outgoing.py b/tests/integration/mail/outgoing/test_outgoing.py
index 72731925..e2787a8b 100644
--- a/tests/integration/mail/outgoing/test_outgoing.py
+++ b/tests/integration/mail/outgoing/test_outgoing.py
@@ -32,6 +32,7 @@ from mock import Mock
from leap.bitmask.mail.rfc3156 import RFC3156CompliantGenerator
from leap.bitmask.mail.outgoing.service import OutgoingMail
+from leap.bitmask.mail.outgoing.sender import SMTPSender
from leap.bitmask.mail.testing import ADDRESS, ADDRESS_2, PUBLIC_KEY_2
from leap.bitmask.mail.testing import KeyManagerWithSoledadTestCase
from leap.bitmask.mail.testing.smtp import getSMTPFactory
@@ -75,9 +76,9 @@ class TestOutgoingMail(KeyManagerWithSoledadTestCase):
self.opts = opts
def init_outgoing_and_proto(_):
- self.outgoing_mail = OutgoingMail(
- self.fromAddr, self.km, opts.cert,
- opts.key, opts.hostname, opts.port)
+ self.outgoing = OutgoingMail(self.fromAddr, self.km)
+ self.outgoing.add_sender(
+ SMTPSender(self.fromAddr, opts.key, opts.hostname, opts.port))
user = TEST_USER
@@ -101,7 +102,7 @@ class TestOutgoingMail(KeyManagerWithSoledadTestCase):
decrypted,
'Decrypted text does not contain the original text.')
- d = self.outgoing_mail._maybe_encrypt_and_sign(self.raw, self.dest)
+ d = self.outgoing._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))
@@ -122,7 +123,7 @@ class TestOutgoingMail(KeyManagerWithSoledadTestCase):
self.assertTrue(ADDRESS_2 in signkey.address,
"Verification failed")
- d = self.outgoing_mail._maybe_encrypt_and_sign(self.raw, self.dest)
+ d = self.outgoing._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))
@@ -139,9 +140,7 @@ class TestOutgoingMail(KeyManagerWithSoledadTestCase):
return_value=fail(errors.KeyNotFound()))
recipient = User('ihavenopubkey@nonleap.se',
'gateway.leap.se', self.proto, ADDRESS)
- self.outgoing_mail = OutgoingMail(
- self.fromAddr, self.km, self.opts.cert, self.opts.key,
- self.opts.hostname, self.opts.port)
+ self.outgoing = OutgoingMail(self.fromAddr, self.km)
def check_signed(res):
message, _ = res
@@ -187,13 +186,13 @@ class TestOutgoingMail(KeyManagerWithSoledadTestCase):
return d
# TODO shouldn't depend on private method on this test
- d = self.outgoing_mail._maybe_encrypt_and_sign(self.raw, recipient)
+ d = self.outgoing._maybe_encrypt_and_sign(self.raw, recipient)
d.addCallback(check_signed)
d.addCallback(verify)
return d
def test_attach_key(self):
- d = self.outgoing_mail._maybe_encrypt_and_sign(self.raw, self.dest)
+ d = self.outgoing._maybe_encrypt_and_sign(self.raw, self.dest)
d.addCallback(self._assert_encrypted)
d.addCallback(self._check_headers, self.lines[:4])
d.addCallback(lambda message: self.km.decrypt(
@@ -209,7 +208,7 @@ class TestOutgoingMail(KeyManagerWithSoledadTestCase):
raw = '\r\n'.join(lines)
dest = User(unknown_address, 'gateway.leap.se', self.proto, ADDRESS_2)
- d = self.outgoing_mail._maybe_encrypt_and_sign(
+ d = self.outgoing._maybe_encrypt_and_sign(
raw, dest, fetch_remote=False)
d.addCallback(lambda (message, _):
self._check_headers(message, lines[:4]))
diff --git a/tests/integration/mail/smtp/test_gateway.py b/tests/integration/mail/smtp/test_gateway.py
index aac90b50..254ee029 100644
--- a/tests/integration/mail/smtp/test_gateway.py
+++ b/tests/integration/mail/smtp/test_gateway.py
@@ -29,6 +29,7 @@ from twisted.test import proto_helpers
from mock import Mock
from leap.bitmask.keymanager import openpgp, errors
+from leap.bitmask.mail.outgoing.service import OutgoingMail
from leap.bitmask.mail.testing import KeyManagerWithSoledadTestCase
from leap.bitmask.mail.testing import ADDRESS, ADDRESS_2
from leap.bitmask.mail.testing.smtp import getSMTPFactory, TEST_USER
@@ -91,7 +92,8 @@ class TestSmtpGateway(KeyManagerWithSoledadTestCase):
'354 Continue']
user = TEST_USER
- proto = getSMTPFactory({user: None}, {user: self.km}, {user: None})
+ proto = getSMTPFactory({user: OutgoingMail(user, self.km)},
+ {user: None})
transport = proto_helpers.StringTransport()
proto.makeConnection(transport)
reply = ""
@@ -117,7 +119,7 @@ class TestSmtpGateway(KeyManagerWithSoledadTestCase):
return_value=fail(errors.KeyNotFound()))
user = TEST_USER
proto = getSMTPFactory(
- {user: None}, {user: self.km}, {user: None},
+ {user: OutgoingMail(user, self.km)}, {user: None},
encrypted_only=True)
transport = proto_helpers.StringTransport()
proto.makeConnection(transport)
@@ -147,7 +149,8 @@ class TestSmtpGateway(KeyManagerWithSoledadTestCase):
self.km._fetch_keys_from_server_and_store_local = Mock(
return_value=fail(errors.KeyNotFound()))
user = TEST_USER
- proto = getSMTPFactory({user: None}, {user: self.km}, {user: None})
+ proto = getSMTPFactory({user: OutgoingMail(user, self.km)},
+ {user: None})
transport = proto_helpers.StringTransport()
proto.makeConnection(transport)
yield self.getReply(self.EMAIL_DATA[0] + '\r\n', proto, transport)
diff --git a/tests/unit/mail/outgoing/test_service.py b/tests/unit/mail/outgoing/test_service.py
index 9200397b..7b6df847 100644
--- a/tests/unit/mail/outgoing/test_service.py
+++ b/tests/unit/mail/outgoing/test_service.py
@@ -36,7 +36,6 @@ class TestService(unittest.TestCase):
def test_send_error_bounces_if_bouncer_is_provided(self):
bouncer = MagicMock()
outgoing_mail = OutgoingMail(self.from_address, self.keymanager,
- self.cert, self.key, self.host, self.port,
bouncer)
failure = Failure(exc_value=Exception())
@@ -48,7 +47,6 @@ class TestService(unittest.TestCase):
def test_send_error_raises_exception_if_there_is_no_bouncer(self):
bouncer = None
outgoing_mail = OutgoingMail(self.from_address, self.keymanager,
- self.cert, self.key, self.host, self.port,
bouncer)
failure = Failure(exc_value=Exception('smtp error'))