diff options
author | drebs <drebs@leap.se> | 2013-06-13 16:22:16 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2013-07-22 14:46:29 -0300 |
commit | 48868afb477eb605057b8063afb72e427a494877 (patch) | |
tree | c53d1a94640acbc46f853a12862cc7c08cb5516f | |
parent | 24b7abec9d56d868bd31bd1e8ea1be4766776b09 (diff) |
Adapt smtp relay to latest soledad and keymanager.
-rw-r--r-- | mail/setup.py | 1 | ||||
-rw-r--r-- | mail/src/leap/mail/imap/server.py | 9 | ||||
-rw-r--r-- | mail/src/leap/mail/smtp/__init__.py | 2 | ||||
-rw-r--r-- | mail/src/leap/mail/smtp/smtprelay.py | 7 | ||||
-rw-r--r-- | mail/src/leap/mail/smtp/tests/185CA770.key (renamed from mail/src/leap/mail/tests/smtp/185CA770.key) | 0 | ||||
-rw-r--r-- | mail/src/leap/mail/smtp/tests/185CA770.pub (renamed from mail/src/leap/mail/tests/smtp/185CA770.pub) | 0 | ||||
-rw-r--r-- | mail/src/leap/mail/smtp/tests/__init__.py (renamed from mail/src/leap/mail/tests/smtp/__init__.py) | 59 | ||||
-rw-r--r-- | mail/src/leap/mail/smtp/tests/mail.txt (renamed from mail/src/leap/mail/tests/smtp/mail.txt) | 0 | ||||
-rw-r--r-- | mail/src/leap/mail/smtp/tests/test_smtprelay.py (renamed from mail/src/leap/mail/tests/smtp/test_smtprelay.py) | 4 |
9 files changed, 62 insertions, 20 deletions
diff --git a/mail/setup.py b/mail/setup.py index 8d4e415..f0713bf 100644 --- a/mail/setup.py +++ b/mail/setup.py @@ -22,6 +22,7 @@ from setuptools import setup, find_packages requirements = [ "leap.soledad", "leap.common>=0.2.3-dev", + "leap.keymanager>=0.2.1", "twisted", ] diff --git a/mail/src/leap/mail/imap/server.py b/mail/src/leap/mail/imap/server.py index 45c43b7..2b66ba6 100644 --- a/mail/src/leap/mail/imap/server.py +++ b/mail/src/leap/mail/imap/server.py @@ -772,7 +772,7 @@ class LeapMessage(WithMsgFields): return None -class MessageCollection(WithMsgFields): +class MessageCollection(WithMsgFields, IndexedDB): """ A collection of messages, surprisingly. @@ -795,6 +795,10 @@ class MessageCollection(WithMsgFields): WithMsgFields.RAW_KEY: "", } + # get from SoledadBackedAccount the needed index-related constants + INDEXES = SoledadBackedAccount.INDEXES + TYPE_IDX = SoledadBackedAccount.TYPE_IDX + def __init__(self, mbox=None, soledad=None): """ Constructor for MessageCollection. @@ -1131,8 +1135,7 @@ class SoledadMailbox(WithMsgFields): """ return map(str, self.INIT_FLAGS) - # TODO -- returning hardcoded flags for now, - # no need of setting flags. + # XXX CHECK against thunderbird XXX #mbox = self._get_mbox() #if not mbox: diff --git a/mail/src/leap/mail/smtp/__init__.py b/mail/src/leap/mail/smtp/__init__.py index daa7ccf..78eb4f8 100644 --- a/mail/src/leap/mail/smtp/__init__.py +++ b/mail/src/leap/mail/smtp/__init__.py @@ -22,8 +22,6 @@ SMTP relay helper function. from twisted.internet import reactor -#from leap import soledad -#from leap.common.keymanager import KeyManager from leap.mail.smtp.smtprelay import SMTPFactory diff --git a/mail/src/leap/mail/smtp/smtprelay.py b/mail/src/leap/mail/smtp/smtprelay.py index d87dc87..1738840 100644 --- a/mail/src/leap/mail/smtp/smtprelay.py +++ b/mail/src/leap/mail/smtp/smtprelay.py @@ -21,7 +21,6 @@ LEAP SMTP encrypted relay. import re import os -import gnupg import tempfile @@ -38,13 +37,13 @@ from email.parser import Parser from leap.common.check import leap_assert, leap_assert_type -from leap.common.keymanager import KeyManager -from leap.common.keymanager.openpgp import ( +from leap.keymanager import KeyManager +from leap.keymanager.openpgp import ( OpenPGPKey, encrypt_asym, sign, ) -from leap.common.keymanager.errors import KeyNotFound +from leap.keymanager.errors import KeyNotFound # diff --git a/mail/src/leap/mail/tests/smtp/185CA770.key b/mail/src/leap/mail/smtp/tests/185CA770.key index 587b416..587b416 100644 --- a/mail/src/leap/mail/tests/smtp/185CA770.key +++ b/mail/src/leap/mail/smtp/tests/185CA770.key diff --git a/mail/src/leap/mail/tests/smtp/185CA770.pub b/mail/src/leap/mail/smtp/tests/185CA770.pub index 38af19f..38af19f 100644 --- a/mail/src/leap/mail/tests/smtp/185CA770.pub +++ b/mail/src/leap/mail/smtp/tests/185CA770.pub diff --git a/mail/src/leap/mail/tests/smtp/__init__.py b/mail/src/leap/mail/smtp/tests/__init__.py index c69c34f..73c9421 100644 --- a/mail/src/leap/mail/tests/smtp/__init__.py +++ b/mail/src/leap/mail/smtp/tests/__init__.py @@ -30,8 +30,7 @@ from twisted.trial import unittest from leap.soledad import Soledad -from leap.soledad.crypto import SoledadCrypto -from leap.common.keymanager import ( +from leap.keymanager import ( KeyManager, openpgp, ) @@ -59,26 +58,53 @@ class TestCaseWithKeyManager(BaseLeapTest): address = 'leap@leap.se' # user's address in the form user@provider uuid = 'leap@leap.se' passphrase = '123' - secret_path = os.path.join(self.tempdir, 'secret.gpg') + 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._soledad = self._soledad_instance( + uuid, passphrase, secrets_path, local_db_path, server_url, + cert_file) + self._km = self._keymanager_instance(address) + + 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) # instantiate soledad - self._soledad = Soledad( + def _put_doc_side_effect(doc): + self._doc_put = doc + + class MockSharedDB(object): + + get_doc = Mock(return_value=None) + put_doc = Mock(side_effect=_put_doc_side_effect) + + def __call__(self): + return self + + Soledad._shared_db = MockSharedDB() + + return Soledad( uuid, passphrase, - secret_path, - local_db_path, - server_url, - cert_file, + secrets_path=secrets_path, + local_db_path=local_db_path, + server_url=server_url, + cert_file=cert_file, ) + def _keymanager_instance(self, address): + """ + Return a Key Manager instance for tests. + """ self._config = { 'host': 'http://provider/', 'port': 25, @@ -87,14 +113,29 @@ class TestCaseWithKeyManager(BaseLeapTest): 'encrypted_only': True } + class Response(object): + status_code = 200 + headers = {'content-type': 'application/json'} + + def json(self): + return {'address': ADDRESS_2, 'openpgp': PUBLIC_KEY_2} + + def raise_for_status(self): + pass + nickserver_url = '' # the url of the nickserver - self._km = KeyManager(address, nickserver_url, self._soledad) + km = KeyManager(address, nickserver_url, self._soledad, + ca_cert_path='') + km._fetcher.put = Mock() + km._fetcher.get = Mock(return_value=Response()) # insert test keys in key manager. pgp = openpgp.OpenPGPScheme(self._soledad) pgp.put_ascii_key(PRIVATE_KEY) pgp.put_ascii_key(PRIVATE_KEY_2) + return km + def tearDown(self): # mimic LeapBaseTest.tearDownClass behaviour os.environ["PATH"] = self.old_path diff --git a/mail/src/leap/mail/tests/smtp/mail.txt b/mail/src/leap/mail/smtp/tests/mail.txt index 9542047..9542047 100644 --- a/mail/src/leap/mail/tests/smtp/mail.txt +++ b/mail/src/leap/mail/smtp/tests/mail.txt diff --git a/mail/src/leap/mail/tests/smtp/test_smtprelay.py b/mail/src/leap/mail/smtp/tests/test_smtprelay.py index e48f129..65c4558 100644 --- a/mail/src/leap/mail/tests/smtp/test_smtprelay.py +++ b/mail/src/leap/mail/smtp/tests/test_smtprelay.py @@ -38,12 +38,12 @@ from leap.mail.smtp.smtprelay import ( SMTPFactory, EncryptedMessage, ) -from leap.mail.tests.smtp import ( +from leap.mail.smtp.tests import ( TestCaseWithKeyManager, ADDRESS, ADDRESS_2, ) -from leap.common.keymanager import openpgp +from leap.keymanager import openpgp # some regexps |