From de0ac2dd999a0548f2276cd2e2715ca93cb6b41b Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Fri, 30 Sep 2016 17:36:12 -0500 Subject: [bug] In case of wrong url don't leave files in the config folder - Resolves: #8498 --- src/leap/bitmask/bonafide/_protocol.py | 2 +- src/leap/bitmask/bonafide/config.py | 14 +++++++++++--- src/leap/bitmask/bonafide/errors.py | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/bonafide/_protocol.py b/src/leap/bitmask/bonafide/_protocol.py index 01919c7..3572cbf 100644 --- a/src/leap/bitmask/bonafide/_protocol.py +++ b/src/leap/bitmask/bonafide/_protocol.py @@ -168,7 +168,7 @@ class BonafideProtocol(object): def do_get_provider(self, provider_id, autoconf=False): provider = config.Provider(provider_id, autoconf=autoconf) - return provider.callWhenMainConfigReady(provider.config) + return provider.callWhenReady(provider.config) def do_provider_delete(self, provider_id): return config.delete_provider(provider_id) diff --git a/src/leap/bitmask/bonafide/config.py b/src/leap/bitmask/bonafide/config.py index 8ef6c1b..e4e2bf4 100644 --- a/src/leap/bitmask/bonafide/config.py +++ b/src/leap/bitmask/bonafide/config.py @@ -33,7 +33,7 @@ from twisted.web.client import Agent, downloadPage from leap.bitmask.bonafide._http import httpRequest from leap.bitmask.bonafide.provider import Discovery -from leap.bitmask.bonafide.errors import NotConfiguredError +from leap.bitmask.bonafide.errors import NotConfiguredError, NetworkError from leap.common.check import leap_assert from leap.common.config import get_path_prefix as common_get_path_prefix @@ -284,9 +284,13 @@ class Provider(object): uri = self._disco.get_provider_info_uri() met = self._disco.get_provider_info_method() + def errback(failure): + shutil.rmtree(folders) + raise NetworkError(failure.getErrorMessage()) + d = downloadPage(uri, provider_json, method=met) d.addCallback(lambda _: self._load_provider_json()) - d.addErrback(log.err) + d.addErrback(errback) return d def update_provider_info(self): @@ -299,6 +303,10 @@ class Provider(object): """ :rtype: deferred """ + + def errback(self, failure): + raise NetworkError(failure.getErrorMessage()) + path = self._get_ca_cert_path() if is_file(path): return defer.succeed('ca_cert_path_already_exists') @@ -306,7 +314,7 @@ class Provider(object): uri = self._get_ca_cert_uri() mkdir_p(os.path.split(path)[0]) d = downloadPage(uri, path) - d.addErrback(log.err) + d.addErrback(errback) return d def validate_ca_cert(self, ignored): diff --git a/src/leap/bitmask/bonafide/errors.py b/src/leap/bitmask/bonafide/errors.py index 485c43e..db92519 100644 --- a/src/leap/bitmask/bonafide/errors.py +++ b/src/leap/bitmask/bonafide/errors.py @@ -21,3 +21,7 @@ Exceptions for bonafide class NotConfiguredError(Exception): pass + + +class NetworkError(Exception): + pass -- cgit v1.2.3