diff options
Diffstat (limited to 'mail/src/leap')
-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 |
8 files changed, 61 insertions, 20 deletions
diff --git a/mail/src/leap/mail/imap/server.py b/mail/src/leap/mail/imap/server.py index 45c43b72..2b66ba64 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 daa7ccfd..78eb4f88 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 d87dc87b..17388409 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 587b4164..587b4164 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 38af19f8..38af19f8 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 c69c34f0..73c9421a 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 95420470..95420470 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 e48f1291..65c45580 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 |