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

[tor-commits] [stem/master] Handling empty read/write-history value listings



commit 707897bea765b3d403dea9eaf4a3a0788a455bd0
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Apr 14 17:23:03 2012 -0700

    Handling empty read/write-history value listings
    
    Bug where relay server descriptors with read/write-history lines but no values
    on them would fail validation. Added a unit test for this and fixed the bug.
---
 stem/descriptor/server_descriptor.py      |   17 +++++++++--------
 test/unit/descriptor/server_descriptor.py |   13 +++++++++++++
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 6892381..780e7b5 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -522,14 +522,15 @@ class ServerDescriptorV3(stem.descriptor.Descriptor):
         elif validate:
           raise ValueError("%s line's interval wasn't a number: %s" % (keyword, line))
         
-        for sampling in history_values.split(","):
-          if sampling.isdigit():
-            if is_read: self.read_history_values.append(int(sampling))
-            else: self.write_history_values.append(int(sampling))
-          else:
-            if validate:
-              raise ValueError("%s line has non-numeric values: %s" % (keyword, line))
-            else: break
+        if history_values != '':
+          for sampling in history_values.split(","):
+            if sampling.isdigit():
+              if is_read: self.read_history_values.append(int(sampling))
+              else: self.write_history_values.append(int(sampling))
+            else:
+              if validate:
+                raise ValueError("%s line has non-numeric values: %s" % (keyword, line))
+              else: break
       else:
         self._unrecognized_lines.append(line)
   
diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py
index 5c4cfce..d170e96 100644
--- a/test/unit/descriptor/server_descriptor.py
+++ b/test/unit/descriptor/server_descriptor.py
@@ -249,6 +249,19 @@ class TestServerDescriptor(unittest.TestCase):
       self.assertEquals(900, attr[2])
       self.assertEquals(expected_values, attr[3])
   
+  def test_read_history_empty(self):
+    """
+    Parses a read-history with an empty value.
+    """
+    
+    value = "2005-12-17 01:23:11 (900 s) "
+    desc_text = _make_descriptor({"opt read-history": value})
+    desc = RelayDescriptorV3(desc_text)
+    self.assertEquals(value, desc.read_history)
+    self.assertEquals(datetime.datetime(2005, 12, 17, 1, 23, 11), desc.read_history_end)
+    self.assertEquals(900, desc.read_history_interval)
+    self.assertEquals([], desc.read_history_values)
+  
   def test_annotations(self):
     """
     Checks that content before a descriptor are parsed as annotations.



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