[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Allow blank values in bandwidth-file-headers fields
commit abf2579bb302df35f64eb9f38eb8b680d103508c
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Jul 22 12:47:47 2018 -0700
Allow blank values in bandwidth-file-headers fields
The initial dir-spec definition of this field allowed blank values. Then it got
revised to disallow them. Now they're allowed again. ;P
https://gitweb.torproject.org/torspec.git/commit/?id=2cce07d
No big whoop. Until we cut a release this is easy to twiddle.
---
stem/descriptor/networkstatus.py | 4 ++--
test/unit/descriptor/networkstatus/document_v3.py | 20 ++++++--------------
2 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index f9245b43..57098e81 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -778,14 +778,14 @@ def _parse_shared_rand_current_value(descriptor, entries):
def _parse_bandwidth_file_headers(descriptor, entries):
# "bandwidth-file-headers" KeyValues
- # KeyValues ::= KeyValue | KeyValues SP KeyValue
+ # KeyValues ::= "" | KeyValue | KeyValues SP KeyValue
# KeyValue ::= Keyword '=' Value
# Value ::= ArgumentChar+
value = _value('bandwidth-file-headers', entries)
results = {}
- for key, val in _mappings_for('bandwidth-file-headers', value, require_value = True):
+ for key, val in _mappings_for('bandwidth-file-headers', value):
results[key] = val
descriptor.bandwidth_file_headers = results
diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py
index fca7a0af..b15a9aac 100644
--- a/test/unit/descriptor/networkstatus/document_v3.py
+++ b/test/unit/descriptor/networkstatus/document_v3.py
@@ -1262,6 +1262,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
test_values = {
'': {},
+ 'timestamp=': {'timestamp': ''},
'timestamp=12=34': {'timestamp': '12=34'},
'timestamp=123': {'timestamp': '123'},
'timestamp=123 version=1.0': {'timestamp': '123', 'version': '1.0'},
@@ -1272,22 +1273,13 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
document = NetworkStatusDocumentV3.create({'vote-status': 'vote', 'bandwidth-file-headers': test_value})
self.assertEqual(expected_value, document.bandwidth_file_headers)
- def test_bandwidth_file_headers_malformed(self):
- """
- Parses 'bandwidth-file-headers' with invalid content.
- """
-
- test_values = (
- 'timestamp=',
- 'key_without_value',
- )
+ # field must be key=value mappings
- for attr in test_values:
- content = NetworkStatusDocumentV3.content({'vote-status': 'vote', 'bandwidth-file-headers': attr})
- self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
+ content = NetworkStatusDocumentV3.content({'vote-status': 'vote', 'bandwidth-file-headers': 'key_without_value'})
+ self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
- document = NetworkStatusDocumentV3(content, False)
- self.assertEqual({}, document.bandwidth_file_headers)
+ document = NetworkStatusDocumentV3(content, False)
+ self.assertEqual({}, document.bandwidth_file_headers)
def test_with_legacy_directory_authorities(self):
"""
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits