From 9cdd52be577fff75830c854bd7738ee1649e7083 Mon Sep 17 00:00:00 2001 From: Bruno Wagner Date: Fri, 19 Aug 2016 21:37:34 -0300 Subject: Started deferring leap session creation #759 Started adapting get_leap_session to deferreds Soledad and keymanager setup calls will now happen in deferreds and leap session creation itself is a deferred with callbacks This is a start in breaking the big blocking calls we were doing on the main thread, this was done without changing code inside the leap libraries yet so things can be further optimized This breaks the ~4 seconds get_leap_session piece into smaller 1 seconds one, that can be further optimized and deferred to even smaller calls There are requests calls happening on the main thread that should get this number even further down Also moved some pieces from bitmask libraries to our bootstrap, because they are not bitmask libraries anymore and that was causing confusion --- .../test/unit/bitmask_libraries/test_keymanager.py | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 service/test/unit/bitmask_libraries/test_keymanager.py (limited to 'service/test/unit/bitmask_libraries/test_keymanager.py') diff --git a/service/test/unit/bitmask_libraries/test_keymanager.py b/service/test/unit/bitmask_libraries/test_keymanager.py new file mode 100644 index 00000000..1a1038b8 --- /dev/null +++ b/service/test/unit/bitmask_libraries/test_keymanager.py @@ -0,0 +1,65 @@ +# +# 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 . +from mock import patch +from mockito import when + +from test_abstract_leap import AbstractLeapTest +from leap.keymanager import openpgp, KeyNotFound +from pixelated.bitmask_libraries.keymanager import Keymanager +from pixelated.bitmask_libraries.certs import LeapCertificate +from pixelated.config import leap_config + + +class KeymanagerTest(AbstractLeapTest): + @patch('pixelated.bitmask_libraries.keymanager.KeyManager') + def test_that_keymanager_is_created(self, keymanager_mock): + LeapCertificate.provider_api_cert = '/some/path/to/provider_ca_cert' + when(self.provider)._discover_nicknym_server().thenReturn('https://nicknym.some-server.test:6425/') + leap_config.gpg_binary = '/path/to/gpg' + + Keymanager(self.provider, + self.soledad, + 'test_user@some-server.test', + self.auth.token, + self.auth.uuid) + + keymanager_mock.assert_called_with( + 'test_user@some-server.test', + 'https://nicknym.some-server.test:6425/', + self.soledad, + token=self.auth.token, + ca_cert_path='/some/path/to/provider_ca_cert', + api_uri='https://api.some-server.test:4430', + api_version='1', + uid=self.auth.uuid, + gpgbinary='/path/to/gpg') + + @patch('pixelated.bitmask_libraries.keymanager.KeyManager') + def test_gen_key(self, keymanager_mock): + # given + keyman = keymanager_mock.return_value + keyman.get_key.side_effect = KeyNotFound + keymanager = Keymanager(self.provider, + self.soledad, + 'test_user@some-server.test', + self.auth.token, + self.auth.uuid) + + # when/then + keymanager.generate_openpgp_key() + + keyman.get_key.assert_called_with('test_user@some-server.test', private=True, fetch_remote=False) + keyman.gen_key.assert_called() -- cgit v1.2.3