[stem/master] Register unrecognized lines as new Tor capabilities
commit 22d1c1bccaa99814d621c840bc13fe6470442589 Author: Cristóbal <cristobal.leiva@usach.cl> Date: Fri Mar 20 21:25:45 2015 -0300 Register unrecognized lines as new Tor capabilities --- test/integ/control/controller.py | 9 +++++++- test/integ/descriptor/extrainfo_descriptor.py | 14 +++++++----- test/integ/descriptor/microdescriptor.py | 10 ++++++++- test/integ/descriptor/networkstatus.py | 30 ++++++++++++++++--------- test/integ/descriptor/server_descriptor.py | 4 ++-- 5 files changed, 47 insertions(+), 20 deletions(-) diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py index ca18292..2be5a17 100644 --- a/test/integ/control/controller.py +++ b/test/integ/control/controller.py @@ -26,6 +26,7 @@ from stem import Flag, Signal from stem.control import EventType, Listener, State from stem.exit_policy import ExitPolicy from stem.version import Requirement +from test.util import register_new_capability from test.runner import ( require_controller, @@ -1087,7 +1088,13 @@ class TestController(unittest.TestCase): unrecognized_lines = desc.get_unrecognized_lines() if unrecognized_lines: - self.fail('Unrecognized descriptor content: %s' % unrecognized_lines) + # Forward-compability: + # 1) SHOULD function at least as it does normally (ignore the unknown) + # 2) Report each of the aditional (unrecognized) fields to the user + + for line in unrecognized_lines: + key = line.split()[0] + register_new_capability(key, 'Network Descriptor Entry') count += 1 if count > 10: diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py index d102fea..92dcbf5 100644 --- a/test/integ/descriptor/extrainfo_descriptor.py +++ b/test/integ/descriptor/extrainfo_descriptor.py @@ -10,6 +10,8 @@ import test.runner from test.runner import only_run_once +from test.util import register_new_capability + class TestExtraInfoDescriptor(unittest.TestCase): @only_run_once @@ -41,10 +43,10 @@ class TestExtraInfoDescriptor(unittest.TestCase): elif desc.dir_v2_tunneled_dl_unknown: self.fail('Unrecognized stats on dirreq-v2-tunneled-dl lines: %s' % desc.dir_v2_tunneled_dl_unknown) elif unrecognized_lines: - # TODO: This isn't actually a problem, and rather than failing we - # should alert the user about these entries at the end of the tests - # (along with new events, getinfo options, and such). For now though - # there doesn't seem to be anything in practice to trigger this so - # failing to get our attention if it does. + # Forward-compability: + # 1) SHOULD function at least as it does normally (ignore the unknown) + # 2) Report each of the aditional (unrecognized) fields to the user - self.fail('Unrecognized descriptor content: %s' % unrecognized_lines) + for line in unrecognized_lines: + key = line.split()[0] + register_new_capability(key, 'Extrainfo Descriptor Entry') diff --git a/test/integ/descriptor/microdescriptor.py b/test/integ/descriptor/microdescriptor.py index ebd0287..0ea7ea1 100644 --- a/test/integ/descriptor/microdescriptor.py +++ b/test/integ/descriptor/microdescriptor.py @@ -10,6 +10,8 @@ import test.runner from test.runner import only_run_once +from test.util import register_new_capability + class TestMicrodescriptor(unittest.TestCase): @only_run_once @@ -31,4 +33,10 @@ class TestMicrodescriptor(unittest.TestCase): unrecognized_lines = desc.get_unrecognized_lines() if unrecognized_lines: - self.fail('Unrecognized microdescriptor content: %s' % unrecognized_lines) + # Forward-compability: + # 1) SHOULD function at least as it does normally (ignore the unknown) + # 2) Report each of the aditional (unrecognized) fields to the user + + for line in unrecognized_lines: + key = line.split()[0] + register_new_capability(key, 'Microdescriptor Descriptor Entry') diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py index 8f97b26..21fdaf1 100644 --- a/test/integ/descriptor/networkstatus.py +++ b/test/integ/descriptor/networkstatus.py @@ -13,6 +13,8 @@ import test.runner from test.runner import only_run_once +from test.util import register_new_capability + class TestNetworkStatus(unittest.TestCase): @only_run_once @@ -38,17 +40,21 @@ class TestNetworkStatus(unittest.TestCase): for router in stem.descriptor.parse_file(descriptor_file, 'network-status-consensus-3 1.0', validate = True): count += 1 - # check if there's any unknown flags - # TODO: this should be a 'new capability' check later rather than - # failing the tests + # check if there's any unknown flags and report them to the user for flag in router.flags: if flag not in stem.Flag: - raise ValueError('Unrecognized flag type: %s, found on relay %s (%s)' % (flag, router.fingerprint, router.nickname)) + register_new_capability(flag, 'Network Flag') unrecognized_lines = router.get_unrecognized_lines() if unrecognized_lines: - self.fail('Unrecognized descriptor content: %s' % unrecognized_lines) + # Forward-compability: + # 1) SHOULD function at least as it does normally (ignore the unknown) + # 2) Report each of the aditional (unrecognized) fields to the user + + for line in unrecognized_lines: + key = line.split()[0] + register_new_capability(key, 'Network Descriptor Entry') # Sanity test that there's at least a hundred relays. If that's not the # case then this probably isn't a real, complete tor consensus. @@ -75,16 +81,20 @@ class TestNetworkStatus(unittest.TestCase): for router in stem.descriptor.parse_file(descriptor_file, 'network-status-microdesc-consensus-3 1.0', validate = True): count += 1 - # check if there's any unknown flags - # TODO: this should be a 'new capability' check later rather than - # failing the tests + # check if there's any unknown flags and report them to the user for flag in router.flags: if flag not in stem.Flag: - raise ValueError('Unrecognized flag type: %s, found on microdescriptor relay %s (%s)' % (flag, router.fingerprint, router.nickname)) + register_new_capability(flag, 'Network Flag') unrecognized_lines = router.get_unrecognized_lines() if unrecognized_lines: - self.fail('Unrecognized descriptor content: %s' % unrecognized_lines) + # Forward-compability: + # 1) SHOULD function at least as it does normally (ignore the unknown) + # 2) Report each of the aditional (unrecognized) fields to the user + + for line in unrecognized_lines: + key = line.split()[0] + register_new_capability(key, 'Network Descriptor Entry') self.assertTrue(count > 100) diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py index e7d49fd..1404cfa 100644 --- a/test/integ/descriptor/server_descriptor.py +++ b/test/integ/descriptor/server_descriptor.py @@ -11,7 +11,7 @@ import test.runner from test.runner import only_run_once -import test.util +from test.util import register_new_capability class TestServerDescriptor(unittest.TestCase): @@ -46,4 +46,4 @@ class TestServerDescriptor(unittest.TestCase): for line in unrecognized_lines: key = line.split()[0] - test.util.register_new_capability(key, 'Server Descriptor Entry') + register_new_capability(key, 'Server Descriptor Entry')
participants (1)
-
atagar@torproject.org