コード例 #1
0
    def test_HTTPSDistributor_getBridges_with_proxy_and_nonproxy_users(self):
        """An HTTPSDistributor should give separate bridges to proxy users."""
        proxies = ProxySet(
            ['.'.join(['1.1.1', str(x)]) for x in range(1, 256)])
        dist = distributor.HTTPSDistributor(3, self.key, proxies)
        [dist.insert(bridge) for bridge in self.bridges]

        for _ in range(10):
            bridgeRequest1 = self.randomClientRequest()
            bridgeRequest1.client = '.'.join(
                ['1.1.1', str(random.randrange(1, 255))])

            bridgeRequest2 = self.randomClientRequest()
            bridgeRequest2.client = '.'.join(
                ['9.9.9', str(random.randrange(1, 255))])

            n1 = dist.getBridges(bridgeRequest1, 1)
            n2 = dist.getBridges(bridgeRequest2, 1)

            self.assertGreater(len(n1), 0)
            self.assertGreater(len(n2), 0)

            for b in n1:
                self.assertNotIn(b, n2)
            for b in n2:
                self.assertNotIn(b, n1)
コード例 #2
0
 def test_HTTPSDistributor_prepopulateRings_with_proxies(self):
     """An HTTPSDistributor with proxies should prepopulate two extra
     subhashrings (one for each of HTTP-Proxy-IPv4 and HTTP-Proxy-IPv6).
     """
     dist = distributor.HTTPSDistributor(3, self.key, ProxySet(['1.1.1.1', '2.2.2.2']))
     [dist.insert(bridge) for bridge in self.bridges]
     dist.prepopulateRings()
     self.assertEqual(len(dist.hashring.filterRings), 8)
コード例 #3
0
 def test_HTTPSDistributor_mapSubnetToSubring_usingProxy(self):
     """HTTPSDistributor.mapSubnetToSubring() when the client was using a
     proxy should map the client to the proxy subhashring.
     """
     dist = distributor.HTTPSDistributor(3, self.key, ProxySet(['1.1.1.1', '2.2.2.2']))
     subnet = 'proxy-group-3'
     subring = dist.mapSubnetToSubring(subnet, usingProxy=True)
     self.assertEqual(subring, dist.proxySubring)
コード例 #4
0
 def test_HTTPSDistributor_init_with_proxies(self):
     """The HTTPSDistributor, when initialised with proxies, should add an
     extra hashring for proxy users.
     """
     dist = distributor.HTTPSDistributor(3, self.key, ProxySet(['1.1.1.1', '2.2.2.2']))
     self.assertIsNotNone(dist.proxies)
     self.assertGreater(dist.proxySubring, 0)
     self.assertEqual(dist.proxySubring, 4)
     self.assertEqual(dist.totalSubrings, 4)
コード例 #5
0
 def test_HTTPSDistributor_mapSubnetToSubring_with_proxies(self):
     """HTTPSDistributor.mapSubnetToSubring() when the client wasn't using
     a proxy, but the distributor does have some known proxies and a
     proxySubring, should not map the client to the proxy subhashring.
     """
     dist = distributor.HTTPSDistributor(3, self.key, ProxySet(['1.1.1.1', '2.2.2.2']))
     # Note that if they were actually from a proxy, their subnet would be
     # something like "proxy-group-3".
     subnet = '15.1.0.0/16'
     subring = dist.mapSubnetToSubring(subnet, usingProxy=False)
     self.assertNotEqual(subring, dist.proxySubring)