Ejemplo n.º 1
0
 def test_byNotBlockedIn_vanilla_blocked(self):
     """Calling byNotBlockedIn('vanilla') should not return the IPv4 vanilla
     address, if it is blocked.
     """
     self.bridge.setBlockedIn('ru')
     filtre = filters.byNotBlockedIn('ru', methodname='vanilla')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 2
0
 def test_byNotBlockedIn_vanilla_blocked(self):
     """Calling byNotBlockedIn('vanilla') should not return the IPv4 vanilla
     address, if it is blocked.
     """
     self.bridge.setBlockedIn('ru')
     filtre = filters.byNotBlockedIn('ru', methodname='vanilla')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 3
0
 def test_byNotBlockedIn_no_transports_blocked(self):
     """A bridge without any transports which is also blocked should cause
     byNotBlockedIn('voltron') to return False.
     """
     self.bridge.setBlockedIn('cn')
     filtre = filters.byNotBlockedIn('cn', methodname='voltron')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 4
0
 def test_byNotBlockedIn_with_transport_ipv6(self):
     """A bridge with an IPv6 voltron transport should cause
     byNotBlockedIn('voltron') to return True.
     """
     self.addIPv6VoltronPT()
     filtre = filters.byNotBlockedIn('cn', 'voltron', ipVersion=6)
     self.assertTrue(filtre(self.bridge))
Ejemplo n.º 5
0
 def test_byNotBlockedIn_with_transport_ipv4(self):
     """A bridge with an IPv4 voltron transport should cause
     byNotBlockedIn('voltron') to return True.
     """
     self.addIPv4VoltronPT()
     filtre = filters.byNotBlockedIn('CN', methodname='voltron')
     self.assertTrue(filtre(self.bridge))
Ejemplo n.º 6
0
 def test_byNotBlockedIn_wrong_transport(self):
     """A bridge with only a Voltron transport should cause
     byNotBlockedIn('obfs3') to return False.
     """
     self.addIPv4VoltronPT()
     filtre = filters.byNotBlockedIn('cn', methodname='obfs3')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 7
0
 def test_byNotBlockedIn_with_transport_ipv4(self):
     """A bridge with an IPv4 voltron transport should cause
     byNotBlockedIn('voltron') to return True.
     """
     self.addIPv4VoltronPT()
     filtre = filters.byNotBlockedIn('CN', methodname='voltron')
     self.assertTrue(filtre(self.bridge))
Ejemplo n.º 8
0
 def test_byNotBlockedIn_no_countryCode_no_transports(self):
     """A bridge without any transports should cause
     byNotBlockedIn('voltron') to return False (because it calls
     filters.byTransport('voltron')).
     """
     filtre = filters.byNotBlockedIn(None, methodname='voltron')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 9
0
    def generateFilters(self):
        """Build the list of callables, ``filters``, according to the current
        contents of the lists of ``transports``, ``notBlockedIn``, and the
        ``ipVersion``.
        """
        self.clearFilters()

        pt = self.justOnePTType()
        msg = ("Adding a filter to %s for %s for IPv%d" %
               (self.__class__.__name__, self.client, self.ipVersion))

        # If this bridge runs any active probing-resistant PTs, we should
        # *only* hand out its active probing-resistant PTs.  Otherwise, a
        # non-resistant PT would get this bridge scanned and blocked:
        # <https://bugs.torproject.org/28655>
        self.addFilter(byProbingResistance(pt, self.ipVersion))

        if self.notBlockedIn:
            for country in self.notBlockedIn:
                logging.info("%s %s bridges not blocked in %s..." %
                             (msg, pt or "vanilla", country))
                self.addFilter(
                    byNotBlockedIn(country, pt or "vanilla", self.ipVersion))
        elif pt:
            logging.info("%s %s bridges..." % (msg, pt))
            self.addFilter(byTransport(pt, self.ipVersion))
        else:
            logging.info("%s bridges..." % msg)
            self.addFilter(byIPv(self.ipVersion))
