[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Replacing get_server_descriptor() and get_network_status() tests
commit db19cafb398e9626502cf9d1226803a5fb4cb4b1
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Mar 2 19:57:57 2013 -0800
Replacing get_server_descriptor() and get_network_status() tests
Our integration tests for get_server_descriptor() and get_network_status() have
been skipped for quite some time due to...
https://trac.torproject.org/7163
Replacing them with a simpler (and hopefully more reliable) test like what
we're now doing for get_microdescriptor().
---
stem/version.py | 2 +
test/integ/control/controller.py | 95 +++++++++++++++++---------------------
2 files changed, 44 insertions(+), 53 deletions(-)
diff --git a/stem/version.py b/stem/version.py
index b138f8b..fcf628e 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -47,6 +47,7 @@ easily parsed and compared, for instance...
**FEATURE_VERBOSE_NAMES** 'VERBOSE_NAMES' optional feature
**GETINFO_CONFIG_TEXT** 'GETINFO config-text' query
**LOADCONF** LOADCONF requests
+ **MICRODESCRIPTOR_IS_DEFAULT** Tor gets microdescriptors by default rather than server descriptors
**TAKEOWNERSHIP** TAKEOWNERSHIP requests
**TORRC_CONTROL_SOCKET** 'ControlSocket <path>' config option
**TORRC_PORT_FORWARDING** 'PortForwarding' config option
@@ -305,6 +306,7 @@ Requirement = stem.util.enum.Enum(
("FEATURE_VERBOSE_NAMES", Version("0.2.2.1-alpha")),
("GETINFO_CONFIG_TEXT", Version("0.2.2.7-alpha")),
("LOADCONF", Version("0.2.1.1")),
+ ("MICRODESCRIPTOR_IS_DEFAULT", Version("0.2.3.25")),
("TAKEOWNERSHIP", Version("0.2.2.28-beta")),
("TORRC_CONTROL_SOCKET", Version("0.2.0.30")),
("TORRC_PORT_FORWARDING", Version("0.2.3.1-alpha")),
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 23966a9..42006c4 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -4,7 +4,6 @@ Integration tests for the stem.control.Controller class.
from __future__ import with_statement
-import os
import shutil
import socket
import tempfile
@@ -28,6 +27,11 @@ from stem.control import EventType, State
from stem.exit_policy import ExitPolicy
from stem.version import Requirement
+# Router status entry for a relay with a nickname other than 'Unnamed'. This is
+# used for a few tests that need to look up a relay.
+
+TEST_ROUTER_STATUS_ENTRY = None
+
class TestController(unittest.TestCase):
def test_from_port(self):
@@ -802,6 +806,8 @@ class TestController(unittest.TestCase):
if test.runner.require_control(self):
return
+ elif test.runner.require_version(self, Requirement.MICRODESCRIPTOR_IS_DEFAULT):
+ return
with test.runner.get_runner().get_tor_controller() as controller:
# we should balk at invalid content
@@ -814,36 +820,24 @@ class TestController(unittest.TestCase):
self.assertRaises(stem.ControllerError, controller.get_microdescriptor, "blargg")
self.assertRaises(stem.ControllerError, controller.get_microdescriptor, "5" * 40)
- # microdescriptors exclude the fingerprint and nickname so checking the
- # consensus to get the nickname and fingerprint of a relay
-
- test_router_status_entry = None
+ test_relay = self._get_router_status_entry(controller)
- for desc in controller.get_network_statuses():
- if desc.nickname != "Unnamed":
- test_router_status_entry = desc
- break
-
- if test_router_status_entry is None:
- self.fail("Unable to find any relays without a nickname of 'Unnamed'")
-
- md_by_fingerprint = controller.get_microdescriptor(test_router_status_entry.fingerprint)
- md_by_nickname = controller.get_microdescriptor(test_router_status_entry.nickname)
+ md_by_fingerprint = controller.get_microdescriptor(test_relay.fingerprint)
+ md_by_nickname = controller.get_microdescriptor(test_relay.nickname)
self.assertEqual(md_by_fingerprint, md_by_nickname)
def test_get_server_descriptor(self):
"""
- Compares get_server_descriptor() against our cached descriptors.
+ Basic checks for get_server_descriptor().
"""
runner = test.runner.get_runner()
- descriptor_path = runner.get_test_dir("cached-descriptors")
if test.runner.require_control(self):
return
- elif not os.path.exists(descriptor_path):
- test.runner.skip(self, "(no cached descriptors)")
+ elif runner.get_tor_version() >= Requirement.MICRODESCRIPTOR_IS_DEFAULT:
+ test.runner.skip(self, "(requires server descriptors)")
return
with runner.get_tor_controller() as controller:
@@ -857,18 +851,12 @@ class TestController(unittest.TestCase):
self.assertRaises(stem.ControllerError, controller.get_server_descriptor, "blargg")
self.assertRaises(stem.ControllerError, controller.get_server_descriptor, "5" * 40)
- test.runner.skip(self, "(https://trac.torproject.org/7163)")
- return
+ test_relay = self._get_router_status_entry(controller)
- first_descriptor = None
- with stem.descriptor.reader.DescriptorReader([descriptor_path]) as reader:
- for desc in reader:
- if desc.nickname != "Unnamed":
- first_descriptor = desc
- break
+ desc_by_fingerprint = controller.get_server_descriptor(test_relay.fingerprint)
+ desc_by_nickname = controller.get_server_descriptor(test_relay.nickname)
- self.assertEqual(first_descriptor, controller.get_server_descriptor(first_descriptor.fingerprint))
- self.assertEqual(first_descriptor, controller.get_server_descriptor(first_descriptor.nickname))
+ self.assertEqual(desc_by_fingerprint, desc_by_nickname)
def test_get_server_descriptors(self):
"""
@@ -897,19 +885,13 @@ class TestController(unittest.TestCase):
def test_get_network_status(self):
"""
- Compares get_network_status() against our cached descriptors.
+ Basic checks for get_network_status().
"""
- runner = test.runner.get_runner()
- descriptor_path = runner.get_test_dir("cached-consensus")
-
if test.runner.require_control(self):
return
- elif not os.path.exists(descriptor_path):
- test.runner.skip(self, "(no cached descriptors)")
- return
- with runner.get_tor_controller() as controller:
+ with test.runner.get_runner().get_tor_controller() as controller:
# we should balk at invalid content
self.assertRaises(ValueError, controller.get_network_status, None)
self.assertRaises(ValueError, controller.get_network_status, "")
@@ -920,24 +902,12 @@ class TestController(unittest.TestCase):
self.assertRaises(stem.ControllerError, controller.get_network_status, "blargg")
self.assertRaises(stem.ControllerError, controller.get_network_status, "5" * 40)
- # our cached consensus is v3 but the control port can only be queried for
- # v2 or v1 network status information
-
- test.runner.skip(self, "(https://trac.torproject.org/7163)")
- return
-
- first_descriptor = None
- with stem.descriptor.reader.DescriptorReader([descriptor_path]) as reader:
- for desc in reader:
- if desc.nickname != "Unnamed":
- # truncate to just the first couple lines and reconstruct as a v2 entry
- truncated_content = "\n".join(str(desc).split("\n")[:2])
+ test_relay = self._get_router_status_entry(controller)
- first_descriptor = stem.descriptor.router_status_entry.RouterStatusEntryV2(truncated_content)
- break
+ desc_by_fingerprint = controller.get_network_status(test_relay.fingerprint)
+ desc_by_nickname = controller.get_network_status(test_relay.nickname)
- self.assertEqual(first_descriptor, controller.get_network_status(first_descriptor.fingerprint))
- self.assertEqual(first_descriptor, controller.get_network_status(first_descriptor.nickname))
+ self.assertEqual(desc_by_fingerprint, desc_by_nickname)
def test_get_network_statuses(self):
"""
@@ -1009,3 +979,22 @@ class TestController(unittest.TestCase):
new_circ = controller.new_circuit()
circuits = controller.get_circuits()
self.assertTrue(new_circ in [circ.id for circ in circuits])
+
+ def _get_router_status_entry(self, controller):
+ """
+ Provides a router status entry for a relay with a nickname other than
+ 'Unnamed'. This fails the test if unable to find one.
+ """
+
+ global TEST_ROUTER_STATUS_ENTRY
+
+ if TEST_ROUTER_STATUS_ENTRY is None:
+ for desc in controller.get_network_statuses():
+ if desc.nickname != "Unnamed":
+ TEST_ROUTER_STATUS_ENTRY = desc
+ break
+
+ if TEST_ROUTER_STATUS_ENTRY is None:
+ self.fail("Unable to find any relays without a nickname of 'Unnamed'")
+
+ return TEST_ROUTER_STATUS_ENTRY
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits