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

[tor-commits] [stem/master] Unit tests for minimal v2 and microdescriptor v3 router status entries



commit a1d2a0ffffd5aeec96c37fbbf1b4134c9b34b631
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Oct 7 18:18:14 2012 -0700

    Unit tests for minimal v2 and microdescriptor v3 router status entries
    
    Tests to exercise basic parsing for the v2 and microdescriptor v3
    RouterStatusEntry subclasses. They're both largely a subset of the v3
    RouterStatusEntry so I don't plan to add additional tests for the moment.
---
 stem/descriptor/router_status_entry.py      |    2 +-
 test/mocking.py                             |   74 ++++++++++++++++++++++++---
 test/unit/descriptor/router_status_entry.py |   47 ++++++++++++++++-
 3 files changed, 111 insertions(+), 12 deletions(-)

diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 50f0825..f663f07 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -285,7 +285,7 @@ class RouterStatusEntryMicroV3(RouterStatusEntry):
     
     self.digest = None
     
-    super(RouterStatusEntryMicroV3, self).__init__(content)
+    super(RouterStatusEntryMicroV3, self).__init__(content, validate, document)
   
   def _parse(self, entries, validate):
     for keyword, values in entries.items():
diff --git a/test/mocking.py b/test/mocking.py
index 808cb8d..7c848ad 100644
--- a/test/mocking.py
+++ b/test/mocking.py
@@ -23,14 +23,24 @@ calling :func:`test.mocking.revert_mocking`.
   Instance Constructors
     get_message                     - stem.socket.ControlMessage
     get_protocolinfo_response       - stem.response.protocolinfo.ProtocolInfoResponse
-    get_relay_server_descriptor     - stem.descriptor.server_descriptor.RelayDescriptor
-    get_bridge_server_descriptor    - stem.descriptor.server_descriptor.BridgeDescriptor
-    get_relay_extrainfo_descriptor  - stem.descriptor.extrainfo_descriptor.RelayExtraInfoDescriptor
-    get_bridge_extrainfo_descriptor - stem.descriptor.extrainfo_descriptor.BridgeExtraInfoDescriptor
-    get_router_status_entry_v3      - stem.descriptor.router_status_entry.RouterStatusEntryV3
-    get_directory_authority         - stem.descriptor.networkstatus.DirectoryAuthority
-    get_key_certificate             - stem.descriptor.networkstatus.KeyCertificate
-    get_network_status_document     - stem.descriptor.networkstatus.NetworkStatusDocument
+    
+    stem.descriptor.server_descriptor
+      get_relay_server_descriptor  - RelayDescriptor
+      get_bridge_server_descriptor - BridgeDescriptor
+    
+    stem.descriptor.extrainfo_descriptor
+      get_relay_extrainfo_descriptor  - RelayExtraInfoDescriptor
+      get_bridge_extrainfo_descriptor - BridgeExtraInfoDescriptor
+    
+    stem.descriptor.networkstatus
+      get_directory_authority     - DirectoryAuthority
+      get_key_certificate         - KeyCertificate
+      get_network_status_document - NetworkStatusDocument
+    
+    stem.descriptor.router_status_entry
+      get_router_status_entry_v2       - RouterStatusEntryV2
+      get_router_status_entry_v3       - RouterStatusEntryV3
+      get_router_status_entry_micro_v3 - RouterStatusEntryMicroV3
 """
 
 import inspect
@@ -107,11 +117,21 @@ BRIDGE_EXTRAINFO_FOOTER = (
   ("router-digest", "006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4"),
 )
 
+ROUTER_STATUS_ENTRY_V2_HEADER = (
+  ("r", "caerSidi p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE 2012-08-06 11:19:31 71.35.150.29 9001 0"),
+)
+
 ROUTER_STATUS_ENTRY_V3_HEADER = (
   ("r", "caerSidi p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE 2012-08-06 11:19:31 71.35.150.29 9001 0"),
   ("s", "Fast Named Running Stable Valid"),
 )
 
+ROUTER_STATUS_ENTRY_MICRO_V3_HEADER = (
+  ("r", "Konata ARIJF2zbqirB9IwsW0mQznccWww 2012-09-24 13:40:40 69.64.48.168 9001 9030"),
+  ("m", "aiUklwBrua82obG5AsTX+iEpkjQA2+AQHxZ7GwMfY70"),
+  ("s", "Fast Guard HSDir Named Running Stable V2Dir Valid"),
+)
+
 AUTHORITY_HEADER = (
   ("dir-source", "turtles 27B6B5996C426270A5C95488AA5BCEB6BCC86956 no.place.com 76.73.17.194 9030 9090"),
   ("contact", "Mike Perry <email>"),
@@ -523,6 +543,25 @@ def get_bridge_extrainfo_descriptor(attr = None, exclude = (), content = False):
   else:
     return stem.descriptor.extrainfo_descriptor.BridgeExtraInfoDescriptor(desc_content, validate = True)
 
+def get_router_status_entry_v2(attr = None, exclude = (), content = False):
+  """
+  Provides the descriptor content for...
+  stem.descriptor.router_status_entry.RouterStatusEntryV2
+  
+  :param dict attr: keyword/value mappings to be included in the descriptor
+  :param list exclude: mandatory keywords to exclude from the descriptor
+  :param bool content: provides the str content of the descriptor rather than the class if True
+  
+  :returns: RouterStatusEntryV2 for the requested descriptor content
+  """
+  
+  desc_content = _get_descriptor_content(attr, exclude, ROUTER_STATUS_ENTRY_V2_HEADER)
+  
+  if content:
+    return desc_content
+  else:
+    return stem.descriptor.router_status_entry.RouterStatusEntryV2(desc_content, validate = True)
+
 def get_router_status_entry_v3(attr = None, exclude = (), content = False):
   """
   Provides the descriptor content for...
@@ -542,6 +581,25 @@ def get_router_status_entry_v3(attr = None, exclude = (), content = False):
   else:
     return stem.descriptor.router_status_entry.RouterStatusEntryV3(desc_content, validate = True)
 
+def get_router_status_entry_micro_v3(attr = None, exclude = (), content = False):
+  """
+  Provides the descriptor content for...
+  stem.descriptor.router_status_entry.RouterStatusEntryMicroV3
+  
+  :param dict attr: keyword/value mappings to be included in the descriptor
+  :param list exclude: mandatory keywords to exclude from the descriptor
+  :param bool content: provides the str content of the descriptor rather than the class if True
+  
+  :returns: RouterStatusEntryMicroV3 for the requested descriptor content
+  """
+  
+  desc_content = _get_descriptor_content(attr, exclude, ROUTER_STATUS_ENTRY_MICRO_V3_HEADER)
+  
+  if content:
+    return desc_content
+  else:
+    return stem.descriptor.router_status_entry.RouterStatusEntryMicroV3(desc_content, validate = True)
+
 def get_directory_authority(attr = None, exclude = (), is_vote = False, content = False):
   """
   Provides the descriptor content for...
diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py
index 6816656..d971906 100644
--- a/test/unit/descriptor/router_status_entry.py
+++ b/test/unit/descriptor/router_status_entry.py
@@ -9,7 +9,7 @@ from stem.descriptor import Flag
 from stem.descriptor.router_status_entry import RouterStatusEntryV3, _decode_fingerprint
 from stem.version import Version
 from stem.exit_policy import MicrodescriptorExitPolicy
-from test.mocking import get_router_status_entry_v3, ROUTER_STATUS_ENTRY_V3_HEADER
+from test.mocking import get_router_status_entry_v2, get_router_status_entry_v3, get_router_status_entry_micro_v3, ROUTER_STATUS_ENTRY_V3_HEADER
 
 class TestRouterStatusEntry(unittest.TestCase):
   def test_fingerprint_decoding(self):
@@ -35,9 +35,29 @@ class TestRouterStatusEntry(unittest.TestCase):
       self.assertRaises(ValueError, _decode_fingerprint, arg, True)
       self.assertEqual(None, _decode_fingerprint(arg, False))
   
-  def test_minimal(self):
+  def test_minimal_v2(self):
     """
-    Parses a minimal router status entry.
+    Parses a minimal v2 router status entry.
+    """
+    
+    entry = get_router_status_entry_v2()
+    
+    self.assertEqual(None, entry.document)
+    self.assertEqual("caerSidi", entry.nickname)
+    self.assertEqual("A7569A83B5706AB1B1A9CB52EFF7D2D32E4553EB", entry.fingerprint)
+    self.assertEqual("oQZFLYe9e4A7bOkWKR7TaNxb0JE", entry.digest)
+    self.assertEqual(datetime.datetime(2012, 8, 6, 11, 19, 31), entry.published)
+    self.assertEqual("71.35.150.29", entry.address)
+    self.assertEqual(9001, entry.or_port)
+    self.assertEqual(None, entry.dir_port)
+    self.assertEqual(None, entry.flags)
+    self.assertEqual(None, entry.version_line)
+    self.assertEqual(None, entry.version)
+    self.assertEqual([], entry.get_unrecognized_lines())
+  
+  def test_minimal_v3(self):
+    """
+    Parses a minimal v3 router status entry.
     """
     
     entry = get_router_status_entry_v3()
@@ -61,6 +81,27 @@ class TestRouterStatusEntry(unittest.TestCase):
     self.assertEqual(None, entry.microdescriptor_hashes)
     self.assertEqual([], entry.get_unrecognized_lines())
   
+  def test_minimal_micro_v3(self):
+    """
+    Parses a minimal microdescriptor v3 router status entry.
+    """
+    
+    entry = get_router_status_entry_micro_v3()
+    
+    expected_flags = set([Flag.FAST, Flag.GUARD, Flag.HSDIR, Flag.NAMED, Flag.RUNNING, Flag.STABLE, Flag.V2DIR, Flag.VALID])
+    self.assertEqual(None, entry.document)
+    self.assertEqual("Konata", entry.nickname)
+    self.assertEqual("011209176CDBAA2AC1F48C2C5B4990CE771C5B0C", entry.fingerprint)
+    self.assertEqual(datetime.datetime(2012, 9, 24, 13, 40, 40), entry.published)
+    self.assertEqual("69.64.48.168", entry.address)
+    self.assertEqual(9001, entry.or_port)
+    self.assertEqual(9030, entry.dir_port)
+    self.assertEqual(expected_flags, set(entry.flags))
+    self.assertEqual(None, entry.version_line)
+    self.assertEqual(None, entry.version)
+    self.assertEqual("aiUklwBrua82obG5AsTX+iEpkjQA2+AQHxZ7GwMfY70", entry.digest)
+    self.assertEqual([], entry.get_unrecognized_lines())
+  
   def test_missing_fields(self):
     """
     Parses a router status entry that's missing fields.



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