Beispiel #1
0
    def test_main_createBridgeRings(self):
        """main.createBridgeRings() should add three hashrings to the
        hashring.
        """
        proxyList = None
        (hashring, emailDist, httpsDist, moatDist) = main.createBridgeRings(
            self.config, proxyList, self.key)

        # Should have an HTTPSDistributor ring, an EmailDistributor ring,
        # a MoatDistributor right, and an UnallocatedHolder ring:
        self.assertEqual(len(hashring.ringsByName.keys()), 4)
Beispiel #2
0
    def test_main_createBridgeRings(self):
        """main.createBridgeRings() should add three hashrings to the
        hashring.
        """
        proxyList = None
        (hashring, emailDist, httpsDist, moatDist) = main.createBridgeRings(
            self.config, proxyList, self.key)

        # Should have an HTTPSDistributor ring, an EmailDistributor ring,
        # a MoatDistributor right, and an UnallocatedHolder ring:
        self.assertEqual(len(hashring.ringsByName.keys()), 4)
Beispiel #3
0
    def test_main_createBridgeRings_no_reserved_share(self):
        """When RESERVED_SHARE=0, main.createBridgeRings() should add only
        two hashrings to the hashring.
        """
        proxyList = main.proxy.ProxySet()
        config = self.config
        config.RESERVED_SHARE = 0
        (hashring, emailDist, httpsDist, moatDist) = main.createBridgeRings(
            config, proxyList, self.key)

        # Should have an HTTPSDistributor ring, an EmailDistributor ring, and a
        # MoatDistributor ring:
        self.assertEqual(len(hashring.ringsByName.keys()), 3)
        self.assertNotIn('unallocated', hashring.rings)
Beispiel #4
0
    def test_main_createBridgeRings_no_reserved_share(self):
        """When RESERVED_SHARE=0, main.createBridgeRings() should add only
        two hashrings to the hashring.
        """
        proxyList = main.proxy.ProxySet()
        config = self.config
        config.RESERVED_SHARE = 0
        (hashring, emailDist, httpsDist, moatDist) = main.createBridgeRings(
            config, proxyList, self.key)

        # Should have an HTTPSDistributor ring, an EmailDistributor ring, and a
        # MoatDistributor ring:
        self.assertEqual(len(hashring.ringsByName.keys()), 3)
        self.assertNotIn('unallocated', hashring.rings)
Beispiel #5
0
    def test_main_createBridgeRings_no_email_dist(self):
        """When EMAIL_DIST=False, main.createBridgeRings() should add only
        two hashrings to the hashring.
        """
        proxyList = main.proxy.ProxySet()
        config = self.config
        config.EMAIL_DIST = False
        (hashring, emailDist, httpsDist, moatDist) = main.createBridgeRings(
            config, proxyList, self.key)

        # Should have an HTTPSDistributor ring, a MoatDistributor ring, and an
        # UnallocatedHolder ring:
        self.assertEqual(len(hashring.ringsByName.keys()), 3)
        self.assertNotIn('email', hashring.rings)
        self.assertNotIn(emailDist, hashring.ringsByName.values())
Beispiel #6
0
    def test_main_createBridgeRings_with_proxyList(self):
        """main.createBridgeRings() should add three hashrings to the
        hashring and add the proxyList to the IPBasedDistibutor.
        """
        exitRelays = ['1.1.1.1', '2.2.2.2', '3.3.3.3']
        proxyList = main.proxy.ProxySet()
        proxyList.addExitRelays(exitRelays)
        (hashring, emailDist, httpsDist, moatDist) = main.createBridgeRings(
            self.config, proxyList, self.key)

        # Should have an HTTPSDistributor ring, an EmailDistributor ring,
        # a MoatDistributor ring, and an UnallocatedHolder ring:
        self.assertEqual(len(hashring.ringsByName.keys()), 4)
        self.assertGreater(len(httpsDist.proxies), 0)
        self.assertCountEqual(exitRelays, httpsDist.proxies)
Beispiel #7
0
    def test_main_createBridgeRings_no_email_dist(self):
        """When EMAIL_DIST=False, main.createBridgeRings() should add only
        two hashrings to the hashring.
        """
        proxyList = main.proxy.ProxySet()
        config = self.config
        config.EMAIL_DIST = False
        (hashring, emailDist, httpsDist, moatDist) = main.createBridgeRings(
            config, proxyList, self.key)

        # Should have an HTTPSDistributor ring, a MoatDistributor ring, and an
        # UnallocatedHolder ring:
        self.assertEqual(len(hashring.ringsByName.keys()), 3)
        self.assertNotIn('email', hashring.rings)
        self.assertNotIn(emailDist, hashring.ringsByName.values())
Beispiel #8
0
    def test_main_createBridgeRings_with_proxyList(self):
        """main.createBridgeRings() should add three hashrings to the
        hashring and add the proxyList to the IPBasedDistibutor.
        """
        exitRelays = ['1.1.1.1', '2.2.2.2', '3.3.3.3']
        proxyList = main.proxy.ProxySet()
        proxyList.addExitRelays(exitRelays)
        (hashring, emailDist, httpsDist, moatDist) = main.createBridgeRings(
            self.config, proxyList, self.key)

        # Should have an HTTPSDistributor ring, an EmailDistributor ring,
        # a MoatDistributor ring, and an UnallocatedHolder ring:
        self.assertEqual(len(hashring.ringsByName.keys()), 4)
        self.assertGreater(len(httpsDist.proxies), 0)
        self.assertItemsEqual(exitRelays, httpsDist.proxies)
Beispiel #9
0
    def test_main_loadBlockedBridges(self):
        Storage.initializeDBLock()

        # Mock configuration object that we use to initialize our bridge rings.
        class Cfg(object):
            def __init__(self):
                self.FORCE_PORTS = [(443, 1)]
                self.FORCE_FLAGS = [("Stable", 1)]
                self.MOAT_DIST = False
                self.HTTPS_DIST = True
                self.HTTPS_SHARE = 10
                self.N_IP_CLUSTERS = 1
                self.EMAIL_DIST = False
                self.RESERVED_SHARE = 0

        bridge = self.fakeBridges[0]
        addr, port, _ = bridge.orAddresses[0]
        cc = "de"

        # Mock object that we use to simulate a database connection.
        class DummyDB(object):
            def __init__(self):
                pass

            def __enter__(self):
                return self

            def __exit__(self, type, value, traceback):
                pass

            def getBlockedBridges(self):
                return {bridge.fingerprint: [(cc, addr, port)]}

            def getBridgeDistributor(self, bridge, validRings):
                return "https"

            def insertBridgeAndGetRing(self,
                                       bridge,
                                       setRing,
                                       seenAt,
                                       validRings,
                                       defaultPool="unallocated"):
                return "https"

            def commit(self):
                pass

        oldObj = Storage.getDB
        Storage.getDB = DummyDB

        hashring, _, _, _ = main.createBridgeRings(Cfg(), None, b'key')
        hashring.insert(bridge)

        self.assertEqual(len(hashring), 1)
        self.assertFalse(bridge.isBlockedIn(cc))
        self.assertFalse(bridge.isBlockedIn("ab"))
        self.assertFalse(bridge.addressIsBlockedIn(cc, addr, port))

        main.loadBlockedBridges(hashring)

        self.assertTrue(bridge.isBlockedIn(cc))
        self.assertFalse(bridge.isBlockedIn("ab"))
        self.assertTrue(bridge.addressIsBlockedIn(cc, addr, port))

        Storage.getDB = oldObj