[tor-commits] [stem/master] Dropping validation on bandwidth-weights contents
atagar at torproject.org
atagar at torproject.org
Mon May 27 01:30:45 UTC 2013
commit 7b396bdcebe7165df6ea6aaa911707e74974fa38
Author: Damian Johnson <atagar at torproject.org>
Date: Sun May 26 18:14:15 2013 -0700
Dropping validation on bandwidth-weights contents
Our validation of network status documents included checking for the
bandwidth-weights specified in the spec. This is because, according to the
spec, they were all mandatory and new weights could not be added. Tor has
loosened this restriction...
https://gitweb.torproject.org/torspec.git/commitdiff/ec3eaca
https://trac.torproject.org/6872
---
stem/descriptor/networkstatus.py | 17 -----------
test/unit/descriptor/networkstatus/document_v3.py | 34 +++++----------------
2 files changed, 8 insertions(+), 43 deletions(-)
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index 1081b10..f65c7dc 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -137,14 +137,6 @@ KEY_CERTIFICATE_PARAMS = (
('dir-key-certification', True),
)
-BANDWIDTH_WEIGHT_ENTRIES = (
- "Wbd", "Wbe", "Wbg", "Wbm",
- "Wdb",
- "Web", "Wed", "Wee", "Weg", "Wem",
- "Wgb", "Wgd", "Wgg", "Wgm",
- "Wmb", "Wmd", "Wme", "Wmg", "Wmm",
-)
-
def _parse_file(document_file, document_type = None, validate = True, is_microdescriptor = False, document_handler = stem.descriptor.DocumentHandler.ENTRIES):
"""
@@ -837,15 +829,6 @@ class _DocumentFooter(object):
raise ValueError("A network status document's 'directory-footer' line shouldn't have any content, got '%s'" % line)
elif keyword == "bandwidth-weights":
self.bandwidth_weights = _parse_int_mappings(keyword, value, validate)
-
- if validate:
- weight_keys = tuple(sorted(self.bandwidth_weights.keys()))
-
- if weight_keys != BANDWIDTH_WEIGHT_ENTRIES:
- expected_label = ', '.join(BANDWIDTH_WEIGHT_ENTRIES)
- actual_label = ', '.join(weight_keys)
-
- raise ValueError("A network status document's 'bandwidth-weights' entries should be '%s', got '%s'" % (expected_label, actual_label))
elif keyword == "directory-signature":
for sig_value, block_contents in values:
if not sig_value.count(" ") in (1, 2) or not block_contents:
diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py
index 4984e67..366b516 100644
--- a/test/unit/descriptor/networkstatus/document_v3.py
+++ b/test/unit/descriptor/networkstatus/document_v3.py
@@ -14,7 +14,6 @@ from stem import Flag
from stem.descriptor.networkstatus import HEADER_STATUS_DOCUMENT_FIELDS, \
FOOTER_STATUS_DOCUMENT_FIELDS, \
DEFAULT_PARAMS, \
- BANDWIDTH_WEIGHT_ENTRIES, \
DirectoryAuthority, \
NetworkStatusDocumentV3, \
_parse_file
@@ -31,6 +30,14 @@ from test.mocking import get_router_status_entry_v3, \
DOC_SIG, \
NETWORK_STATUS_DOCUMENT_FOOTER
+BANDWIDTH_WEIGHT_ENTRIES = (
+ "Wbd", "Wbe", "Wbg", "Wbm",
+ "Wdb",
+ "Web", "Wed", "Wee", "Weg", "Wem",
+ "Wgb", "Wgd", "Wgg", "Wgm",
+ "Wmb", "Wmd", "Wme", "Wmg", "Wmm",
+)
+
class TestNetworkStatusDocument(unittest.TestCase):
def test_minimal_consensus(self):
@@ -720,31 +727,6 @@ class TestNetworkStatusDocument(unittest.TestCase):
document = NetworkStatusDocumentV3(content, False)
self.assertEquals(expected, document.bandwidth_weights)
- def test_bandwidth_wights_omissions(self):
- """
- Leaves entries out of the 'bandwidth-wights' line.
- """
-
- # try parsing an empty value
-
- content = get_network_status_document_v3({"bandwidth-weights": ""}, content = True)
- self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
-
- document = NetworkStatusDocumentV3(content, False)
- self.assertEquals({}, document.bandwidth_weights)
-
- # drop individual values
-
- for missing_entry in BANDWIDTH_WEIGHT_ENTRIES:
- weight_entries = ["%s=5" % e for e in BANDWIDTH_WEIGHT_ENTRIES if e != missing_entry]
- expected = dict([(e, 5) for e in BANDWIDTH_WEIGHT_ENTRIES if e != missing_entry])
-
- content = get_network_status_document_v3({"bandwidth-weights": " ".join(weight_entries)}, content = True)
- self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
-
- document = NetworkStatusDocumentV3(content, False)
- self.assertEquals(expected, document.bandwidth_weights)
-
def test_microdescriptor_signature(self):
"""
The 'directory-signature' lines both with and without a defined method for
More information about the tor-commits
mailing list