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

[tor-commits] [bridgedb/master] Add unittests for HSDir flags in bridge networkstatus documents.



commit 5f3910b02dfa19a70cb8ba0cee7bbc3a2c82b8ed
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Mon Jul 20 19:58:18 2015 +0000

    Add unittests for HSDir flags in bridge networkstatus documents.
    
     * FIXES #16616: https://bugs.torproject.org/16616
---
 test/test_bridges.py           |   19 +++++++++++++++++++
 test/test_parse_descriptors.py |   24 ++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/test/test_bridges.py b/test/test_bridges.py
index 9448e3f..3c5fe0d 100644
--- a/test/test_bridges.py
+++ b/test/test_bridges.py
@@ -403,6 +403,25 @@ class FlagsTests(unittest.TestCase):
         self.assertFalse(self.flags.fast)
         self.assertTrue(self.flags.stable)
 
+    def test_update_HSDir(self):
+        """Test adding the HSDir flag with the update() method.
+
+        See also: :trac:`16616`.
+        """
+        self.flags.update(["Fast", "Stable", "HSDir"])
+        self.assertTrue(self.flags.fast)
+        self.assertTrue(self.flags.stable)
+        # We don't care about the HSDir flag:
+        self.assertIsNone(getattr(self.flags, "hsdir", None))
+
+    def test_update_Unicorn(self):
+        """Test adding a completely made-up flag, "Unicorn", with the update()
+        method.  (It shouldn't get added.)
+        """
+        self.flags.update(["Unicorn"])
+        # We don't care about the make-believe Unicorn flag:
+        self.assertIsNone(getattr(self.flags, "unicorn", None))
+
 
 class BridgeAddressBaseTests(unittest.TestCase):
     """Tests for :class:`bridgedb.bridges.BridgeAddressBase`."""
diff --git a/test/test_parse_descriptors.py b/test/test_parse_descriptors.py
index 5104ccd..bd3c3d5 100644
--- a/test/test_parse_descriptors.py
+++ b/test/test_parse_descriptors.py
@@ -391,6 +391,30 @@ class ParseDescriptorsTests(unittest.TestCase):
                           descriptors.parseNetworkStatusFile,
                           descFile)
 
+    def test_parse_descriptors_parseNetworkStatusFile_HSDir_flag(self):
+        """A Bridge networkstatus descriptor with the HSDir flag should be
+        possible to parse (without errors), however, the flag should be ignored
+        (since the :class:`bridgedb.bridges.Flags` class doesn't care about it).
+
+        See also: :trac:`16616`
+        """
+        unparseable = BRIDGE_NETWORKSTATUS_0.replace(
+            's Fast Guard Running Stable Valid',
+            's Fast Guard Running Stable Valid HSDir')
+        # Write the descriptor to a file for testing. This is necessary
+        # because the function opens the networkstatus file to read it.
+        descFile = self.writeTestDescriptorsToFile('networkstatus-bridges',
+                                                   unparseable)
+        routers = descriptors.parseNetworkStatusFile(descFile)
+        bridge = routers[0]
+
+        for flag in [u'Fast', u'Guard', u'Running',
+                     u'Stable', u'Valid', u'HSDir']:
+            self.assertTrue(flag in bridge.flags,
+                            ("Expected to parse the %r flag from a bridge "
+                             "networkstatus document, but the flag was not "
+                             "found!"))
+
     def test_parse_descriptors_parseNetworkStatusFile_IPv6_ORAddress(self):
         """A Bridge can't have its primary ORAddress be IPv6 without raising
         a ValueError.



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