summaryrefslogtreecommitdiff
path: root/service/test/unit/config
diff options
context:
space:
mode:
Diffstat (limited to 'service/test/unit/config')
-rw-r--r--service/test/unit/config/test_leap.py51
-rw-r--r--service/test/unit/config/test_sessions.py15
2 files changed, 64 insertions, 2 deletions
diff --git a/service/test/unit/config/test_leap.py b/service/test/unit/config/test_leap.py
index 5a68c53a..29f19f2f 100644
--- a/service/test/unit/config/test_leap.py
+++ b/service/test/unit/config/test_leap.py
@@ -19,7 +19,8 @@ from mock import MagicMock, patch, Mock
from twisted.trial import unittest
from twisted.internet import defer
from pixelated.config.leap import create_leap_session, BootstrapUserServices, initialize_leap_single_user
-from pixelated.config.sessions import LeapSessionFactory, SessionCache
+from pixelated.config.sessions import LeapSessionFactory, SessionCache, SoledadWrongPassphraseException
+from leap.soledad.common.crypto import UnknownMacMethodError
class TestLeapInit(unittest.TestCase):
@@ -143,3 +144,51 @@ class TestUserBootstrap(unittest.TestCase):
self._user_bootstrap.setup(self.user_auth, self.password)
mock_add_welcome_email.assert_called_once_with(mail_store, default_language)
+
+ @patch('pixelated.config.leap.create_leap_session')
+ @patch('pixelated.config.leap.log.warn')
+ @defer.inlineCallbacks
+ def test__setup__should_log_an_error_raised_from_create_leap_session(self, mock_logger_warn, mock_create_leap_session):
+ mock_create_leap_session.side_effect = SoledadWrongPassphraseException(UnknownMacMethodError("oh no"))
+ with self.assertRaises(SoledadWrongPassphraseException):
+ yield self._user_bootstrap.setup(self.user_auth, self.password, '')
+ mock_logger_warn.assert_called_once_with("SoledadWrongPassphraseException: oh no. Closing session for user: ayoyo")
+
+ @patch('pixelated.config.leap.BootstrapUserServices._setup_user_services')
+ @patch('pixelated.config.leap.create_leap_session')
+ @patch('pixelated.config.leap.log.warn')
+ @defer.inlineCallbacks
+ def test__setup__should_log_an_error_raised_from__setup_user_services(self, mock_logger_warn, mock_create_leap_session, mock_setup_user_services):
+ leap_session = Mock()
+ mock_create_leap_session.return_value = leap_session
+ mock_setup_user_services.side_effect = UnknownMacMethodError("oh no")
+ with self.assertRaises(UnknownMacMethodError):
+ yield self._user_bootstrap.setup(self.user_auth, self.password, '')
+ mock_logger_warn.assert_called_once_with("UnknownMacMethodError: oh no. Closing session for user: ayoyo")
+
+ @patch('pixelated.config.leap.BootstrapUserServices._setup_user_services')
+ @patch('pixelated.config.leap.create_leap_session')
+ @patch('pixelated.config.leap.log.warn')
+ @defer.inlineCallbacks
+ def test__setup__should_close_leap_sesson_on_error_from__setup_user_services(self, mock_logger_warn, mock_create_leap_session, mock_setup_user_services):
+ leap_session = Mock()
+ leap_session.close = Mock()
+ mock_create_leap_session.return_value = leap_session
+ mock_setup_user_services.side_effect = UnknownMacMethodError("oh no")
+ with self.assertRaises(UnknownMacMethodError):
+ yield self._user_bootstrap.setup(self.user_auth, self.password, '')
+ leap_session.close.assert_called_once_with()
+
+ @patch('pixelated.config.leap.BootstrapUserServices._add_welcome_email')
+ @patch('pixelated.config.leap.BootstrapUserServices._setup_user_services')
+ @patch('pixelated.config.leap.create_leap_session')
+ @patch('pixelated.config.leap.log.warn')
+ @defer.inlineCallbacks
+ def test__setup__should_close_leap_sesson_on_error_from__add_welcome_email(self, mock_logger_warn, mock_create_leap_session, _, mock_add_welcome_email):
+ leap_session = Mock()
+ leap_session.close = Mock()
+ mock_create_leap_session.return_value = leap_session
+ mock_add_welcome_email.side_effect = UnknownMacMethodError("oh no")
+ with self.assertRaises(UnknownMacMethodError):
+ yield self._user_bootstrap.setup(self.user_auth, self.password, '')
+ leap_session.close.assert_called_once_with()
diff --git a/service/test/unit/config/test_sessions.py b/service/test/unit/config/test_sessions.py
index 91a0ef90..e2254eae 100644
--- a/service/test/unit/config/test_sessions.py
+++ b/service/test/unit/config/test_sessions.py
@@ -19,10 +19,11 @@ from mock import patch
from mock import MagicMock
from mockito import when
from twisted.internet import defer
-from pixelated.config.sessions import LeapSession, SessionCache, LeapSessionFactory
+from pixelated.config.sessions import LeapSession, SessionCache, LeapSessionFactory, SoledadWrongPassphraseException
from pixelated.bitmask_libraries.keymanager import UploadKeyError
from test.unit.bitmask_libraries.test_abstract_leap import AbstractLeapTest
from leap.common.events.catalog import KEYMANAGER_FINISHED_KEY_GENERATION
+from leap.soledad.common.crypto import WrongMacError, UnknownMacMethodError
class SessionTest(AbstractLeapTest):
@@ -179,6 +180,18 @@ class SessionTest(AbstractLeapTest):
self.assertIs(type(uuid_arg), str, "expected uuid argument to be a string")
self.assertIs(type(pass_arg), unicode, "expected passphrase argument to be unicode")
+ @defer.inlineCallbacks
+ def test_sessions__setup_soledad__will_raise_wrong_passphrase_exception_on_errors(self):
+ leap_session_factory = LeapSessionFactory(self.provider)
+
+ with patch('pixelated.config.sessions.Soledad', side_effect=WrongMacError("oh no")):
+ with self.assertRaises(SoledadWrongPassphraseException):
+ yield leap_session_factory.setup_soledad('token', u'uuid', 'passphrase', None)
+
+ with patch('pixelated.config.sessions.Soledad', side_effect=UnknownMacMethodError("oh no")):
+ with self.assertRaises(SoledadWrongPassphraseException):
+ yield leap_session_factory.setup_soledad('token', u'uuid', 'passphrase', None)
+
def _create_session(self):
return LeapSession(self.provider, self.auth, self.mail_store, self.soledad_session, self.keymanager, self.smtp_mock)