[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Validation for params fails due to ordering



commit 40fd99d8f14261f8221734e837ea0db1028dd127
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Jan 27 19:17:15 2017 -0800

    Validation for params fails due to ordering
    
    We check that a params attribute is only supplied in consensus methods that
    should have it. However, we checked it before the value might be set.
    
    I'm not sure why this only surfaced with recent changes but unit tests failed
    for this reason.
---
 stem/descriptor/__init__.py      |  2 +-
 stem/descriptor/networkstatus.py | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 0d4e73e..ee0b289 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -643,7 +643,7 @@ class Descriptor(object):
 
   def __getattr__(self, name):
     # If an attribute we should have isn't present it means either...
-    #    
+    #
     #   a. we still need to lazy load this
     #   b. we read the whole descriptor but it wasn't present, so needs the default
 
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index 9818624..78b453b 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -638,11 +638,6 @@ def _parse_header_parameters_line(descriptor, entries):
 
   value = _value('params', entries)
 
-  # should only appear in consensus-method 7 or later
-
-  if not descriptor.meets_consensus_method(7):
-    raise ValueError("A network status document's 'params' line should only appear in consensus-method 7 or later")
-
   if value != '':
     descriptor.params = _parse_int_mappings('params', value, True)
     descriptor._check_params_constraints()
@@ -998,6 +993,11 @@ class NetworkStatusDocumentV3(NetworkStatusDocument):
 
       self._parse(entries, validate, parser_for_line = self.HEADER_PARSER_FOR_LINE)
 
+      # should only appear in consensus-method 7 or later
+
+      if not self.meets_consensus_method(7) and 'params' in list(entries.keys()):
+        raise ValueError("A network status document's 'params' line should only appear in consensus-method 7 or later")
+
       _check_for_missing_and_disallowed_fields(self, entries, HEADER_STATUS_DOCUMENT_FIELDS)
 
       # default consensus_method and consensus_methods based on if we're a consensus or vote



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits