summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
authorNavaL <ayoyo@thoughtworks.com>2016-05-19 11:51:43 +0200
committerNavaL <ayoyo@thoughtworks.com>2016-05-19 11:51:43 +0200
commit053d51e8c6484f95b43c7b45e5b42fcb3e89784c (patch)
treec624ef9832b544e823eb345bf24c58b30f7bfcc2 /service/test
parent021fd399db4801c3d2c96b6f2bace99046d9f54b (diff)
when invalid soledad auth token, it logs user out if multi-user and stops the reactor if single-user mode
Issue #689
Diffstat (limited to 'service/test')
-rw-r--r--service/test/unit/test_application.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/service/test/unit/test_application.py b/service/test/unit/test_application.py
index 5f7f9c74..7fb2b9ff 100644
--- a/service/test/unit/test_application.py
+++ b/service/test/unit/test_application.py
@@ -1,5 +1,6 @@
import unittest
+from leap.common.events import catalog as events
from mock import patch, MagicMock, ANY
import pixelated
@@ -73,3 +74,34 @@ class ApplicationTest(unittest.TestCase):
d.addCallback(_assert)
return d
+
+ @patch('leap.common.events.client')
+ @patch('pixelated.application.reactor')
+ @patch('pixelated.application.services.Services')
+ def test_should_log_user_out_if_invalid_soledad_token(self, services_mock, reactor_mock, events_mock):
+ app_mock = MagicMock()
+ services_factory_mock = MagicMock()
+
+ mock_service_log_user_out = MagicMock(return_value=None)
+ services_factory_mock.log_out_user = mock_service_log_user_out
+
+ leap_session = MagicMock()
+ register_mock = events_mock.register
+ register_mock.register.return_value = None
+
+ config = ApplicationTest.MockConfig(12345, '127.0.0.1')
+ d = pixelated.application.start_user_agent_in_single_user_mode(app_mock, services_factory_mock, config.home, leap_session)
+
+ pixelated.application.add_top_level_system_callbacks(d, services_factory_mock)
+
+ def _assert_user_logged_out(_):
+ used_arguments = register_mock.call_args[0]
+ self.assertIsNotNone(used_arguments)
+ soledad_invalid_auth_event = used_arguments[0]
+ self.assertEqual(soledad_invalid_auth_event, events.SOLEDAD_INVALID_AUTH_TOKEN)
+ used_log_out_method = used_arguments[1]
+ used_log_out_method({'uuid': 'some_uuid'})
+ mock_service_log_user_out.assert_called_once_with('some_uuid')
+
+ d.addCallback(_assert_user_logged_out)
+ return d