[tor-commits] [stem/master] Fix when router status entries have duplicate lines

atagar at torproject.org atagar at torproject.org
Sat Oct 13 18:35:45 UTC 2012


commit a09b1e038fc97dada370e01ad8fd0c4f81b90c12
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Oct 4 09:39:27 2012 -0700

    Fix when router status entries have duplicate lines
    
    Spotted a bug with the RouterStatusEntry where we have an undefined 'key'
    variable when validating that we don't have any duplicate entries. Turns out
    that this use case wasn't being tested so added a unit test to exercise the bug
    first.
---
 stem/descriptor/networkstatus.py            |    2 +-
 test/unit/descriptor/networkstatus/entry.py |   14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index c27f587..fa02e44 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -1114,7 +1114,7 @@ class RouterStatusEntry(stem.descriptor.Descriptor):
       
       # most attributes can only appear at most once
       if validate and len(values) > 1 and keyword in ('r', 's', 'v', 'w', 'p'):
-        raise ValueError("Router status entries can only have a single '%s' line, got %i:\n%s" % (key, len(values), content))
+        raise ValueError("Router status entries can only have a single '%s' line, got %i:\n%s" % (keyword, len(values), content))
       
       if keyword == 'r':
         # "r" nickname identity digest publication IP ORPort DirPort
diff --git a/test/unit/descriptor/networkstatus/entry.py b/test/unit/descriptor/networkstatus/entry.py
index a0ece4d..6400f2b 100644
--- a/test/unit/descriptor/networkstatus/entry.py
+++ b/test/unit/descriptor/networkstatus/entry.py
@@ -100,6 +100,20 @@ class TestRouterStatusEntry(unittest.TestCase):
     entry = RouterStatusEntry(content)
     self.assertEqual("Tor 0.2.2.35", entry.version_line)
   
+  def test_duplicate_lines(self):
+    """
+    Duplicates linesin the entry.
+    """
+    
+    lines = get_router_status_entry(content = True).split("\n")
+    
+    for i in xrange(len(lines)):
+      content = "\n".join(lines[:i] + [lines[i]] + lines[i:])
+      self.assertRaises(ValueError, RouterStatusEntry, content)
+      
+      entry = RouterStatusEntry(content, False)
+      self.assertEqual("caerSidi", entry.nickname)
+  
   def test_missing_r_field(self):
     """
     Excludes fields from the 'r' line.





More information about the tor-commits mailing list