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 | c55892d69a2a9b8873b979c37a8d17ddfad39560 (patch) | |
tree | 3a96b5870d4830b28bce2f989e94da88cea7d0eb /src/leap/mail | |
parent | 9a5a325831230687a7da4ad5300c99f03aebba72 (diff) |
Adapt smtp relay to latest soledad and keymanager.
Diffstat (limited to 'src/leap/mail')
-rw-r--r-- | src/leap/mail/imap/server.py | 9 | ||||
-rw-r--r-- | src/leap/mail/smtp/__init__.py | 2 | ||||
-rw-r--r-- | src/leap/mail/smtp/smtprelay.py | 7 | ||||
-rw-r--r-- | src/leap/mail/smtp/tests/185CA770.key (renamed from src/leap/mail/tests/smtp/185CA770.key) | 0 | ||||
-rw-r--r-- | src/leap/mail/smtp/tests/185CA770.pub (renamed from src/leap/mail/tests/smtp/185CA770.pub) | 0 | ||||
-rw-r--r-- | src/leap/mail/smtp/tests/__init__.py (renamed from src/leap/mail/tests/smtp/__init__.py) | 59 | ||||
-rw-r--r-- | src/leap/mail/smtp/tests/mail.txt (renamed from src/leap/mail/tests/smtp/mail.txt) | 0 | ||||
-rw-r--r-- | src/leap/mail/smtp/tests/test_smtprelay.py (renamed from src/leap/mail/tests/smtp/test_smtprelay.py) | 4 |
8 files changed, 61 insertions, 20 deletions
diff --git a/src/leap/mail/imap/server.py b/src/leap/mail/imap/server.py index 45c43b7..2b66ba6 100644 --- a/src/leap/mail/imap/server.py +++ b/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/src/leap/mail/smtp/__init__.py b/src/leap/mail/smtp/__init__.py index daa7ccf..78eb4f8 100644 --- a/src/leap/mail/smtp/__init__.py +++ b/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/src/leap/mail/smtp/smtprelay.py b/src/leap/mail/smtp/smtprelay.py index d87dc87..1738840 100644 --- a/src/leap/mail/smtp/smtprelay.py +++ b/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/src/leap/mail/tests/smtp/185CA770.key b/src/leap/mail/smtp/tests/185CA770.key index 587b416..587b416 100644 --- a/src/leap/mail/tests/smtp/185CA770.key +++ b/src/leap/mail/smtp/tests/185CA770.key diff --git a/src/leap/mail/tests/smtp/185CA770.pub b/src/leap/mail/smtp/tests/185CA770.pub index 38af19f..38af19f 100644 --- a/src/leap/mail/tests/smtp/185CA770.pub +++ b/src/leap/mail/smtp/tests/185CA770.pub diff --git a/src/leap/mail/tests/smtp/__init__.py b/src/leap/mail/smtp/tests/__init__.py index c69c34f..73c9421 100644 --- a/src/leap/mail/tests/smtp/__init__.py +++ b/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/src/leap/mail/tests/smtp/mail.txt b/src/leap/mail/smtp/tests/mail.txt index 9542047..9542047 100644 --- a/src/leap/mail/tests/smtp/mail.txt +++ b/src/leap/mail/smtp/tests/mail.txt diff --git a/src/leap/mail/tests/smtp/test_smtprelay.py b/src/leap/mail/smtp/tests/test_smtprelay.py index e48f129..65c4558 100644 --- a/src/leap/mail/tests/smtp/test_smtprelay.py +++ b/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 |