[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Only report connection resolvers that are in our PATH



commit 276fb65ef4dbf0536be91e3fcb1912363d5ada73
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Sep 23 12:03:25 2013 -0700

    Only report connection resolvers that are in our PATH
    
    Having get_system_resolvers() check that resolvers are in our PATH before
    returning them.
---
 stem/util/connection.py      |    4 ++++
 test/unit/util/connection.py |    9 ++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/stem/util/connection.py b/stem/util/connection.py
index 4605a57..0b93130 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -249,6 +249,10 @@ def get_system_resolvers(system = None):
 
     resolvers = [Resolver.NETSTAT, Resolver.SOCKSTAT, Resolver.LSOF, Resolver.SS]
 
+  # remove any that aren't in the user's PATH
+
+  resolvers = filter(lambda r: stem.util.system.is_available(RESOLVER_COMMAND[r]), resolvers)
+
   # proc resolution, by far, outperforms the others so defaults to this is able
 
   if stem.util.proc.is_available():
diff --git a/test/unit/util/connection.py b/test/unit/util/connection.py
index 03d83c1..1d9e6f6 100644
--- a/test/unit/util/connection.py
+++ b/test/unit/util/connection.py
@@ -88,12 +88,14 @@ BSD_PROCSTAT_OUTPUT = """\
 
 
 class TestConnection(unittest.TestCase):
+  @patch('stem.util.system.is_available')
   @patch('stem.util.proc.is_available')
-  def test_get_system_resolvers(self, proc_mock):
+  def test_get_system_resolvers(self, proc_mock, is_available_mock):
     """
     Checks the get_system_resolvers function.
     """
 
+    is_available_mock.return_value = True
     proc_mock.return_value = False
 
     self.assertEqual([], stem.util.connection.get_system_resolvers('Windows'))
@@ -110,6 +112,11 @@ class TestConnection(unittest.TestCase):
 
     self.assertEqual(stem.util.connection.get_system_resolvers(platform.system()), stem.util.connection.get_system_resolvers())
 
+    # check that lacking commands in our PATH drops them from the results
+
+    is_available_mock.return_value = False
+    self.assertEqual([Resolver.PROC], stem.util.connection.get_system_resolvers('Linux'))
+
   @patch('stem.util.proc.get_connections')
   def test_get_connections_by_proc(self, proc_mock):
     """

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits