commit 52b44ac93f71a8bddb3b3a154f5517a6abda18e8 Author: Arturo Filastò arturo@filasto.net Date: Tue Feb 16 13:21:16 2016 +0100
hotfix: Move logic for detecting supported collectors into deck --- ooni/deck.py | 11 +++++++++++ ooni/errors.py | 6 ++++++ ooni/oonicli.py | 24 +++++++++--------------- 3 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/ooni/deck.py b/ooni/deck.py index 83a9a70..4049103 100644 --- a/ooni/deck.py +++ b/ooni/deck.py @@ -6,6 +6,9 @@ from ooni.settings import config from ooni.utils import log from ooni import errors as e
+from twisted import version as _twisted_version +from twisted.python.versions import Version + from twisted.python.filepath import FilePath from twisted.internet import defer
@@ -158,6 +161,14 @@ class Deck(InputFile): if not has_test_helper(missing_option): raise self.requiresTor = True + + if net_test_loader.collector and net_test_loader.collector.startswith('https://'): + _twisted_14_0_2_version = Version('twisted', 14, 0, 2) + if _twisted_version < _twisted_14_0_2_version: + raise e.HTTPCollectorUnsupported + elif net_test_loader.collector and net_test_loader.collector.startswith('http://'): + if config.advanced.insecure_collector is not True: + raise e.InsecureCollector self.netTestLoaders.append(net_test_loader)
@defer.inlineCallbacks diff --git a/ooni/errors.py b/ooni/errors.py index 55b97e1..3b327f7 100644 --- a/ooni/errors.py +++ b/ooni/errors.py @@ -277,3 +277,9 @@ class ProtocolAlreadyRegistered(Exception):
class LibraryNotInstalledError(Exception): pass + +class InsecureCollector(Exception): + pass + +class HTTPSCollectorUnsupported(Exception): + pass diff --git a/ooni/oonicli.py b/ooni/oonicli.py index 864f700..1ba70d5 100644 --- a/ooni/oonicli.py +++ b/ooni/oonicli.py @@ -6,8 +6,6 @@ import yaml import random import urlparse
-from twisted import version as _twisted_version -from twisted.python.versions import Version from twisted.python import usage from twisted.python.util import spewer from twisted.internet import defer, reactor, protocol @@ -262,25 +260,21 @@ def createDeck(global_options, url=None): log.err(e) print e.net_test_loader.usageOptions().getUsage() sys.exit(4) + except errors.HTTPSCollectorUnsupported: + log.err("HTTPS collectors require a twisted version of at least 14.0.2.") + sys.exit(6) + except errors.InsecureCollector: + log.err("Attempting to report to an insecure collector.") + log.err("To enable reporting to insecure collector set the " + "advanced->insecure_collector option to true in " + "your ooniprobe.conf file.") + sys.exit(7) except Exception as e: if config.advanced.debug: log.exception(e) log.err(e) sys.exit(5)
- if net_test_loader.collector and net_test_loader.collector.startswith('https://'): - _twisted_14_0_2_version = Version('twisted', 14, 0, 2) - if _twisted_version < _twisted_14_0_2_version: - log.err("HTTPS collectors require a twisted version of at least 14.0.2.") - sys.exit(6) - elif net_test_loader.collector and net_test_loader.collector.startswith('http://'): - if config.advanced.insecure_collector is not True: - log.err("Attempting to report to an insecure collector.") - log.err("To enable reporting to insecure collector set the " - "advanced->insecure_collector option to true in " - "your ooniprobe.conf file.") - sys.exit(7) - return deck
tor-commits@lists.torproject.org