From 8c71fcd6e070d6bf46394fb29fba4d75c76a3987 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Thu, 15 Jan 2015 19:18:05 -0300 Subject: Fix failing tests. Remove srpauth obsolete tests. Remove providerconfig obsolete test. Set as mandatory the signaler object on ProviderBootstrapper and EIPBootstrapper. Closes #6631. --- .../bitmask/config/tests/test_providerconfig.py | 12 ----- src/leap/bitmask/crypto/tests/test_srpauth.py | 60 ++++------------------ src/leap/bitmask/provider/providerbootstrapper.py | 41 ++++++++++----- .../provider/tests/test_providerbootstrapper.py | 3 +- src/leap/bitmask/services/eip/eipbootstrapper.py | 11 ++-- src/leap/bitmask/services/eip/eipconfig.py | 2 + 6 files changed, 49 insertions(+), 80 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/config/tests/test_providerconfig.py b/src/leap/bitmask/config/tests/test_providerconfig.py index fe27e683..7bc30f9c 100644 --- a/src/leap/bitmask/config/tests/test_providerconfig.py +++ b/src/leap/bitmask/config/tests/test_providerconfig.py @@ -258,18 +258,6 @@ class ProviderConfigTest(BaseLeapTest): pc.load(data=json_string) self.assertTrue('unknown' in pc.get_services()) - def test_get_services_string(self): - pc = self._provider_config - config = copy.deepcopy(sample_config) - config['services'] = [ - 'openvpn', 'asdf', 'openvpn', 'not_supported_service'] - json_string = json.dumps(config) - pc.load(data=json_string) - - self.assertEqual(pc.get_services_string(), - "Encrypted Internet, asdf, Encrypted Internet," - " not_supported_service") - if __name__ == "__main__": unittest.main() diff --git a/src/leap/bitmask/crypto/tests/test_srpauth.py b/src/leap/bitmask/crypto/tests/test_srpauth.py index 511a12ed..d420ef93 100644 --- a/src/leap/bitmask/crypto/tests/test_srpauth.py +++ b/src/leap/bitmask/crypto/tests/test_srpauth.py @@ -27,6 +27,7 @@ import sys import binascii import requests import mock +import shutil from functools import partial @@ -42,6 +43,7 @@ from leap.bitmask.crypto import srpregister, srpauth from leap.bitmask.crypto.tests import fake_provider from leap.bitmask.util.request_helpers import get_content from leap.common.testing.https_server import where +from leap.common.files import mkdir_p log.startLogging(sys.stdout) @@ -118,6 +120,10 @@ class SRPAuthTestCase(unittest.TestCase): self.old_cookie_get = self.auth_backend._session.cookies.get self.old_auth = self.auth_backend.authenticate + # HACK: this is needed since it seems that the backend settings path is + # not using the right path + mkdir_p('config/leap') + def tearDown(self): self.auth_backend._session.post = self.old_post self.auth_backend._session.put = self.old_put @@ -132,6 +138,10 @@ class SRPAuthTestCase(unittest.TestCase): self.auth_backend._session.cookies.get = self.old_cookie_get self.auth_backend.authenticate = self.old_auth + # HACK: see 'setUp' + if os.path.exists('config'): + shutil.rmtree('config') + # helper methods def _get_https_uri(self): @@ -710,56 +720,6 @@ class SRPAuthSingletonTestCase(unittest.TestCase): obj2 = srpauth.SRPAuth(ProviderConfig()) self.assertEqual(obj1._SRPAuth__instance, obj2._SRPAuth__instance) - @deferred() - def test_authenticate_notifies_gui(self): - auth = srpauth.SRPAuth(ProviderConfig()) - auth._SRPAuth__instance.authenticate = mock.create_autospec( - auth._SRPAuth__instance.authenticate, - return_value=threads.deferToThread(lambda: None)) - auth._gui_notify = mock.create_autospec( - auth._gui_notify) - - d = auth.authenticate("", "") - - def check(*args): - auth._gui_notify.assert_called_once_with(None) - - d.addCallback(check) - return d - - @deferred() - def test_authenticate_errsback(self): - auth = srpauth.SRPAuth(ProviderConfig()) - auth._SRPAuth__instance.authenticate = mock.create_autospec( - auth._SRPAuth__instance.authenticate, - return_value=threads.deferToThread(MagicMock( - side_effect=Exception()))) - auth._gui_notify = mock.create_autospec( - auth._gui_notify) - auth._errback = mock.create_autospec( - auth._errback) - - d = auth.authenticate("", "") - - def check(*args): - self.assertFalse(auth._gui_notify.called) - self.assertEqual(auth._errback.call_count, 1) - - d.addCallback(check) - return d - - @deferred() - def test_authenticate_runs_cleanly_when_raises(self): - auth = srpauth.SRPAuth(ProviderConfig()) - auth._SRPAuth__instance.authenticate = mock.create_autospec( - auth._SRPAuth__instance.authenticate, - return_value=threads.deferToThread(MagicMock( - side_effect=Exception()))) - - d = auth.authenticate("", "") - - return d - @deferred() def test_authenticate_runs_cleanly(self): auth = srpauth.SRPAuth(ProviderConfig()) diff --git a/src/leap/bitmask/provider/providerbootstrapper.py b/src/leap/bitmask/provider/providerbootstrapper.py index 8eefb9d9..efba29f9 100644 --- a/src/leap/bitmask/provider/providerbootstrapper.py +++ b/src/leap/bitmask/provider/providerbootstrapper.py @@ -225,8 +225,9 @@ class ProviderBootstrapper(AbstractBootstrapper): if flags.APP_VERSION_CHECK: # TODO split if not provider.supports_client(min_client_version): - self._signaler.signal( - self._signaler.prov_unsupported_client) + if self._signaler is not None: + self._signaler.signal( + self._signaler.prov_unsupported_client) raise UnsupportedClientVersionError() provider_definition, mtime = get_content(res) @@ -248,7 +249,9 @@ class ProviderBootstrapper(AbstractBootstrapper): 'Found: {1}.').format(api_supported, api_version) logger.error(error) - self._signaler.signal(self._signaler.prov_unsupported_api) + if self._signaler is not None: + self._signaler.signal( + self._signaler.prov_unsupported_api) raise UnsupportedProviderAPI(error) def run_provider_select_checks(self, domain, download_if_needed=False): @@ -267,12 +270,18 @@ class ProviderBootstrapper(AbstractBootstrapper): self._domain = ProviderConfig.sanitize_path_component(domain) self._download_if_needed = download_if_needed + name_resolution = None + https_connection = None + down_provider_info = None + if self._signaler is not None: + name_resolution = self._signaler.prov_name_resolution + https_connection = self._signaler.prov_https_connection + down_provider_info = self._signaler.prov_download_provider_info + cb_chain = [ - (self._check_name_resolution, - self._signaler.prov_name_resolution), - (self._check_https, self._signaler.prov_https_connection), - (self._download_provider_info, - self._signaler.prov_download_provider_info) + (self._check_name_resolution, name_resolution), + (self._check_https, https_connection), + (self._download_provider_info, down_provider_info) ] return self.addCallbackChain(cb_chain) @@ -398,12 +407,18 @@ class ProviderBootstrapper(AbstractBootstrapper): self._provider_config = provider_config self._download_if_needed = download_if_needed + download_ca_cert = None + check_ca_fingerprint = None + check_api_certificate = None + if self._signaler is not None: + download_ca_cert = self._signaler.prov_download_ca_cert + check_ca_fingerprint = self._signaler.prov_check_ca_fingerprint + check_api_certificate = self._signaler.prov_check_api_certificate + cb_chain = [ - (self._download_ca_cert, self._signaler.prov_download_ca_cert), - (self._check_ca_fingerprint, - self._signaler.prov_check_ca_fingerprint), - (self._check_api_certificate, - self._signaler.prov_check_api_certificate) + (self._download_ca_cert, download_ca_cert), + (self._check_ca_fingerprint, check_ca_fingerprint), + (self._check_api_certificate, check_api_certificate) ] return self.addCallbackChain(cb_chain) diff --git a/src/leap/bitmask/provider/tests/test_providerbootstrapper.py b/src/leap/bitmask/provider/tests/test_providerbootstrapper.py index 6cf3e469..e694e456 100644 --- a/src/leap/bitmask/provider/tests/test_providerbootstrapper.py +++ b/src/leap/bitmask/provider/tests/test_providerbootstrapper.py @@ -38,7 +38,6 @@ from requests.models import Response from leap.bitmask import provider from leap.bitmask import util -from leap.bitmask.backend import Signaler from leap.bitmask.config.providerconfig import ProviderConfig from leap.bitmask.crypto.tests import fake_provider from leap.bitmask.provider.providerbootstrapper import ProviderBootstrapper @@ -51,7 +50,7 @@ from leap.common.testing.https_server import where class ProviderBootstrapperTest(BaseLeapTest): def setUp(self): - self.pb = ProviderBootstrapper(Signaler()) + self.pb = ProviderBootstrapper() def tearDown(self): pass diff --git a/src/leap/bitmask/services/eip/eipbootstrapper.py b/src/leap/bitmask/services/eip/eipbootstrapper.py index 264eac2e..f78113bc 100644 --- a/src/leap/bitmask/services/eip/eipbootstrapper.py +++ b/src/leap/bitmask/services/eip/eipbootstrapper.py @@ -115,10 +115,15 @@ class EIPBootstrapper(AbstractBootstrapper): self._provider_config = provider_config self._download_if_needed = download_if_needed + eip_config_ready = None + eip_certificate_ready = None + if self._signaler is not None: + eip_config_ready = self._signaler.eip_config_ready + eip_certificate_ready = self._signaler.eip_client_certificate_ready + cb_chain = [ - (self._download_config, self._signaler.eip_config_ready), - (self._download_client_certificates, - self._signaler.eip_client_certificate_ready) + (self._download_config, eip_config_ready), + (self._download_client_certificates, eip_certificate_ready) ] return self.addCallbackChain(cb_chain) diff --git a/src/leap/bitmask/services/eip/eipconfig.py b/src/leap/bitmask/services/eip/eipconfig.py index 659ca1b1..f4d6b216 100644 --- a/src/leap/bitmask/services/eip/eipconfig.py +++ b/src/leap/bitmask/services/eip/eipconfig.py @@ -118,6 +118,8 @@ class VPNGatewaySelector(object): """ gateways_timezones = [] locations = self._eipconfig.get_locations() + if not locations: + locations = {} gateways = self._eipconfig.get_gateways() for idx, gateway in enumerate(gateways): -- cgit v1.2.3