Ejemplo n.º 10
0
 def test_byNotBlockedIn_no_transports_blocked(self):
     """A bridge without any transports which is also blocked should cause
     byNotBlockedIn('voltron') to return False.
     """
     self.bridge.setBlockedIn('cn')
     filtre = filters.byNotBlockedIn('cn', methodname='voltron')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 11
0
 def test_byNotBlockedIn_wrong_transport(self):
     """A bridge with only a Voltron transport should cause
     byNotBlockedIn('obfs3') to return False.
     """
     self.addIPv4VoltronPT()
     filtre = filters.byNotBlockedIn('cn', methodname='obfs3')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 12
0
 def test_byNotBlockedIn_no_countryCode_no_transports(self):
     """A bridge without any transports should cause
     byNotBlockedIn('voltron') to return False (because it calls
     filters.byTransport('voltron')).
     """
     filtre = filters.byNotBlockedIn(None, methodname='voltron')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 13
0
 def test_byNotBlockedIn_with_transport_ipv6(self):
     """A bridge with an IPv6 voltron transport should cause
     byNotBlockedIn('voltron') to return True.
     """
     self.addIPv6VoltronPT()
     filtre = filters.byNotBlockedIn('cn', 'voltron', ipVersion=6)
     self.assertTrue(filtre(self.bridge))
Ejemplo n.º 14
0
 def test_byNotBlockedIn_with_transport_ipv4_blocked(self):
     """A bridge with an IPv4 voltron transport which is blocked should
     cause byNotBlockedIn('voltron') to return False.
     """
     self.addIPv4VoltronPT()
     self.bridge.setBlockedIn('CN')
     filtre = filters.byNotBlockedIn('CN', methodname='voltron')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 15
0
 def test_byNotBlockedIn_vanilla_not_blocked_ipv6(self):
     """Calling byNotBlockedIn('vanilla', ipVersion=6) should not return the
     IPv4 vanilla address, even if it is not blocked, because it has the
     wrong IP version.
     """
     self.bridge.setBlockedIn('ru')
     filtre = filters.byNotBlockedIn('cn', methodname='vanilla', ipVersion=6)
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 16
0
 def test_byNotBlockedIn_with_transport_ipv4_not_blocked_ipv4(self):
     """A bridge with an IPv6 voltron transport which is not blocked in China
     should cause byNotBlockedIn('cn', 'voltron') to return False, because
     the IP version is wrong.
     """
     self.addIPv6VoltronPT()
     filtre = filters.byNotBlockedIn('cn', 'voltron')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 17
0
 def test_byNotBlockedIn_with_transport_ipv6_blocked(self):
     """A bridge with an IPv6 voltron transport which is blocked should
     cause byNotBlockedIn('voltron') to return False.
     """
     self.addIPv6VoltronPT()
     self.bridge.setBlockedIn('CN')
     filtre = filters.byNotBlockedIn('cn', 'voltron', ipVersion=6)
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 18
0
 def test_byNotBlockedIn_with_transport_ipv4_not_blocked_ipv4(self):
     """A bridge with an IPv6 voltron transport which is not blocked in China
     should cause byNotBlockedIn('cn', 'voltron') to return False, because
     the IP version is wrong.
     """
     self.addIPv6VoltronPT()
     filtre = filters.byNotBlockedIn('cn', 'voltron')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 19
0
 def test_byNotBlockedIn_with_transport_ipv4_blocked(self):
     """A bridge with an IPv4 voltron transport which is blocked should
     cause byNotBlockedIn('voltron') to return False.
     """
     self.addIPv4VoltronPT()
     self.bridge.setBlockedIn('CN')
     filtre = filters.byNotBlockedIn('CN', methodname='voltron')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 20
