diff options
Diffstat (limited to 'mail/src/leap')
-rw-r--r-- | mail/src/leap/mail/adaptors/tests/__init__.py | 0 | ||||
-rw-r--r-- | mail/src/leap/mail/incoming/tests/__init__.py | 0 | ||||
-rw-r--r-- | mail/src/leap/mail/outgoing/tests/__init__.py | 0 | ||||
-rw-r--r-- | mail/src/leap/mail/smtp/tests/__init__.py | 0 | ||||
-rw-r--r-- | mail/src/leap/mail/testing/__init__.py (renamed from mail/src/leap/mail/imap/tests/__init__.py) | 250 | ||||
-rw-r--r-- | mail/src/leap/mail/testing/__init__.py~ (renamed from mail/src/leap/mail/tests/__init__.py) | 150 | ||||
-rw-r--r-- | mail/src/leap/mail/testing/common.py (renamed from mail/src/leap/mail/tests/common.py) | 18 | ||||
-rw-r--r-- | mail/src/leap/mail/testing/imap.py (renamed from mail/src/leap/mail/imap/tests/utils.py) | 2 | ||||
-rw-r--r-- | mail/src/leap/mail/testing/rfc822.multi-encrypt-signed.message (renamed from mail/src/leap/mail/incoming/tests/rfc822.multi-encrypt-signed.message) | 0 | ||||
-rw-r--r-- | mail/src/leap/mail/testing/smtp.py | 51 |
10 files changed, 325 insertions, 146 deletions
diff --git a/mail/src/leap/mail/adaptors/tests/__init__.py b/mail/src/leap/mail/adaptors/tests/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/mail/src/leap/mail/adaptors/tests/__init__.py +++ /dev/null diff --git a/mail/src/leap/mail/incoming/tests/__init__.py b/mail/src/leap/mail/incoming/tests/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/mail/src/leap/mail/incoming/tests/__init__.py +++ /dev/null diff --git a/mail/src/leap/mail/outgoing/tests/__init__.py b/mail/src/leap/mail/outgoing/tests/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/mail/src/leap/mail/outgoing/tests/__init__.py +++ /dev/null diff --git a/mail/src/leap/mail/smtp/tests/__init__.py b/mail/src/leap/mail/smtp/tests/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/mail/src/leap/mail/smtp/tests/__init__.py +++ /dev/null diff --git a/mail/src/leap/mail/imap/tests/__init__.py b/mail/src/leap/mail/testing/__init__.py index 5aa7364..982be55 100644 --- a/mail/src/leap/mail/imap/tests/__init__.py +++ b/mail/src/leap/mail/testing/__init__.py @@ -1,110 +1,141 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- +# __init__.py +# Copyright (C) 2013 LEAP +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. """ -leap/email/imap/tests/__init__.py ----------------------------------- -Module intialization file for leap.mx.tests, a module containing unittesting -code, using twisted.trial, for testing leap_mx. - -@authors: Kali Kaneko, <kali@leap.se> -@license: GPLv3, see included LICENSE file -@copyright: © 2013 Kali Kaneko, see COPYLEFT file +Base classes and keys for leap.mail tests. """ - import os -from leap.soledad.common import l2db +import distutils.spawn +from mock import Mock +from twisted.internet.defer import gatherResults, succeed +from twisted.trial import unittest +from twisted.web.client import Response +from twisted.internet import defer +from twisted.python import log -from leap.common.testing.basetest import BaseLeapTest from leap.soledad.client import Soledad -from leap.soledad.common.document import SoledadDocument +from leap.keymanager import KeyManager -__all__ = ['test_imap'] +from leap.common.testing.basetest import BaseLeapTest + +ADDRESS = 'leap@leap.se' +ADDRESS_2 = 'anotheruser@leap.se' -def run(): - """xxx fill me in""" - pass +class defaultMockSharedDB(object): + get_doc = Mock(return_value=None) + put_doc = Mock(side_effect=None) + open = Mock(return_value=None) + close = Mock(return_value=None) + syncable = True -# ----------------------------------------------------------------------------- -# Some tests inherit from BaseSoledadTest in order to have a working Soledad -# instance in each test. -# ----------------------------------------------------------------------------- + def __call__(self): + return self -class BaseSoledadIMAPTest(BaseLeapTest): - """ - Instantiates GPG and Soledad for usage in LeapIMAPServer tests. - Copied from BaseSoledadTest, but moving setup to classmethod - """ +class KeyManagerWithSoledadTestCase(unittest.TestCase, BaseLeapTest): def setUp(self): - # open test dbs - self.db1_file = os.path.join( - self.tempdir, "db1.u1db") - self.db2_file = os.path.join( - self.tempdir, "db2.u1db") + self.gpg_binary_path = self._find_gpg() - self._db1 = l2db.open(self.db1_file, create=True, - document_factory=SoledadDocument) - self._db2 = l2db.open(self.db2_file, create=True, - document_factory=SoledadDocument) + self._soledad = Soledad( + u"leap@leap.se", + u"123456", + secrets_path=self.tempdir + "/secret.gpg", + local_db_path=self.tempdir + "/soledad.u1db", + server_url='', + cert_file=None, + auth_token=None, + shared_db=defaultMockSharedDB(), + syncable=False) - # soledad config info - self.email = 'leap@leap.se' - secrets_path = os.path.join( - self.tempdir, Soledad.STORAGE_SECRETS_FILE_NAME) - local_db_path = os.path.join( - self.tempdir, Soledad.LOCAL_DATABASE_FILE_NAME) - server_url = '' - cert_file = None + self.km = self._key_manager() - self._soledad = self._soledad_instance( - self.email, '123', - secrets_path=secrets_path, - local_db_path=local_db_path, - server_url=server_url, - cert_file=cert_file) + class Response(object): + code = 200 + phrase = '' + def deliverBody(self, x): + return '' - def _soledad_instance(self, uuid, passphrase, secrets_path, local_db_path, - server_url, cert_file): - """ - Return a Soledad instance for tests. - """ - # mock key fetching and storing so Soledad doesn't fail when trying to - # reach the server. - Soledad._fetch_keys_from_shared_db = Mock(return_value=None) - Soledad._assert_keys_in_shared_db = Mock(return_value=None) + # XXX why the fuck is this needed? ------------------------ + self.km._async_client_pinned.request = Mock( + return_value=defer.succeed(Response())) + #self.km._async_client.request = Mock(return_value='') + #self.km._async_client_pinned.request = Mock( + #return_value='') + # ------------------------------------------------------- - # instantiate soledad - def _put_doc_side_effect(doc): - self._doc_put = doc + d1 = self.km.put_raw_key(PRIVATE_KEY, ADDRESS) + d2 = self.km.put_raw_key(PRIVATE_KEY_2, ADDRESS_2) + return gatherResults([d1, d2]) - class MockSharedDB(object): + def tearDown(self): + km = self._key_manager() + # wait for the indexes to be ready for the tear down + d = km._openpgp.deferred_init + d.addCallback(lambda _: self.delete_all_keys(km)) + d.addCallback(lambda _: self._soledad.close()) + return d - get_doc = Mock(return_value=None) - put_doc = Mock(side_effect=_put_doc_side_effect) + def delete_all_keys(self, km): + def delete_keys(keys): + deferreds = [] + for key in keys: + d = km._openpgp.delete_key(key) + deferreds.append(d) + return gatherResults(deferreds) - def __call__(self): - return self + def check_deleted(_, private): + d = km.get_all_keys(private=private) + d.addCallback(lambda keys: self.assertEqual(keys, [])) + return d - Soledad._shared_db = MockSharedDB() + deferreds = [] + for private in [True, False]: + d = km.get_all_keys(private=private) + d.addCallback(delete_keys) + d.addCallback(check_deleted, private) + deferreds.append(d) + return gatherResults(deferreds) - return Soledad( - uuid, - passphrase, - secrets_path=secrets_path, - local_db_path=local_db_path, - server_url=server_url, - cert_file=cert_file, - ) + def _key_manager(self, user=ADDRESS, url='', token=None, + ca_cert_path=None): + return KeyManager(user, url, self._soledad, token=token, + gpgbinary=self.gpg_binary_path, + ca_cert_path=ca_cert_path) - def tearDown(self): - self._db1.close() - self._db2.close() - self._soledad.close() + def _find_gpg(self): + gpg_path = distutils.spawn.find_executable('gpg') + if gpg_path is not None: + return os.path.realpath(gpg_path) + else: + return "/usr/bin/gpg" + + def get_public_binary_key(self): + with open(PATH + '/fixtures/public_key.bin', 'r') as binary_public_key: + return binary_public_key.read() + + def get_private_binary_key(self): + with open( + PATH + '/fixtures/private_key.bin', 'r') as binary_private_key: + return binary_private_key.read() -# Key material for testing +# key 24D18DDF: public key "Leap Test Key <leap@leap.se>" KEY_FINGERPRINT = "E36E738D69173C13D709E44F2F455E2824D18DDF" PUBLIC_KEY = """ -----BEGIN PGP PUBLIC KEY BLOCK----- @@ -266,3 +297,62 @@ RZXoH+FTg9UAW87eqU610npOkT6cRaBxaMK/mDtGNdc= =JTFu -----END PGP PRIVATE KEY BLOCK----- """ + +# key 7FEE575A: public key "anotheruser <anotheruser@leap.se>" +PUBLIC_KEY_2 = """ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.4.10 (GNU/Linux) + +mI0EUYwJXgEEAMbTKHuPJ5/Gk34l9Z06f+0WCXTDXdte1UBoDtZ1erAbudgC4MOR +gquKqoj3Hhw0/ILqJ88GcOJmKK/bEoIAuKaqlzDF7UAYpOsPZZYmtRfPC2pTCnXq +Z1vdeqLwTbUspqXflkCkFtfhGKMq5rH8GV5a3tXZkRWZhdNwhVXZagC3ABEBAAG0 +IWFub3RoZXJ1c2VyIDxhbm90aGVydXNlckBsZWFwLnNlPoi4BBMBAgAiBQJRjAle +AhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRB/nfpof+5XWotuA/4tLN4E +gUr7IfLy2HkHAxzw7A4rqfMN92DIM9mZrDGaWRrOn3aVF7VU1UG7MDkHfPvp/cFw +ezoCw4s4IoHVc/pVlOkcHSyt4/Rfh248tYEJmFCJXGHpkK83VIKYJAithNccJ6Q4 +JE/o06Mtf4uh/cA1HUL4a4ceqUhtpLJULLeKo7iNBFGMCV4BBADsyQI7GR0wSAxz +VayLjuPzgT+bjbFeymIhjuxKIEwnIKwYkovztW+4bbOcQs785k3Lp6RzvigTpQQt +Z/hwcLOqZbZw8t/24+D+Pq9mMP2uUvCFFqLlVvA6D3vKSQ/XNN+YB919WQ04jh63 +yuRe94WenT1RJd6xU1aaUff4rKizuQARAQABiJ8EGAECAAkFAlGMCV4CGwwACgkQ +f536aH/uV1rPZQQAqCzRysOlu8ez7PuiBD4SebgRqWlxa1TF1ujzfLmuPivROZ2X +Kw5aQstxgGSjoB7tac49s0huh4X8XK+BtJBfU84JS8Jc2satlfwoyZ35LH6sDZck +I+RS/3we6zpMfHs3vvp9xgca6ZupQxivGtxlJs294TpJorx+mFFqbV17AzQ= +=Thdu +-----END PGP PUBLIC KEY BLOCK----- +""" + +PRIVATE_KEY_2 = """ +-----BEGIN PGP PRIVATE KEY BLOCK----- +Version: GnuPG v1.4.10 (GNU/Linux) + +lQHYBFGMCV4BBADG0yh7jyefxpN+JfWdOn/tFgl0w13bXtVAaA7WdXqwG7nYAuDD +kYKriqqI9x4cNPyC6ifPBnDiZiiv2xKCALimqpcwxe1AGKTrD2WWJrUXzwtqUwp1 +6mdb3Xqi8E21LKal35ZApBbX4RijKuax/BleWt7V2ZEVmYXTcIVV2WoAtwARAQAB +AAP7BLuSAx7tOohnimEs74ks8l/L6dOcsFQZj2bqs4AoY3jFe7bV0tHr4llypb/8 +H3/DYvpf6DWnCjyUS1tTnXSW8JXtx01BUKaAufSmMNg9blKV6GGHlT/Whe9uVyks +7XHk/+9mebVMNJ/kNlqq2k+uWqJohzC8WWLRK+d1tBeqDsECANZmzltPaqUsGV5X +C3zszE3tUBgptV/mKnBtopKi+VH+t7K6fudGcG+bAcZDUoH/QVde52mIIjjIdLje +uajJuHUCAO1mqh+vPoGv4eBLV7iBo3XrunyGXiys4a39eomhxTy3YktQanjjx+ty +GltAGCs5PbWGO6/IRjjvd46wh53kzvsCAO0J97gsWhzLuFnkxFAJSPk7RRlyl7lI +1XS/x0Og6j9XHCyY1OYkfBm0to3UlCfkgirzCYlTYObCofzdKFIPDmSqHbQhYW5v +dGhlcnVzZXIgPGFub3RoZXJ1c2VyQGxlYXAuc2U+iLgEEwECACIFAlGMCV4CGwMG +CwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEH+d+mh/7ldai24D/i0s3gSBSvsh +8vLYeQcDHPDsDiup8w33YMgz2ZmsMZpZGs6fdpUXtVTVQbswOQd8++n9wXB7OgLD +izgigdVz+lWU6RwdLK3j9F+Hbjy1gQmYUIlcYemQrzdUgpgkCK2E1xwnpDgkT+jT +oy1/i6H9wDUdQvhrhx6pSG2kslQst4qjnQHYBFGMCV4BBADsyQI7GR0wSAxzVayL +juPzgT+bjbFeymIhjuxKIEwnIKwYkovztW+4bbOcQs785k3Lp6RzvigTpQQtZ/hw +cLOqZbZw8t/24+D+Pq9mMP2uUvCFFqLlVvA6D3vKSQ/XNN+YB919WQ04jh63yuRe +94WenT1RJd6xU1aaUff4rKizuQARAQABAAP9EyElqJ3dq3EErXwwT4mMnbd1SrVC +rUJrNWQZL59mm5oigS00uIyR0SvusOr+UzTtd8ysRuwHy5d/LAZsbjQStaOMBILx +77TJveOel0a1QK0YSMF2ywZMCKvquvjli4hAtWYz/EwfuzQN3t23jc5ny+GqmqD2 +3FUxLJosFUfLNmECAO9KhVmJi+L9dswIs+2Dkjd1eiRQzNOEVffvYkGYZyKxNiXF +UA5kvyZcB4iAN9sWCybE4WHZ9jd4myGB0MPDGxkCAP1RsXJbbuD6zS7BXe5gwunO +2q4q7ptdSl/sJYQuTe1KNP5d/uGsvlcFfsYjpsopasPjFBIncc/2QThMKlhoEaEB +/0mVAxpT6SrEvUbJ18z7kna24SgMPr3OnPMxPGfvNLJY/Xv/A17YfoqjmByCvsKE +JCDjopXtmbcrZyoEZbEht9mko4ifBBgBAgAJBQJRjAleAhsMAAoJEH+d+mh/7lda +z2UEAKgs0crDpbvHs+z7ogQ+Enm4EalpcWtUxdbo83y5rj4r0TmdlysOWkLLcYBk +o6Ae7WnOPbNIboeF/FyvgbSQX1POCUvCXNrGrZX8KMmd+Sx+rA2XJCPkUv98Hus6 +THx7N776fcYHGumbqUMYrxrcZSbNveE6SaK8fphRam1dewM0 +=a5gs +-----END PGP PRIVATE KEY BLOCK----- +""" diff --git a/mail/src/leap/mail/tests/__init__.py b/mail/src/leap/mail/testing/__init__.py~ index 962bbe3..ffaadd8 100644 --- a/mail/src/leap/mail/tests/__init__.py +++ b/mail/src/leap/mail/testing/__init__.py~ @@ -20,8 +20,11 @@ Base classes and keys for leap.mail tests. import os import distutils.spawn from mock import Mock -from twisted.internet.defer import gatherResults +from twisted.internet.defer import gatherResults, succeed from twisted.trial import unittest +from twisted.web.client import Response +from twisted.internet import defer +from twisted.python import log from leap.soledad.client import Soledad @@ -30,83 +33,110 @@ from leap.keymanager import KeyManager from leap.common.testing.basetest import BaseLeapTest +ADDRESS = 'leap@leap.se' +ADDRESS_2 = 'anotheruser@leap.se' -def _find_gpg(): - gpg_path = distutils.spawn.find_executable('gpg') - return (os.path.realpath(gpg_path) - if gpg_path is not None else "/usr/bin/gpg") +class defaultMockSharedDB(object): + get_doc = Mock(return_value=None) + put_doc = Mock(side_effect=None) + open = Mock(return_value=None) + close = Mock(return_value=None) + syncable = True + def __call__(self): + return self -class TestCaseWithKeyManager(unittest.TestCase, BaseLeapTest): - GPG_BINARY_PATH = _find_gpg() +class KeyManagerWithSoledadTestCase(unittest.TestCase, BaseLeapTest): def setUp(self): - self.setUpEnv() - - # setup our own stuff - address = 'leap@leap.se' # user's address in the form user@provider - uuid = 'leap@leap.se' - passphrase = u'123' - secrets_path = os.path.join(self.tempdir, 'secret.gpg') - local_db_path = os.path.join(self.tempdir, 'soledad.u1db') - server_url = 'http://provider/' - cert_file = '' + self.gpg_binary_path = self._find_gpg() self._soledad = Soledad( - uuid, - passphrase, - secrets_path=secrets_path, - local_db_path=local_db_path, - server_url=server_url, - cert_file=cert_file, - syncable=False - ) - return self._setup_keymanager(address) + u"leap@leap.se", + u"123456", + secrets_path=self.tempdir + "/secret.gpg", + local_db_path=self.tempdir + "/soledad.u1db", + server_url='', + cert_file=None, + auth_token=None, + shared_db=defaultMockSharedDB(), + syncable=False) - def _setup_keymanager(self, address): - """ - Set up Key Manager and return a Deferred that will be fired when done. - """ - self._config = { - 'host': 'https://provider/', - 'port': 25, - 'username': address, - 'password': '<password>', - 'encrypted_only': True, - 'cert': u'src/leap/mail/smtp/tests/cert/server.crt', - 'key': u'src/leap/mail/smtp/tests/cert/server.key', - } + self.km = self._key_manager() class Response(object): - status_code = 200 - headers = {'content-type': 'application/json'} - - def json(self): - return {'address': ADDRESS_2, 'openpgp': PUBLIC_KEY_2} + code = 200 + phrase = '' + def deliverBody(self, x): + return - def raise_for_status(self): - pass + # XXX why the fuck is this needed? ------------------------ + self.km._async_client_pinned.request = Mock( + return_value=defer.succeed(Response())) + #self.km._async_client.request = Mock(return_value='') + #self.km._async_client_pinned.request = Mock( + #return_value='') + # ------------------------------------------------------- - nickserver_url = '' # the url of the nickserver - self._km = KeyManager(address, nickserver_url, self._soledad, - gpgbinary=self.GPG_BINARY_PATH) - self._km._async_client.request = Mock(return_value="") - self._km._async_client_pinned.request = Mock(return_value="") - - d1 = self._km.put_raw_key(PRIVATE_KEY, ADDRESS) - d2 = self._km.put_raw_key(PRIVATE_KEY_2, ADDRESS_2) + d1 = self.km.put_raw_key(PRIVATE_KEY, ADDRESS) + d2 = self.km.put_raw_key(PRIVATE_KEY_2, ADDRESS_2) return gatherResults([d1, d2]) def tearDown(self): - self.tearDownEnv() + km = self._key_manager() + # wait for the indexes to be ready for the tear down + d = km._openpgp.deferred_init + d.addCallback(lambda _: self.delete_all_keys(km)) + d.addCallback(lambda _: self._soledad.close()) + return d + def delete_all_keys(self, km): + def delete_keys(keys): + deferreds = [] + for key in keys: + d = km._openpgp.delete_key(key) + deferreds.append(d) + return gatherResults(deferreds) -# Key material for testing -KEY_FINGERPRINT = "E36E738D69173C13D709E44F2F455E2824D18DDF" + def check_deleted(_, private): + d = km.get_all_keys(private=private) + d.addCallback(lambda keys: self.assertEqual(keys, [])) + return d -ADDRESS = 'leap@leap.se' + deferreds = [] + for private in [True, False]: + d = km.get_all_keys(private=private) + d.addCallback(delete_keys) + d.addCallback(check_deleted, private) + deferreds.append(d) + return gatherResults(deferreds) + + def _key_manager(self, user=ADDRESS, url='', token=None, + ca_cert_path=None): + return KeyManager(user, url, self._soledad, token=token, + gpgbinary=self.gpg_binary_path, + ca_cert_path=ca_cert_path) + def _find_gpg(self): + gpg_path = distutils.spawn.find_executable('gpg') + if gpg_path is not None: + return os.path.realpath(gpg_path) + else: + return "/usr/bin/gpg" + + def get_public_binary_key(self): + with open(PATH + '/fixtures/public_key.bin', 'r') as binary_public_key: + return binary_public_key.read() + + def get_private_binary_key(self): + with open( + PATH + '/fixtures/private_key.bin', 'r') as binary_private_key: + return binary_private_key.read() + + +# key 24D18DDF: public key "Leap Test Key <leap@leap.se>" +KEY_FINGERPRINT = "E36E738D69173C13D709E44F2F455E2824D18DDF" PUBLIC_KEY = """ -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.10 (GNU/Linux) @@ -160,7 +190,6 @@ ZtQ/VymwFL3XdUWV6B/hU4PVAFvO3qlOtdJ6TpE+nEWgcWjCv5g7RjXX =MuOY -----END PGP PUBLIC KEY BLOCK----- """ - PRIVATE_KEY = """ -----BEGIN PGP PRIVATE KEY BLOCK----- Version: GnuPG v1.4.10 (GNU/Linux) @@ -269,8 +298,7 @@ RZXoH+FTg9UAW87eqU610npOkT6cRaBxaMK/mDtGNdc= -----END PGP PRIVATE KEY BLOCK----- """ -ADDRESS_2 = 'anotheruser@leap.se' - +# key 7FEE575A: public key "anotheruser <anotheruser@leap.se>" PUBLIC_KEY_2 = """ -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.10 (GNU/Linux) diff --git a/mail/src/leap/mail/tests/common.py b/mail/src/leap/mail/testing/common.py index 6ef5d17..1bf1de2 100644 --- a/mail/src/leap/mail/tests/common.py +++ b/mail/src/leap/mail/testing/common.py @@ -18,7 +18,6 @@ Common utilities for testing Soledad. """ import os -import shutil import tempfile from twisted.internet import defer @@ -70,9 +69,13 @@ class SoledadTestMixin(unittest.TestCase, BaseLeapTest): def setUp(self): self.results = [] - self.setUpEnv() + # pytest handles correctly the setupEnv for the class, + # but trial ignores it. + if not getattr(self, 'tempdir', None): + self.tempdir = tempfile.gettempdir() + # Soledad: config info self.gnupg_home = "%s/gnupg" % self.tempdir self.email = 'leap@leap.se' @@ -95,5 +98,12 @@ class SoledadTestMixin(unittest.TestCase, BaseLeapTest): except Exception: print "ERROR WHILE CLOSING SOLEDAD" # logging.exception(exc) - finally: - self.tearDownEnv() + self.tearDownEnv() + + @classmethod + def setUpClass(self): + pass + + @classmethod + def tearDownClass(self): + pass diff --git a/mail/src/leap/mail/imap/tests/utils.py b/mail/src/leap/mail/testing/imap.py index 64a0326..72acbf2 100644 --- a/mail/src/leap/mail/imap/tests/utils.py +++ b/mail/src/leap/mail/testing/imap.py @@ -33,7 +33,7 @@ from zope.interface import implementer from leap.mail.adaptors import soledad as soledad_adaptor from leap.mail.imap.account import IMAPAccount from leap.mail.imap.server import LEAPIMAPServer -from leap.mail.tests.common import SoledadTestMixin +from leap.mail.testing.common import SoledadTestMixin TEST_USER = "testuser@leap.se" TEST_PASSWD = "1234" diff --git a/mail/src/leap/mail/incoming/tests/rfc822.multi-encrypt-signed.message b/mail/src/leap/mail/testing/rfc822.multi-encrypt-signed.message index 98304f2..98304f2 100644 --- a/mail/src/leap/mail/incoming/tests/rfc822.multi-encrypt-signed.message +++ b/mail/src/leap/mail/testing/rfc822.multi-encrypt-signed.message diff --git a/mail/src/leap/mail/testing/smtp.py b/mail/src/leap/mail/testing/smtp.py new file mode 100644 index 0000000..d8690f1 --- /dev/null +++ b/mail/src/leap/mail/testing/smtp.py @@ -0,0 +1,51 @@ +from twisted.mail import smtp + +from leap.mail.smtp.gateway import SMTPFactory, LOCAL_FQDN +from leap.mail.smtp.gateway import SMTPDelivery +from leap.mail.outgoing.service import outgoingFactory + +TEST_USER = u'anotheruser@leap.se' + + +class UnauthenticatedSMTPServer(smtp.SMTP): + + encrypted_only = False + + def __init__(self, soledads, keyms, opts, encrypted_only=False): + smtp.SMTP.__init__(self) + + userid = TEST_USER + keym = keyms[userid] + + class Opts: + cert = '/tmp/cert' + key = '/tmp/cert' + hostname = 'remote' + port = 666 + + outgoing = outgoingFactory( + userid, keym, Opts, check_cert=False) + avatar = SMTPDelivery(userid, keym, encrypted_only, outgoing) + self.delivery = avatar + + def validateFrom(self, helo, origin): + return origin + + +class UnauthenticatedSMTPFactory(SMTPFactory): + """ + A Factory that produces a SMTP server that does not authenticate user. + Only for tests! + """ + protocol = UnauthenticatedSMTPServer + domain = LOCAL_FQDN + encrypted_only = False + + +def getSMTPFactory(soledad_s, keymanager_s, sendmail_opts, + encrypted_only=False): + factory = UnauthenticatedSMTPFactory + factory.encrypted_only = encrypted_only + proto = factory( + soledad_s, keymanager_s, sendmail_opts).buildProtocol(('127.0.0.1', 0)) + return proto |