summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
authorNavaL <mnandri@thoughtworks.com>2016-01-27 19:29:36 +0100
committerNavaL <mnandri@thoughtworks.com>2016-01-28 10:43:14 +0100
commit766c5617007650d90f1d249aaa253755dcd1906c (patch)
treeebe66b6219cbbab28b5101a72a3338210c69f99c /service/test
parent29f0bd4576955536d3714b1c095bcfe387ec51b9 (diff)
making async setup user services after auth
Issue #583
Diffstat (limited to 'service/test')
-rw-r--r--service/test/support/integration/multi_user_client.py34
-rw-r--r--service/test/unit/resources/test_login_resource.py9
2 files changed, 32 insertions, 11 deletions
diff --git a/service/test/support/integration/multi_user_client.py b/service/test/support/integration/multi_user_client.py
index 13e1b64b..67b034cc 100644
--- a/service/test/support/integration/multi_user_client.py
+++ b/service/test/support/integration/multi_user_client.py
@@ -14,19 +14,36 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-from leap.auth import SRPAuth
+import json
+import shutil
+
from leap.exceptions import SRPAuthenticationError
-from mockito import mock, when
+from leap.mail.imap.account import IMAPAccount
+from mockito import mock, when, any as ANY
+from twisted.cred import portal
+from twisted.cred.checkers import AllowAnonymousAccess
from twisted.internet import defer
+from leap.auth import SRPAuth
+
+from pixelated.adapter.mailstore.leap_attachment_store import LeapAttachmentStore
+from pixelated.adapter.services.feedback_service import FeedbackService
from pixelated.application import UserAgentMode, ServicesFactory, set_up_protected_resources
+
+from pixelated.adapter.mailstore import LeapMailStore
+from pixelated.adapter.mailstore.searchable_mailstore import SearchableMailStore
+
+from pixelated.adapter.search import SearchEngine
+from pixelated.adapter.services.draft_service import DraftService
from pixelated.bitmask_libraries.session import LeapSession, LeapSessionFactory
import pixelated.config.services
# from pixelated.config.services import Services
+from pixelated.resources.auth import LeapPasswordChecker, SessionChecker, PixelatedRealm, PixelatedAuthSessionWrapper
+from pixelated.resources.login_resource import LoginResource
from pixelated.resources.root_resource import RootResource
from test.support.integration import AppTestClient
-from test.support.integration.app_test_client import AppTestAccount
-
+from test.support.integration.app_test_client import initialize_soledad, AppTestAccount
+import test.support.mockito
from test.support.test_helper import request_mock
@@ -58,18 +75,19 @@ class MultiUserClient(AppTestClient):
leap_session.config = config
leap_session.fresh_account = False
- self._set_leap_srp_auth(username, password)
+ mock_srp_auth = 'mocked so irrelevant but just need a return value'
+ self._set_leap_srp_auth(username, password, mock_srp_auth)
+ when(LeapSessionFactory).create(username, password, mock_srp_auth).thenReturn(leap_session)
when(leap_session).initial_sync().thenAnswer(lambda: defer.succeed(None))
- when(LeapSessionFactory).create(username, password).thenReturn(leap_session)
when(pixelated.config.services).Services(ANY()).thenReturn(self._test_account.services)
request = request_mock(path='/login', method="POST", body={'username': username, 'password': password})
return self._render(request, as_json=False)
- def _set_leap_srp_auth(self, username, password):
+ def _set_leap_srp_auth(self, username, password, mock_srp_auth):
auth_dict = {'username': 'password'}
if auth_dict[username] == password:
- when(SRPAuth).authenticate(username, password).thenReturn(True)
+ when(SRPAuth).authenticate(username, password).thenReturn(mock_srp_auth)
else:
when(SRPAuth).authenticate(username, password).thenRaise(SRPAuthenticationError())
diff --git a/service/test/unit/resources/test_login_resource.py b/service/test/unit/resources/test_login_resource.py
index 1ccc530d..0baf7ac0 100644
--- a/service/test/unit/resources/test_login_resource.py
+++ b/service/test/unit/resources/test_login_resource.py
@@ -1,3 +1,5 @@
+import os
+
from leap.exceptions import SRPAuthenticationError
from mock import patch
from mockito import mock, when, any as ANY, verify, verifyZeroInteractions
@@ -93,7 +95,7 @@ class TestLoginPOST(unittest.TestCase):
@patch('twisted.web.util.redirectTo')
@patch('pixelated.config.services.Services.setup')
- def test_login_setups_user_services_and_add_corresponding_session_to_services_factory(self, mock_service_setup, mock_redirect):
+ def test_login_responds_interstitial_and_add_corresponding_session_to_services_factory(self, mock_service_setup, mock_redirect):
irrelevant = None
when(self.portal).login(ANY(), None, IResource).thenReturn((irrelevant, self.leap_user, irrelevant))
d = self.web.get(self.request)
@@ -101,7 +103,8 @@ class TestLoginPOST(unittest.TestCase):
def assert_login_setup_service_for_user(_):
verify(self.portal).login(ANY(), None, IResource)
verify(self.services_factory).create_services_from(self.leap_session)
- mock_redirect.assert_called_once_with('/', self.request)
+ interstitial_js_in_template = '<script src="startup-assets/Interstitial.js"></script>'
+ self.assertIn(interstitial_js_in_template, self.request.written[0])
self.assertTrue(self.resource.is_logged_in(self.request))
d.addCallback(assert_login_setup_service_for_user)
@@ -143,12 +146,12 @@ class TestLoginPOST(unittest.TestCase):
@patch('pixelated.resources.session.PixelatedSession.is_logged_in')
def test_should_not_process_login_if_already_logged_in(self, mock_logged_in, mock_redirect):
mock_logged_in.return_value = True
+ mock_redirect.return_value = "mocked redirection"
when(self.portal).login(ANY(), None, IResource).thenRaise(Exception())
d = self.web.get(self.request)
def assert_login_setup_service_for_user(_):
verifyZeroInteractions(self.portal)
- self.assertEqual(200, self.request.responseCode)
mock_redirect.assert_called_once_with('/', self.request)
d.addCallback(assert_login_setup_service_for_user)