0
 def test_byNotBlockedIn_with_transport_ipv6_blocked(self):
     """A bridge with an IPv6 voltron transport which is blocked should
     cause byNotBlockedIn('voltron') to return False.
     """
     self.addIPv6VoltronPT()
     self.bridge.setBlockedIn('CN')
     filtre = filters.byNotBlockedIn('cn', 'voltron', ipVersion=6)
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 21
0
 def test_byNotBlockedIn_no_countryCode_with_transport_ipv4(self):
     """A bridge with an IPv4 voltron transport should cause
     byNotBlockedIn('voltron') to return True (because it calls
     filters.byTransport).
     """
     self.addIPv4VoltronPT()
     filtre = filters.byNotBlockedIn(None, methodname='voltron')
     self.assertTrue(filtre(self.bridge))
Ejemplo n.º 22
0
 def test_byNotBlockedIn_no_countryCode_with_transport_ipv6(self):
     """A bridge with an IPv6 voltron transport should cause
     byNotBlockedIn('voltron') to return True (because it calls
     filters.byTransport).
     """
     self.addIPv6VoltronPT()
     filtre = filters.byNotBlockedIn(None, methodname='voltron', ipVersion=6)
     self.assertTrue(filtre(self.bridge))
Ejemplo n.º 23
0
 def test_byNotBlockedIn_vanilla_not_blocked_ipv6(self):
     """Calling byNotBlockedIn('vanilla', ipVersion=6) should not return the
     IPv4 vanilla address, even if it is not blocked, because it has the
     wrong IP version.
     """
     self.bridge.setBlockedIn('ru')
     filtre = filters.byNotBlockedIn('cn',
                                     methodname='vanilla',
                                     ipVersion=6)
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 24
0
    def generateFilters(self):
        """Build the list of callables, ``filters``, according to the current
        contents of the lists of ``transports``, ``notBlockedIn``, and the
        ``ipVersion``.
        """
        self.clearFilters()

        pt = self.justOnePTType()
        msg = ("Adding a filter to %s for %s for IPv%d"
               % (self.__class__.__name__, self.client, self.ipVersion))

        if self.notBlockedIn:
            for country in self.notBlockedIn:
                logging.info("%s %s bridges not blocked in %s..." %
                             (msg, pt or "vanilla", country))
                self.addFilter(byNotBlockedIn(country, pt, self.ipVersion))
        elif pt:
            logging.info("%s %s bridges..." % (msg, pt))
            self.addFilter(byTransport(pt, self.ipVersion))
        else:
            logging.info("%s bridges..." % msg)
            self.addFilter(byIPv(self.ipVersion))
Ejemplo n.º 25
0
 def test_byNotBlockedIn_ipv5(self):
     """Calling byNotBlockedIn([…], ipVersion=5) should default to IPv4."""
     self.bridge.setBlockedIn('ru')
     filtre = filters.byNotBlockedIn('cn', ipVersion=5)
     self.assertTrue(filtre(self.bridge))
Ejemplo n.º 26
0
 def test_byNotBlockedIn_no_transports(self):
     """A bridge without any transports should cause
     byNotBlockedIn('cn', 'voltron') to return False.
     """
     filtre = filters.byNotBlockedIn('cn', methodname='voltron')
     self.assertFalse(filtre(self.bridge))
Ejemplo n.º 27
0
 def test_byNotBlockedIn_ipv5(self):
     """Calling byNotBlockedIn([…], ipVersion=5) should default to IPv4."""
     self.bridge.setBlockedIn('ru')
     filtre = filters.byNotBlockedIn('cn', ipVersion=5)
     self.assertTrue(filtre(self.bridge))
Ejemplo n.º 28
0
 def test_byNotBlockedIn_no_transports(self):
     """A bridge without any transports should cause
     byNotBlockedIn('cn', 'voltron') to return False.
     """
     filtre = filters.byNotBlockedIn('cn', methodname='voltron')
     self.assertFalse(filtre(self.bridge))