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

[tor-commits] [stem/master] Expanding coverage of PROTOCOLINFO integ test



commit 07fd7f7d23f5312d4b4ee4ef64d63fbe97a911ba
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Nov 21 04:29:10 2011 -0800

    Expanding coverage of PROTOCOLINFO integ test
    
    Providing the assertions for all connection configurations in the integ test.
---
 test/integ/connection/protocolinfo_response.py |   33 ++++++++++++++++-------
 test/runner.py                                 |   18 +++++++++++--
 2 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/test/integ/connection/protocolinfo_response.py b/test/integ/connection/protocolinfo_response.py
index dfb5566..27b5f1f 100644
--- a/test/integ/connection/protocolinfo_response.py
+++ b/test/integ/connection/protocolinfo_response.py
@@ -21,8 +21,12 @@ class TestProtocolInfoResponse(unittest.TestCase):
     """
     
     runner = test.runner.get_runner()
+    connection_type = runner.get_connection_type()
+    
+    if connection_type == test.runner.TorConnection.NONE:
+      self.skipTest("(no connection)")
+    
     control_socket = runner.get_tor_socket(False)
-    if not control_socket: self.skipTest("(no control socket)")
     control_socket_file = control_socket.makefile()
     
     control_socket_file.write("PROTOCOLINFO\r\n")
@@ -38,15 +42,24 @@ class TestProtocolInfoResponse(unittest.TestCase):
     self.assertNotEqual(None, protocolinfo_response.tor_version)
     self.assertNotEqual(None, protocolinfo_response.auth_methods)
     
-    if runner.get_connection_type() != test.runner.TorConnection.NO_AUTH:
-      self.skipTest("(haven't yet implemented...)") # TODO: implement
-    
-    # TODO: The following is for the default integ test configuration. We
-    # should run tests that exercise all of tor's startup configs
-    # (password/cookie auth and control sockets)
-    
-    self.assertEqual((stem.connection.AuthMethod.NONE,), protocolinfo_response.auth_methods)
     self.assertEqual((), protocolinfo_response.unknown_auth_methods)
-    self.assertEqual(None, protocolinfo_response.cookie_file)
     self.assertEqual(None, protocolinfo_response.socket)
+    
+    if connection_type == test.runner.TorConnection.NO_AUTH:
+      self.assertEqual((stem.connection.AuthMethod.NONE,), protocolinfo_response.auth_methods)
+      self.assertEqual(None, protocolinfo_response.cookie_file)
+    elif connection_type == test.runner.TorConnection.PASSWORD:
+      self.assertEqual((stem.connection.AuthMethod.PASSWORD,), protocolinfo_response.auth_methods)
+      self.assertEqual(None, protocolinfo_response.cookie_file)
+    elif connection_type == test.runner.TorConnection.COOKIE:
+      self.assertEqual((stem.connection.AuthMethod.COOKIE,), protocolinfo_response.auth_methods)
+      self.assertEqual(runner.get_auth_cookie_path(), protocolinfo_response.cookie_file)
+    elif connection_type == test.runner.TorConnection.MULTIPLE:
+      self.assertEqual((stem.connection.AuthMethod.COOKIE, stem.connection.AuthMethod.PASSWORD), protocolinfo_response.auth_methods)
+      self.assertEqual(runner.get_auth_cookie_path(), protocolinfo_response.cookie_file)
+    elif connection_type == test.runner.TorConnection.SOCKET:
+      self.assertEqual((stem.connection.AuthMethod.NONE,), protocolinfo_response.auth_methods)
+      self.assertEqual(None, protocolinfo_response.cookie_file)
+    else:
+      self.fail("Unrecognized connection type: %s" % connection_type)
 
diff --git a/test/runner.py b/test/runner.py
index e39bd92..9d26deb 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -230,6 +230,20 @@ class Runner:
     test_dir = self._get("_test_dir")
     return os.path.join(test_dir, "torrc")
   
+  def get_auth_cookie_path(self):
+    """
+    Provides the absolute path for our authentication cookie if we have one.
+    
+    Returns:
+      str with our auth cookie path
+    
+    Raises:
+      RunnerStopped if we aren't running
+    """
+    
+    test_dir = self._get("_test_dir")
+    return os.path.join(test_dir, "control_auth_cookie")
+  
   def get_torrc_contents(self):
     """
     Provides the contents of our torrc.
@@ -282,7 +296,7 @@ class Runner:
     
     # TODO: replace with higher level connection functions when we have them
     
-    connection_type, test_dir = self.get_connection_type(), self._get("_test_dir")
+    connection_type, cookie_path = self.get_connection_type(), self.get_auth_cookie_path()
     if connection_type == None: return None
     
     conn_opts = CONNECTION_OPTS[connection_type]
@@ -299,8 +313,6 @@ class Runner:
       control_socket_file = control_socket.makefile()
       
       if OPT_COOKIE in conn_opts:
-        cookie_path = os.path.join(test_dir, "control_auth_cookie")
-        
         auth_cookie = open(cookie_path, "r")
         auth_cookie_contents = auth_cookie.read()
         auth_cookie.close()



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