[tor-commits] [ooni-probe/master] Use `onion.find_tor_binary()` to obtain the path to the tor binary always

art at torproject.org art at torproject.org
Fri Sep 22 18:41:07 UTC 2017


commit edc76fab398474e28381df9cec3b0efef905ab34
Author: Arturo Filastò <arturo at filasto.net>
Date:   Sun Jun 25 17:59:50 2017 +0200

    Use `onion.find_tor_binary()` to obtain the path to the tor binary always
    
    * Avoid setting `tor_details` globally as this could be called when the
      config file has not yet been parsed and therefore it may not respect
      `advanced-tor_binary`
---
 ooni/nettests/blocking/bridge_reachability.py | 11 +++++++----
 ooni/nettests/blocking/vanilla_tor.py         |  6 ++++--
 ooni/tests/test_onion.py                      |  7 ++++---
 ooni/utils/onion.py                           | 25 +++++++++++++++----------
 setup.py                                      |  1 -
 5 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/ooni/nettests/blocking/bridge_reachability.py b/ooni/nettests/blocking/bridge_reachability.py
index e5cc512e..870dcfa1 100644
--- a/ooni/nettests/blocking/bridge_reachability.py
+++ b/ooni/nettests/blocking/bridge_reachability.py
@@ -48,6 +48,8 @@ class BridgeReachability(nettest.NetTestCase):
 
     def setUp(self):
         self.tor_progress = 0
+        self.tor_details = onion.get_tor_details()
+        self.obfsproxy_details = onion.get_obfsproxy_details()
         self.timeout = int(self.localOptions['timeout'])
 
         fd, self.tor_logfile = tempfile.mkstemp()
@@ -60,12 +62,12 @@ class BridgeReachability(nettest.NetTestCase):
         self.report['success'] = None
         self.report['timeout'] = self.timeout
         self.report['transport_name'] = 'vanilla'
-        self.report['tor_version'] = str(onion.tor_details['version'])
+        self.report['tor_version'] = str(self.tor_details['version'])
         self.report['tor_progress'] = 0
         self.report['tor_progress_tag'] = None
         self.report['tor_progress_summary'] = None
         self.report['tor_log'] = None
-        self.report['obfsproxy_version'] = str(onion.obfsproxy_details['version'])
+        self.report['obfsproxy_version'] = str(self.obfsproxy_details['version'])
         self.report['obfsproxy_log'] = None
         self.report['bridge_address'] = None
 
@@ -128,7 +130,7 @@ class BridgeReachability(nettest.NetTestCase):
         config.DataDirectory = self.tor_datadir
         log.msg(
             "Connecting to %s with tor %s" %
-            (self.bridge, onion.tor_details['version']))
+            (self.bridge, self.tor_details['version']))
 
         transport_name = onion.transport_name(self.bridge)
         if transport_name == None:
@@ -175,7 +177,8 @@ class BridgeReachability(nettest.NetTestCase):
             self.report['tor_progress_tag'] = tag
             self.report['tor_progress_summary'] = summary
 
-        d = txtorcon.launch_tor(config, reactor, timeout=self.timeout,
+        d = txtorcon.launch_tor(config, reactor, tor_binary=onion.find_tor_binary(),
+                                timeout=self.timeout,
                                 progress_updates=updates)
 
         @d.addCallback
diff --git a/ooni/nettests/blocking/vanilla_tor.py b/ooni/nettests/blocking/vanilla_tor.py
index 717fa733..a147be89 100644
--- a/ooni/nettests/blocking/vanilla_tor.py
+++ b/ooni/nettests/blocking/vanilla_tor.py
@@ -39,6 +39,7 @@ class VanillaTor(nettest.NetTestCase):
 
     def setUp(self):
         self.tor_progress = 0
+        self.tor_details = onion.get_tor_details()
         self.timeout = int(self.localOptions['timeout'])
 
         fd, self.tor_logfile = tempfile.mkstemp()
@@ -49,7 +50,7 @@ class VanillaTor(nettest.NetTestCase):
         self.report['success'] = None
         self.report['timeout'] = self.timeout
         self.report['transport_name'] = 'vanilla'
-        self.report['tor_version'] = str(onion.tor_details['version'])
+        self.report['tor_version'] = str(self.tor_details['version'])
         self.report['tor_progress'] = 0
         self.report['tor_progress_tag'] = None
         self.report['tor_progress_summary'] = None
@@ -73,7 +74,8 @@ class VanillaTor(nettest.NetTestCase):
             self.report['tor_progress_tag'] = tag
             self.report['tor_progress_summary'] = summary
 
-        d = txtorcon.launch_tor(config, reactor, timeout=self.timeout,
+        d = txtorcon.launch_tor(config, reactor, tor_binary=onion.find_tor_binary(),
+                                timeout=self.timeout,
                                 progress_updates=updates)
 
         @d.addCallback
diff --git a/ooni/tests/test_onion.py b/ooni/tests/test_onion.py
index 732614fb..0807ca02 100644
--- a/ooni/tests/test_onion.py
+++ b/ooni/tests/test_onion.py
@@ -26,9 +26,10 @@ class MockSuccessTorProtocol(object):
 
 class TestOnion(unittest.TestCase):
     def test_tor_details(self):
-        assert isinstance(onion.tor_details, dict)
-        assert onion.tor_details['version']
-        assert onion.tor_details['binary']
+        tor_details = onion.get_tor_details()
+        assert isinstance(tor_details, dict)
+        assert tor_details['version']
+        assert tor_details['binary']
 
     def test_transport_dicts(self):
 
diff --git a/ooni/utils/onion.py b/ooni/utils/onion.py
index 283579cd..2c2a2c81 100644
--- a/ooni/utils/onion.py
+++ b/ooni/utils/onion.py
@@ -98,15 +98,17 @@ def find_pt_executable(name):
             return bin_loc
     return None
 
-tor_details = {
-    'binary': find_tor_binary(),
-    'version': tor_version()
-}
-
-obfsproxy_details = {
-    'binary': find_executable('obfsproxy'),
-    'version': obfsproxy_version()
-}
+def get_tor_details():
+    return {
+        'binary': find_tor_binary(),
+        'version': tor_version()
+    }
+
+def get_obfsproxy_details():
+    return {
+        'binary': find_executable('obfsproxy'),
+        'version': obfsproxy_version()
+    }
 
 transport_bin_name = { 'fte': 'fteproxy',
                        'scramblesuit': 'obfsproxy',
@@ -148,6 +150,9 @@ class OutdatedTor(Exception):
     pass
 
 def bridge_line(transport, log_file):
+    obfsproxy_details = get_obfsproxy_details()
+    tor_details = get_tor_details()
+
     bin_name = transport_bin_name.get(transport)
     if not bin_name:
         raise UnrecognizedTransport
@@ -387,7 +392,7 @@ class TorLauncherWithRetries(object):
 
     def _launch_tor(self):
         return launch_tor(self.tor_config, reactor,
-                          tor_binary=config.advanced.tor_binary,
+                          tor_binary=find_tor_binary(),
                           progress_updates=self._progress_updates,
                           stdout=self.tor_output,
                           timeout=self.timeout,
diff --git a/setup.py b/setup.py
index 26ed2a19..a16891e7 100644
--- a/setup.py
+++ b/setup.py
@@ -279,7 +279,6 @@ def setup_package():
         },
         classifiers=[c for c in CLASSIFIERS.split('\n') if c]
     )
-
     setup(**metadata)
 
 if __name__ == "__main__":





More information about the tor-commits mailing list