[tor-commits] [bridgedb/develop] Rewrite testDistWithFilterBlockedCountriesAdvanced() in legacy_Tests.
isis at torproject.org
isis at torproject.org
Thu Jun 25 07:10:55 UTC 2015
commit 2de77ba16992b8a967bfe68cebc2c17c2b3998fc
Author: Isis Lovecruft <isis at torproject.org>
Date: Tue Apr 21 02:33:08 2015 +0000
Rewrite testDistWithFilterBlockedCountriesAdvanced() in legacy_Tests.
---
lib/bridgedb/test/legacy_Tests.py | 41 +------------------------------------
lib/bridgedb/test/test_Dist.py | 39 +++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/lib/bridgedb/test/legacy_Tests.py b/lib/bridgedb/test/legacy_Tests.py
index 2f1da67..95dc34e 100644
--- a/lib/bridgedb/test/legacy_Tests.py
+++ b/lib/bridgedb/test/legacy_Tests.py
@@ -183,44 +183,6 @@ class EmailBridgeDistTests(unittest.TestCase):
{'example.com':'example.com'},
{'example.com':[]})
-class IPBridgeDistTests(unittest.TestCase):
-
- def testDistWithFilterBlockedCountriesAdvanced(self):
- d = bridgedb.Dist.HTTPSDistributor(3, "Foo")
- for _ in xrange(250):
- d.insert(fakeBridge6(or_addresses=True, transports=True))
- d.insert(fakeBridge(or_addresses=True, transports=True))
-
- for b in d.hashring.bridges:
- # china blocks some transports
- for pt in b.transports:
- if random.choice(xrange(2)) > 0:
- key = "%s:%s" % (pt.address, pt.port)
- b.blockingCountries[key] = set(['cn'])
- for address, portlist in b.or_addresses.items():
- # china blocks some transports
- for port in portlist:
- if random.choice(xrange(2)) > 0:
- key = "%s:%s" % (address, port)
- b.blockingCountries[key] = set(['cn'])
- key = "%s:%s" % (b.ip, b.orport)
- b.blockingCountries[key] = set(['cn'])
-
- # we probably will get at least one bridge back!
- # it's pretty unlikely to lose a coin flip 250 times in a row
- for i in xrange(5):
- b = d.getBridges(randomIPString(), "x",
- bridgeFilterRules=[
- filterBridgesByNotBlockedIn("cn"),
- filterBridgesByTransport('obfs2'),
- ])
- try: assert len(b) > 0
- except AssertionError:
- print("epic fail")
- b = d.getBridges(randomIPString(), "x", bridgeFilterRules=[
- filterBridgesByNotBlockedIn("us")])
- assert len(b) > 0
-
class SQLStorageTests(unittest.TestCase):
def setUp(self):
@@ -450,8 +412,7 @@ def testSuite():
suite = unittest.TestSuite()
loader = unittest.TestLoader()
- for klass in [IPBridgeDistTests, SQLStorageTests, EmailBridgeDistTests,
- BridgeStabilityTests]:
+ for klass in [SQLStorageTests, EmailBridgeDistTests, BridgeStabilityTests]:
suite.addTest(loader.loadTestsFromTestCase(klass))
return suite
diff --git a/lib/bridgedb/test/test_Dist.py b/lib/bridgedb/test/test_Dist.py
index e8a17e4..85c1b87 100644
--- a/lib/bridgedb/test/test_Dist.py
+++ b/lib/bridgedb/test/test_Dist.py
@@ -244,6 +244,45 @@ class HTTPSDistributorTests(unittest.TestCase):
self.assertNotIn(b.fingerprint, blockedIR)
self.assertGreater(len(bridges), 0)
+ def test_HTTPSDistributor_getBridges_with_varied_blocked_bridges(self):
+ dist = Dist.HTTPSDistributor(1, self.key)
+ bridges = self.bridges[:]
+
+ for bridge in bridges:
+ # Pretend that China blocks all vanilla bridges:
+ bridge.setBlockedIn('cn', methodname='vanilla')
+ # Pretend that China blocks all obfs2:
+ bridge.setBlockedIn('cn', methodname='obfs2')
+ # Pretend that China blocks some obfs3:
+ if self.coinFlip():
+ bridge.setBlockedIn('cn', methodname='obfs3')
+
+ [dist.insert(bridge) for bridge in bridges]
+
+ for i in xrange(5):
+ bridgeRequest1 = self.randomClientRequestForNotBlockedIn('cn')
+ bridgeRequest1.transports.append('obfs2')
+ bridgeRequest1.generateFilters()
+ # We shouldn't get any obfs2 bridges, since they're all blocked in
+ # China:
+ bridges = dist.getBridges(bridgeRequest1, "faketimestamp")
+ self.assertEqual(len(bridges), 0)
+
+ bridgeRequest2 = self.randomClientRequestForNotBlockedIn('cn')
+ bridgeRequest2.transports.append('obfs3')
+ bridgeRequest2.generateFilters()
+ # We probably will get at least one bridge back! It's pretty
+ # unlikely to lose a coin flip 500 times in a row.
+ bridges = dist.getBridges(bridgeRequest2, "faketimestamp")
+ self.assertGreater(len(bridges), 0)
+
+ bridgeRequest3 = self.randomClientRequestForNotBlockedIn('nl')
+ bridgeRequest3.transports.append('obfs3')
+ bridgeRequest3.generateFilters()
+ # We should get bridges, since obfs3 isn't blocked in netherlands:
+ bridges = dist.getBridges(bridgeRequest3, "faketimestamp")
+ self.assertGreater(len(bridges), 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)])
More information about the tor-commits
mailing list