[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Fixing relative cookie expansion test
commit 5b505ec579ab7edcaf55d1e35a2ccd3b9aee6672
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Nov 26 10:10:21 2011 -0800
Fixing relative cookie expansion test
A couple protocolinfo tests filtered system calls so that pid lookups by
process name would fall and we'd fall back on looking it up by the control port
or socket file (to exercise alternative code paths). However, I'd forgotten
that this would also filter out the get_cwd lookup calls, causing those tests
to fail.
The relative cookie expansion by socket file wasn't being exercised at all
because I didn't have a integ test configuration where we had both a control
socket and authentication cookie. I've added this test now and fixed this issue
with the socket test too.
---
run_tests.py | 4 ++-
test/integ/connection/protocolinfo.py | 34 +++++++++++++++++++++++---------
test/runner.py | 3 +-
test/testrc.sample | 1 +
4 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/run_tests.py b/run_tests.py
index 800cab2..8dd141e 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -47,7 +47,7 @@ INTEG_TESTS = (("stem.socket.ControlMessage", test.integ.socket.control_message.
)
# Integration tests above the basic suite.
-TARGETS = stem.util.enum.Enum(*[(v, v) for v in ("ONLINE", "RELATIVE", "CONN_NONE", "CONN_OPEN", "CONN_PASSWORD", "CONN_COOKIE", "CONN_MULTIPLE", "CONN_SOCKET", "CONN_ALL")])
+TARGETS = stem.util.enum.Enum(*[(v, v) for v in ("ONLINE", "RELATIVE", "CONN_NONE", "CONN_OPEN", "CONN_PASSWORD", "CONN_COOKIE", "CONN_MULTIPLE", "CONN_SOCKET", "CONN_SCOOKIE", "CONN_ALL")])
TARGET_ATTR = {
TARGETS.ONLINE: ("test.integ.target.online", "Includes tests that require network activity."),
@@ -58,6 +58,7 @@ TARGET_ATTR = {
TARGETS.CONN_COOKIE: ("test.integ.target.connection.cookie", "Configuration with an authentication cookie."),
TARGETS.CONN_MULTIPLE: ("test.integ.target.connection.multiple", "Configuration with both password and cookie authentication."),
TARGETS.CONN_SOCKET: ("test.integ.target.connection.socket", "Configuration with a control socket."),
+ TARGETS.CONN_SCOOKIE: ("test.integ.target.connection.scookie", "Configuration with a control socket and authentication cookie."),
TARGETS.CONN_ALL: ("test.integ.target.connection.all", "Runs integration tests for all connection configurations."),
}
@@ -220,6 +221,7 @@ if __name__ == '__main__':
"cookie": test.runner.TorConnection.COOKIE,
"multiple": test.runner.TorConnection.MULTIPLE,
"socket": test.runner.TorConnection.SOCKET,
+ "scookie": test.runner.TorConnection.SCOOKIE,
}
for type_key in conn_type_mappings:
diff --git a/test/integ/connection/protocolinfo.py b/test/integ/connection/protocolinfo.py
index 71d2d6c..8c23329 100644
--- a/test/integ/connection/protocolinfo.py
+++ b/test/integ/connection/protocolinfo.py
@@ -16,6 +16,10 @@ class TestProtocolInfo(unittest.TestCase):
integ target to exercise the widest range of use cases.
"""
+ def tearDown(self):
+ # resets call mocking back to being disabled
+ stem.util.system.CALL_MOCKING = None
+
def test_parsing(self):
"""
Makes a PROTOCOLINFO query and processes the response for our control
@@ -53,15 +57,17 @@ class TestProtocolInfo(unittest.TestCase):
# If we have both the 'RELATIVE' target and a cookie then test_parsing
# should exercise cookie expansion using a pid lookup by process name.
# Disabling those lookups so we exercise the lookup by port/socket file
- # too.
+ # too. Gotta remember the get_cwd functions too.
- port_lookup_prefixes = (
+ cwd_by_port_lookup_prefixes = (
stem.util.system.GET_PID_BY_PORT_NETSTAT,
stem.util.system.GET_PID_BY_PORT_SOCKSTAT % "",
- stem.util.system.GET_PID_BY_PORT_LSOF)
+ stem.util.system.GET_PID_BY_PORT_LSOF,
+ stem.util.system.GET_CWD_PWDX % "",
+ "lsof -a -p ")
def port_lookup_filter(command):
- for prefix in port_lookup_prefixes:
+ for prefix in cwd_by_port_lookup_prefixes:
if command.startswith(prefix): return True
return False
@@ -76,16 +82,24 @@ class TestProtocolInfo(unittest.TestCase):
else:
# we don't have a control port
self.assertRaises(stem.socket.SocketError, stem.connection.get_protocolinfo_by_port, "127.0.0.1", test.runner.CONTROL_PORT)
-
- stem.util.system.CALL_MOCKING = None
def test_get_protocolinfo_by_socket(self):
"""
Exercises the stem.connection.get_protocolinfo_by_socket function.
"""
- socket_file_prefix = stem.util.system.GET_PID_BY_FILE_LSOF % ""
- stem.util.system.CALL_MOCKING = lambda cmd: cmd.startswith(socket_file_prefix)
+ cwd_by_socket_lookup_prefixes = (
+ stem.util.system.GET_PID_BY_FILE_LSOF % "",
+ stem.util.system.GET_CWD_PWDX % "",
+ "lsof -a -p ")
+
+ def socket_lookup_filter(command):
+ for prefix in cwd_by_socket_lookup_prefixes:
+ if command.startswith(prefix): return True
+
+ return False
+
+ stem.util.system.CALL_MOCKING = socket_lookup_filter
connection_type = test.runner.get_runner().get_connection_type()
if test.runner.OPT_SOCKET in test.runner.CONNECTION_OPTS[connection_type]:
@@ -95,8 +109,6 @@ class TestProtocolInfo(unittest.TestCase):
else:
# we don't have a control socket
self.assertRaises(stem.socket.SocketError, stem.connection.get_protocolinfo_by_socket, test.runner.CONTROL_SOCKET_PATH)
-
- stem.util.system.CALL_MOCKING = None
def assert_protocolinfo_attr(self, protocolinfo_response, connection_type):
"""
@@ -117,6 +129,8 @@ class TestProtocolInfo(unittest.TestCase):
auth_methods = (stem.connection.AuthMethod.COOKIE, stem.connection.AuthMethod.PASSWORD)
elif connection_type == test.runner.TorConnection.SOCKET:
auth_methods = (stem.connection.AuthMethod.NONE,)
+ elif connection_type == test.runner.TorConnection.SCOOKIE:
+ auth_methods = (stem.connection.AuthMethod.COOKIE,)
else:
self.fail("Unrecognized connection type: %s" % connection_type)
diff --git a/test/runner.py b/test/runner.py
index 89208e3..52e9d25 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -42,7 +42,7 @@ DEFAULT_CONFIG = {
# Methods for connecting to tor. General integration tests only run with the
# DEFAULT_TOR_CONNECTION, but expanded integ tests will run with all of them.
-TorConnection = stem.util.enum.Enum("NONE", "OPEN", "PASSWORD", "COOKIE", "MULTIPLE", "SOCKET")
+TorConnection = stem.util.enum.Enum("NONE", "OPEN", "PASSWORD", "COOKIE", "MULTIPLE", "SOCKET", "SCOOKIE")
DEFAULT_TOR_CONNECTION = TorConnection.OPEN
STATUS_ATTR = (term.Color.BLUE, term.Attr.BOLD)
@@ -80,6 +80,7 @@ CONNECTION_OPTS = {
TorConnection.COOKIE: [OPT_PORT, OPT_COOKIE],
TorConnection.MULTIPLE: [OPT_PORT, OPT_PASSWORD, OPT_COOKIE],
TorConnection.SOCKET: [OPT_SOCKET],
+ TorConnection.SCOOKIE: [OPT_SOCKET, OPT_COOKIE],
}
def get_runner():
diff --git a/test/testrc.sample b/test/testrc.sample
index 28874e9..f0b917d 100644
--- a/test/testrc.sample
+++ b/test/testrc.sample
@@ -40,5 +40,6 @@ test.integ.target.connection.password false
test.integ.target.connection.cookie false
test.integ.target.connection.muiltipe false
test.integ.target.connection.socket false
+test.integ.target.connection.scookie false
test.integ.target.connection.all false
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits