commit 358a583299fdb1dd2f85f95515c07d1be95ee0fb Author: Arturo Filastò arturo@filasto.net Date: Fri Jun 17 11:00:57 2016 +0300
Fix bug in setting annotations and collector address via command line (#534)
* This closes https://github.com/TheTorProject/ooni-probe/issues/529 --- ooni/deck.py | 17 +++++++++++++---- ooni/oonicli.py | 2 +- ooni/tests/test_deck.py | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/ooni/deck.py b/ooni/deck.py index 383845c..657589d 100644 --- a/ooni/deck.py +++ b/ooni/deck.py @@ -120,7 +120,7 @@ class Deck(InputFile): def cached_descriptor(self): return self.cached_file + '.desc'
- def loadDeck(self, deckFile): + def loadDeck(self, deckFile, global_options={}): with open(deckFile) as f: self.id = sha256(f.read()).hexdigest() f.seek(0) @@ -133,12 +133,21 @@ class Deck(InputFile): log.err("Could not find %s" % test['options']['test_file']) log.msg("Skipping...") continue + + annotations = test['options'].get('annotations', {}) + if global_options.get('annotations') is not None: + annotations = global_options["annotations"] + + collector_address = test['options'].get('collector', None) + if global_options.get('collector') is not None: + collector_address = global_options['collector'] + net_test_loader = NetTestLoader(test['options']['subargs'], - annotations=test['options'].get('annotations', {}), + annotations=annotations, test_file=nettest_path) - if test['options'].get('collector', None) is not None: + if collector_address is not None: net_test_loader.collector = CollectorClient( - test['options']['collector'] + collector_address ) if test['options'].get('bouncer', None) is not None: self.bouncer = test['options']['bouncer'] diff --git a/ooni/oonicli.py b/ooni/oonicli.py index 5aa538c..56b331d 100644 --- a/ooni/oonicli.py +++ b/ooni/oonicli.py @@ -244,7 +244,7 @@ def createDeck(global_options, url=None):
try: if global_options['testdeck']: - deck.loadDeck(global_options['testdeck']) + deck.loadDeck(global_options['testdeck'], global_options) else: log.debug("No test deck detected") test_file = nettest_to_path(global_options['test_file'], True) diff --git a/ooni/tests/test_deck.py b/ooni/tests/test_deck.py index fa9b0e8..1e311cf 100644 --- a/ooni/tests/test_deck.py +++ b/ooni/tests/test_deck.py @@ -33,6 +33,7 @@ class BaseTestCase(unittest.TestCase): self.cwd = os.getcwd() self.dummy_deck_content = """- options: collector: null + annotations: null help: 0 logfile: null no-default-reporter: 0 @@ -132,6 +133,24 @@ class TestDeck(BaseTestCase): deck.loadDeck(self.deck_file) assert len(deck.netTestLoaders) == 1
+ def test_load_deck_with_global_options(self): + global_options = { + "annotations": {"spam": "ham"}, + "collector": "httpo://thirteenchars123.onion" + } + deck = Deck(bouncer="httpo://foo.onion", + decks_directory=".") + deck.loadDeck(self.deck_file, + global_options=global_options) + self.assertEqual( + deck.netTestLoaders[0].annotations, + global_options['annotations'] + ) + self.assertEqual( + deck.netTestLoaders[0].collector.base_address, + global_options['collector'].replace("httpo://", "http://") + ) + def test_save_deck_descriptor(self): deck = Deck(bouncer="httpo://foo.onion", decks_directory=".")
tor-commits@lists.torproject.org