diff options
author | NavaL <mnandri@thoughtworks.com> | 2016-02-03 17:23:42 +0100 |
---|---|---|
committer | NavaL <mnandri@thoughtworks.com> | 2016-02-05 14:43:07 +0100 |
commit | e7f77052f0aba1b84febf0ab1382c9602bbf7f93 (patch) | |
tree | 5fd8dd1016cbb21ebd4572284ca84f24bd9ccfa1 /service/test/unit | |
parent | 92f0e9887a216e0ec82355941655d3deebf2d422 (diff) |
closing the services closes leap session, which stops background tasks, close soldedad and remove it from cache
Issue #586
Diffstat (limited to 'service/test/unit')
-rw-r--r-- | service/test/unit/bitmask_libraries/test_session.py | 24 | ||||
-rw-r--r-- | service/test/unit/config/test_services.py | 34 | ||||
-rw-r--r-- | service/test/unit/resources/test_login_resource.py | 8 | ||||
-rw-r--r-- | service/test/unit/resources/test_logout_resources.py | 3 |
4 files changed, 67 insertions, 2 deletions
diff --git a/service/test/unit/bitmask_libraries/test_session.py b/service/test/unit/bitmask_libraries/test_session.py index 6e0e6204..bb1f55ca 100644 --- a/service/test/unit/bitmask_libraries/test_session.py +++ b/service/test/unit/bitmask_libraries/test_session.py @@ -17,7 +17,7 @@ from mock import patch from mock import MagicMock -from pixelated.bitmask_libraries.session import LeapSession +from pixelated.bitmask_libraries.session import LeapSession, SessionCache from test_abstract_leap import AbstractLeapTest from leap.common.events.catalog import KEYMANAGER_FINISHED_KEY_GENERATION @@ -69,6 +69,28 @@ class SessionTest(AbstractLeapTest): unregister_mock.assert_called_once_with(KEYMANAGER_FINISHED_KEY_GENERATION, uid=email) + def test_close_stops_soledad(self): + email = 'someone@somedomain.tld' + self.provider.address_for.return_value = email + session = self._create_session() + + session.close() + self.soledad_session.close.assert_called_once_with() + + def test_close_removes_session_from_cache(self): + email = 'someone@somedomain.tld' + self.provider.address_for.return_value = email + session = self._create_session() + + key = SessionCache.session_key(self.provider, self.auth.username) + SessionCache.remember_session(key, session) + + self.assertEqual(session, SessionCache.lookup_session(key)) + + session.close() + + self.assertIsNone(SessionCache.lookup_session(key)) + @patch('pixelated.bitmask_libraries.session.register') def test_session_fresh_is_initially_false(self, _): session = self._create_session() diff --git a/service/test/unit/config/test_services.py b/service/test/unit/config/test_services.py new file mode 100644 index 00000000..71765d19 --- /dev/null +++ b/service/test/unit/config/test_services.py @@ -0,0 +1,34 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see <http://www.gnu.org/licenses/>. +import unittest + +from mockito import mock, verify + +from pixelated.config.services import Services + + +class ServicesTest(unittest.TestCase): + + def setUp(self): + super(ServicesTest, self).setUp() + self.leap_session = mock() + config = mock() + self.leap_session.config = config + self.services = Services(self.leap_session) + + def test_close_services_closes_the_underlying_leap_session(self): + self.services.close() + verify(self.leap_session).close() diff --git a/service/test/unit/resources/test_login_resource.py b/service/test/unit/resources/test_login_resource.py index b3aaccc2..bc238ae8 100644 --- a/service/test/unit/resources/test_login_resource.py +++ b/service/test/unit/resources/test_login_resource.py @@ -1,3 +1,5 @@ +import test.support.mockito + from leap.exceptions import SRPAuthenticationError from mock import patch from mockito import mock, when, any as ANY, verify, verifyZeroInteractions, verifyNoMoreInteractions @@ -33,6 +35,7 @@ class TestLoginResource(unittest.TestCase): def test_there_are_no_grand_children_resources_when_logged_in(self, mock_is_logged_in): request = DummyRequest(['/login/grand_children']) mock_is_logged_in.return_value = True + when(self.services_factory).is_logged_in(ANY()).thenReturn(True) d = self.web.get(request) @@ -93,9 +96,13 @@ class TestLoginPOST(unittest.TestCase): self.leap_session = leap_session self.user_auth = user_auth + def mock_user_has_services_setup(self): + when(self.services_factory).is_logged_in('some_user_uuid').thenReturn(True) + def test_login_responds_interstitial_and_add_corresponding_session_to_services_factory(self): irrelevant = None when(self.portal).login(ANY(), None, IResource).thenReturn((irrelevant, self.leap_session, irrelevant)) + when(self.services_factory).create_services_from(self.leap_session).thenAnswer(self.mock_user_has_services_setup) d = self.web.get(self.request) @@ -163,6 +170,7 @@ 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 + when(self.services_factory).is_logged_in(ANY()).thenReturn(True) mock_redirect.return_value = "mocked redirection" when(self.portal).login(ANY(), None, IResource).thenRaise(Exception()) d = self.web.get(self.request) diff --git a/service/test/unit/resources/test_logout_resources.py b/service/test/unit/resources/test_logout_resources.py index bb0aea9e..48cf9db9 100644 --- a/service/test/unit/resources/test_logout_resources.py +++ b/service/test/unit/resources/test_logout_resources.py @@ -1,5 +1,5 @@ from mock import patch -from mockito import mock +from mockito import mock, verify from twisted.trial import unittest from twisted.web.test.requesthelper import DummyRequest @@ -24,6 +24,7 @@ class TestLogoutResource(unittest.TestCase): def expire_session_and_redirect(_): session = self.resource.get_session(request) self.assertFalse(session.is_logged_in()) + verify(self.services_factory).log_out_user(session.user_uuid) mock_redirect.assert_called_once_with('/login', request) d.addCallback(expire_session_and_redirect) |