commit d9dcb7f3d143cfb46f2f1e988da96cf5a5b1b449 Author: Isis Lovecruft isis@torproject.org Date: Tue Apr 21 23:34:50 2015 +0000
Rewrite testDistWithFilterIP4() in legacy_Tests. --- lib/bridgedb/test/legacy_Tests.py | 16 ---------------- lib/bridgedb/test/test_Dist.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/lib/bridgedb/test/legacy_Tests.py b/lib/bridgedb/test/legacy_Tests.py index 043f09b..9a0c74f 100644 --- a/lib/bridgedb/test/legacy_Tests.py +++ b/lib/bridgedb/test/legacy_Tests.py @@ -252,22 +252,6 @@ class IPBridgeDistTests(unittest.TestCase): assert type(ipaddr.IPAddress(address)) is ipaddr.IPv6Address assert filterBridgesByIP6(random.choice(bridges))
- def testDistWithFilterIP4(self): - d = bridgedb.Dist.HTTPSDistributor(3, "Foo") - for _ in xrange(250): - d.insert(fakeBridge6(or_addresses=True)) - d.insert(fakeBridge(or_addresses=True)) - - for i in xrange(500): - bridges = d.getBridges(randomIPv4String(), - "faketimestamp", - bridgeFilterRules=[filterBridgesByIP4]) - bridge = random.choice(bridges) - bridge_line = bridge.getConfigLine(addressClass=ipaddr.IPv4Address) - address, portlist = networkstatus.parseALine(bridge_line) - assert type(ipaddr.IPAddress(address)) is ipaddr.IPv4Address - assert filterBridgesByIP4(random.choice(bridges)) - def testDistWithFilterBlockedCountriesAdvanced(self): d = bridgedb.Dist.HTTPSDistributor(3, "Foo") for _ in xrange(250): diff --git a/lib/bridgedb/test/test_Dist.py b/lib/bridgedb/test/test_Dist.py index 9e47a92..82ef823 100644 --- a/lib/bridgedb/test/test_Dist.py +++ b/lib/bridgedb/test/test_Dist.py @@ -288,3 +288,23 @@ class HTTPSDistributorTests(unittest.TestCase): address = address.strip('[]') self.assertIsInstance(ipaddr.IPAddress(address), ipaddr.IPv6Address) self.assertIsNotNone(filterBridgesByIP6(random.choice(bridges))) + + def test_HTTPSDistributor_getBridges_ipv4(self): + """A request for IPv4 bridges should return IPv4 bridges.""" + dist = Dist.HTTPSDistributor(1, self.key) + [dist.insert(bridge) for bridge in self.bridges[:250]] + + for i in xrange(500): + bridgeRequest = self.randomClientRequest() + bridgeRequest.generateFilters() + + bridges = dist.getBridges(bridgeRequest, "faketimestamp") + self.assertTrue(type(bridges) is list) + self.assertGreater(len(bridges), 0) + + bridge = random.choice(bridges) + bridgeLine = bridge.getBridgeLine(bridgeRequest) + addrport, fingerprint = bridgeLine.split() + address, port = addrport.rsplit(':', 1) + self.assertIsInstance(ipaddr.IPAddress(address), ipaddr.IPv4Address) + self.assertIsNotNone(filterBridgesByIP4(random.choice(bridges)))
tor-commits@lists.torproject.org