[tor-commits] [bridgedb/master] Don't discard vanilla bridges as invalid.

phw at torproject.org phw at torproject.org
Tue Oct 29 16:23:53 UTC 2019


commit 18c96a661f73ab72955dbc2632f6b34caf302ffc
Author: Philipp Winter <phw at nymity.ch>
Date:   Tue Oct 22 13:53:33 2019 -0700

    Don't discard vanilla bridges as invalid.
    
    So far, the metrics module discarded all requests for vanilla bridges as
    invalid because the function isTransportSupported() only returned True
    for PTs.  This match renames the function to isBridgeTypeSupported() and
    makes it return True for vanilla bridges.
    
    This patch fixes <https://bugs.torproject.org/32203>.
---
 bridgedb/metrics.py           | 17 ++++++++++-------
 bridgedb/test/test_metrics.py | 11 +++++++++++
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/bridgedb/metrics.py b/bridgedb/metrics.py
index 5e14146..6b2e5cb 100644
--- a/bridgedb/metrics.py
+++ b/bridgedb/metrics.py
@@ -83,17 +83,20 @@ def setSupportedTransports(supportedTransports):
     SUPPORTED_TRANSPORTS = supportedTransports
 
 
-def isTransportSupported(transport):
-    """Return `True' if the given transport is supported or `False' otherwise.
+def isBridgeTypeSupported(bridgeType):
+    """Return `True' or `False' depending on if the given bridge type is
+    supported.
 
-    :param str transport: The transport protocol.
+    :param str bridgeType: The bridge type, e.g., "vanilla" or "obfs4".
     """
 
     if SUPPORTED_TRANSPORTS is None:
         logging.error("Bug: Variable SUPPORTED_TRANSPORTS is None.")
         return False
 
-    return transport in SUPPORTED_TRANSPORTS
+    # Note that "vanilla" isn't a transport protocol (in fact, it's the absence
+    # of a transport), which is why it isn't in SUPPORTED_TRANSPORTS.
+    return (bridgeType in SUPPORTED_TRANSPORTS) or (bridgeType == "vanilla")
 
 
 def export(fh, measurementInterval):
@@ -334,7 +337,7 @@ class HTTPSMetrics(Metrics):
         # BridgeDB's HTTPS interface exposes transport types as a drop down
         # menu but users can still request anything by manipulating HTTP
         # parameters.
-        if not isTransportSupported(bridgeType):
+        if not isBridgeTypeSupported(bridgeType):
             logging.warning("User requested unsupported transport type %s "
                             "over HTTPS." % bridgeType)
             return
@@ -393,7 +396,7 @@ class EmailMetrics(Metrics):
 
         # Over email, transports are requested by typing them.  Typos happen
         # and users can request anything, really.
-        if not isTransportSupported(bridgeType):
+        if not isBridgeTypeSupported(bridgeType):
             logging.warning("User requested unsupported transport type %s "
                             "over email." % bridgeType)
             return
@@ -439,7 +442,7 @@ class MoatMetrics(Metrics):
             logging.warning("Could not decode request: %s" % err)
             return
 
-        if not isTransportSupported(bridgeType):
+        if not isBridgeTypeSupported(bridgeType):
             logging.warning("User requested unsupported transport type %s "
                             "over moat." % bridgeType)
             return
diff --git a/bridgedb/test/test_metrics.py b/bridgedb/test/test_metrics.py
index a27431c..ce0f63d 100644
--- a/bridgedb/test/test_metrics.py
+++ b/bridgedb/test/test_metrics.py
@@ -202,3 +202,14 @@ class StateTest(unittest.TestCase):
         key2 = "moat.obfs4.us.fail.none"
         self.assertTrue(metrix.hotMetrics[key1] == 1)
         self.assertTrue(metrix.hotMetrics[key2] == 1)
+
+    def test_is_bridge_type_supported(self):
+
+        oldTransports = metrics.SUPPORTED_TRANSPORTS
+        metrics.setSupportedTransports({})
+        self.assertFalse(metrics.isBridgeTypeSupported("obfs4"))
+        metrics.setSupportedTransports(oldTransports)
+
+        self.assertTrue(metrics.isBridgeTypeSupported("obfs4"))
+        self.assertTrue(metrics.isBridgeTypeSupported("vanilla"))
+        self.assertFalse(metrics.isBridgeTypeSupported("xxx"))





More information about the tor-commits mailing list