commit 74f8a5548fb408c64169321789f7bdb718b3996b Author: Isis Lovecruft isis@torproject.org Date: Wed Nov 5 00:55:55 2014 +0000
Replace descriptors in test_parse_descriptors with newer leekspin ones.
The descriptors in this unittest file were created by an older version of Leekspin, which had a bugs in the way it created signatures and coverted between fingerprint formats.
In addition, we're now able to test parsing of obfs4 `transport` lines. --- lib/bridgedb/parse/descriptors.py | 2 +- lib/bridgedb/test/test_parse_descriptors.py | 150 +++++++++++++++------------ 2 files changed, 82 insertions(+), 70 deletions(-)
diff --git a/lib/bridgedb/parse/descriptors.py b/lib/bridgedb/parse/descriptors.py index 6c6fd3e..a7cb202 100644 --- a/lib/bridgedb/parse/descriptors.py +++ b/lib/bridgedb/parse/descriptors.py @@ -66,7 +66,7 @@ def parseNetworkStatusFile(filename, validate=True, skipAnnotations=True,
return routers
-def parseServerDescriptorsFile(filename, validate=False): +def parseServerDescriptorsFile(filename, validate=True): """Parse a file which contains ``@type bridge-server-descriptor``s.
.. note:: ``validate`` defaults to ``False`` because there appears to be a diff --git a/lib/bridgedb/test/test_parse_descriptors.py b/lib/bridgedb/test/test_parse_descriptors.py index 1abd08f..953f371 100644 --- a/lib/bridgedb/test/test_parse_descriptors.py +++ b/lib/bridgedb/test/test_parse_descriptors.py @@ -31,111 +31,114 @@ else:
BRIDGE_NETWORKSTATUS_0 = '''\ -r OutwitsPlod b6khbPOgbomgMSGswx9w+N/X3cw qBckYSWbwl/F/qzQWwMJWBxHZ+w 2014-03-12 16:07:08 152.78.9.20 17810 0 -a [bfbd:7a90:2347:cc4:e854:64b3:2c31:124f]:17810 +r MiserLandfalls 4IsyTSCtChPhFPAnq5rD8yymlqA /GMC4lz8RXT/62v6kZNdmzSmopk 2014-11-04 06:23:22 2.215.61.223 4056 0 +a [c5fd:4467:98a7:90be:c76a:b449:8e6f:f0a7]:4055 s Fast Guard Running Stable Valid -w Bandwidth=1902273 +w Bandwidth=1678904 p reject 1-65535 '''
BRIDGE_NETWORKSTATUS_1 = '''\ -r Reestablishes jPqMRoqkH62eLMXl76DqIddlpto 2BETKn1sOghC6coUkCSq/9mvPNM 2014-08-20 19:52:41 25.178.4.186 32324 0 -a [d7b3:8c3e:186a:d65f:706:cbfd:8512:fd1]:32324 +r Unmentionable BgOrX0ViP5hNsK5ZvixAuPZ6EY0 NTg9NoE5ls9KjF96Dp/UdrabZ9Y 2014-11-04 12:23:37 80.44.173.87 51691 0 +a [da14:7d1e:ba8e:60d0:b078:3f88:382b:5c70]:51690 s Fast Guard Running Stable Valid -w Bandwidth=497963 +w Bandwidth=24361 p reject 1-65535 '''
BRIDGE_SERVER_DESCRIPTOR = '''\ -router OutwitsPlod 152.78.9.20 17810 0 0 -or-address [bfbd:7a90:2347:cc4:e854:64b3:2c31:124f]:17810 -platform Tor 0.2.4.16-rc on Linux -protocols Link 1 2 Circuit 1 -published 2014-03-12 16:07:08 -fingerprint 6FA9 216C F3A0 6E89 A031 21AC C31F 70F8 DFD7 DDCC -uptime 57032961 -bandwidth 2240117028 2532306205 1947927850 -extra-info-digest 069EBB610CD8B02BF1BB0CAB17B99DDA73CCC91A +@purpose bridge +router MiserLandfalls 2.215.61.223 4056 0 0 +or-address [c5fd:4467:98a7:90be:c76a:b449:8e6f:f0a7]:4055 +platform Tor 0.2.2.39 on Linux +opt protocols Link 1 2 Circuit 1 +published 2014-11-04 06:23:22 +opt fingerprint E08B 324D 20AD 0A13 E114 F027 AB9A C3F3 2CA6 96A0 +uptime 24247659 +bandwidth 1977077890 2234957615 1719198165 +opt extra-info-digest 1CBBB3D6158F324476E6804B7EE25623899271CB onion-key -----BEGIN RSA PUBLIC KEY----- -MIGkAgEAMA0GCSqGSIb3DQEBAQUABIGPMIGMAgEAAoGBANI67YIwW8xF2v310PZt -Qc8jm0ptwLHmgBdhAzHAIGagqknjvukX5GTL0zie5covhxrQhZqjJm/gQ8inwkol -kZCue1ZQ9PHaTWjz58ESMQo41h+9Whfd8Egm2ev1+MwqlPy1Kr3rcPNIEetsmtil -DFNocpEfq1MC0tDG6qVO6/FNAgMBAAE= +MIGJAoGBAOm4NX2wi8JmgcAyvOyiAEfq9UkzaNHK+VnSZBiPIrb5GAKFibR7S+Bb +7+x7tsT8VBNbe9QmwML2GVah3xXg68gJAksMNIgFdpud+zMhduuGd0jr7V55aLmH +ePGJYCh78B9RqfvmeTridp3pljwcAheKKH/YKi3nv1fPY0BwahurAgMBAAE= -----END RSA PUBLIC KEY----- signing-key -----BEGIN RSA PUBLIC KEY----- -MIGkAgEAMA0GCSqGSIb3DQEBAQUABIGPMIGMAgEAAoGBALk0Ws5qPlgwKO6IQ1b/ -aamtEdXEPj2DrZTF3aGYR5zoZgw9gwmkbRHjrMQ/Wj+QHg0cTFY2DsYt81QXwiv+ -m1P9sshMZSZZz2P8Ld8WqUNuN7YIIJx/fj9Vy6LRFySzoyQ4FF/1Dio+JD0rvtyc -ZyRJl2aV5iYA9/TQY2zs2cxFAgMBAAE= +MIGJAoGBANd/JkrTZRT24EkK3DDc/E+Nj1QBnKIm/xXMyW0gkotFOVdewIWjwQ5z +Tn3YbDhrFN0aFYVdVwNbRhW83e+jZDkpIQuxlQOx6bT13vrzmg8ff1tH8I9EePl7 +MO4v0DLPIEcu7Zfz90oC1bl36oqNsD4h0v4yK/XjVwLutIGiy3gTAgMBAAE= -----END RSA PUBLIC KEY----- -hidden-service-dir contact Somebody somebody@example.com +ntor-onion-key NBsk2O6ks5qnxLhhhKPd59zi0IzfjnakoOJP+Cm8OAE reject *:* router-signature -----BEGIN SIGNATURE----- -i/nkrD4VxqWcnAlBS48hIilrE7C4DvRJhN4XWep7TXNbEC48IqFG+49xpKV6qkts -yKaUDBfD9Y1tMM0mrRjEWK0xYWX/4Ug9Xbbv2q1so4EuS35AF11d69Yf/2ppnCu7 -r+qtX7csROF4KyFJYFNJUKf/hroPHKWuTGCcqzb+D68= +YYA5wJTHcjqXk/QBaDXHX/4Fb8W2OctF4X4VHyxH9Hsou4Ip7nzdfWzbBTcBiIrt +ybaaMO15L9Ctkli/capN+nCw2jWgivgiPnAmJNmLGeN6skTKjLPAau+839hBuQxu +P2aB/+XQfzFBA5TaWF83coDng4OGodhwHaOx10Kn7Bg= -----END SIGNATURE----- '''
BRIDGE_EXTRA_INFO_DESCRIPTOR = '''\ -extra-info OutwitsPlod 6FA9216CF3A06E89A03121ACC31F70F8DFD7DDCC -published 2014-03-12 16:07:08 -write-history 2014-03-12 16:07:08 (900 s) 3188736,2226176,2866176 -read-history 2014-03-12 16:07:08 (900 s) 3891200,2483200,2698240 -dirreq-write-history 2014-03-12 16:07:08 (900 s) 1024,0,2048 -dirreq-read-history 2014-03-12 16:07:08 (900 s) 0,0,0 -geoip-db-digest AAF7B842E52974556F9969A62DF8D31F9D886A33 -geoip6-db-digest C2C80F4EF2908E55A764603B08A8CB99A681EA19 -dirreq-stats-end 2014-03-12 16:07:08 (86400 s) +extra-info MiserLandfalls E08B324D20AD0A13E114F027AB9AC3F32CA696A0 +published 2014-11-04 06:23:22 +write-history 2014-11-04 06:23:22 (900 s) 3188736,2226176,2866176 +read-history 2014-11-04 06:23:22 (900 s) 3891200,2483200,2698240 +dirreq-write-history 2014-11-04 06:23:22 (900 s) 1024,0,2048 +dirreq-read-history 2014-11-04 06:23:22 (900 s) 0,0,0 +geoip-db-digest 09A0E093100B279AD9CFF47A67B13A21C6E1483F +geoip6-db-digest E983833985E4BCA34CEF611B2DF51942D188E638 +dirreq-stats-end 2014-11-04 06:23:22 (86400 s) dirreq-v3-ips dirreq-v3-reqs dirreq-v3-resp ok=16,not-enough-sigs=0,unavailable=0,not-found=0,not-modified=0,busy=0 dirreq-v3-direct-dl complete=0,timeout=0,running=0 dirreq-v3-tunneled-dl complete=12,timeout=0,running=0 -transport obfs3 152.78.9.20:17811 -transport obfs2 152.78.9.20:17812 -bridge-stats-end 2014-03-12 16:07:08 (86400 s) +transport obfs3 2.215.61.223:4057 +transport obfs2 2.215.61.223:4058 +transport scramblesuit 2.215.61.223:4059 password=ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 +transport obfs4 2.215.61.223:4060 iat-mode=0,node-id=19a448c01aa2e7d55979473b647e282459995b85,public-key=7a61b53701befdae0eeeffaecc73f14e20b537bb0f8b91ad7c2936dc63562b25 +bridge-stats-end 2014-11-04 06:23:22 (86400 s) bridge-ips ca=8 bridge-ip-versions v4=8,v6=0 bridge-ip-transports <OR>=8 router-signature -----BEGIN SIGNATURE----- -aW1ZlxqeaGcbNSxVpMONU0ER4xgdihb9X2crguzKa/TYVweCZ2Ew7x3Rsg4cUNpr -Fb05F3Zxg6ZUTMC8gfh6leDGw5eSX7OGVaaJICTfeLbNopLVk+JKNGMJ32R/Zia0 -feWndKJk/zj5ZtkMND8VVbWuJE+R6Jh2Q3L0p8IZ6J4= +KOXNPCoe+Q+thFA/Lz7RTja2tWp4oC6SvyIooEZibHtEDgiXuU4sELWT4bSOk3np +RVmu7QPMmNybx4LHowq3pOeNLtJzpWg8Pfo+N6tR+K4nqPwBRmpsuDhCD/tIXJlP +U36EY4UoN5ABPowhNZFeyr5A3vKiDr6j0hCOqYOhxPY= -----END SIGNATURE----- '''
BRIDGE_EXTRA_INFO_DESCRIPTOR_NEWER_DUPLICATE = '''\ -extra-info OutwitsPlod 6FA9216CF3A06E89A03121ACC31F70F8DFD7DDCC -published 2014-03-12 17:07:08 -write-history 2014-03-12 17:07:08 (900 s) 3188736,2226176,2866176 -read-history 2014-03-12 17:07:08 (900 s) 3891200,2483200,2698240 -dirreq-write-history 2014-03-12 17:07:08 (900 s) 1024,0,2048 -dirreq-read-history 2014-03-12 17:07:08 (900 s) 0,0,0 -geoip-db-digest AAF7B842E52974556F9969A62DF8D31F9D886A33 -geoip6-db-digest C2C80F4EF2908E55A764603B08A8CB99A681EA19 -dirreq-stats-end 2014-03-12 17:07:08 (86400 s) +extra-info MiserLandfalls E08B324D20AD0A13E114F027AB9AC3F32CA696A0 +published 2014-11-04 08:10:25 +write-history 2014-11-04 08:10:25 (900 s) 3188736,2226176,2866176,2226176 +read-history 2014-11-04 08:10:25 (900 s) 3891200,2483200,2698240,2483200 +dirreq-write-history 2014-11-04 08:10:25 (900 s) 1024,0,2048,3072 +dirreq-read-history 2014-11-04 08:10:25 (900 s) 0,0,0,0 +geoip-db-digest 09A0E093100B279AD9CFF47A67B13A21C6E1483F +geoip6-db-digest E983833985E4BCA34CEF611B2DF51942D188E638 +dirreq-stats-end 2014-11-04 08:10:25 (86400 s) dirreq-v3-ips dirreq-v3-reqs dirreq-v3-resp ok=16,not-enough-sigs=0,unavailable=0,not-found=0,not-modified=0,busy=0 dirreq-v3-direct-dl complete=0,timeout=0,running=0 dirreq-v3-tunneled-dl complete=12,timeout=0,running=0 -transport obfs3 152.78.9.20:17811 -transport obfs2 152.78.9.20:17812 -bridge-stats-end 2014-03-12 17:07:08 (86400 s) +transport obfs3 2.215.61.223:4057 +transport obfs2 2.215.61.223:4058 +transport scramblesuit 2.215.61.223:4059 password=ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 +transport obfs4 2.215.61.223:4060 iat-mode=0,node-id=19a448c01aa2e7d55979473b647e282459995b85,public-key=7a61b53701befdae0eeeffaecc73f14e20b537bb0f8b91ad7c2936dc63562b25 +bridge-stats-end 2014-11-04 08:10:25 (86400 s) bridge-ips ca=8 bridge-ip-versions v4=8,v6=0 bridge-ip-transports <OR>=8 router-signature -----BEGIN SIGNATURE----- -aW1ZlxqeaGcbNSxVpMONU0ER4xgdihb9X2crguzKa/TYVweCZ2Ew7x3Rsg4cUNpr -Fb05F3Zxg6ZUTMC8gfh6leDGw5eSX7OGVaaJICTfeLbNopLVk+JKNGMJ32R/Zia0 -feWndKJk/zj5ZtkMND8VVbWuJE+R6Jh2Q3L0p8IZ6J4= +KOXNPCoe+Q+thFA/Lz7RTja2tWp4oC6SvyIooEZibHtEDgiXuU4sELWT4bSOk3np +RVmu7QPMmNybx4LHowq3pOeNLtJzpWg8Pfo+N6tR+K4nqPwBRmpsuDhCD/tIXJlP +U36EY4UoN5ABPowhNZFeyr5A3vKiDr6j0hCOqYOhxPY= -----END SIGNATURE----- '''
@@ -147,6 +150,11 @@ class ParseDescriptorsTests(unittest.TestCase):
def setUp(self): """Test if we have Stem installed. Skip these tests if it's missing.""" + self.expectedIPBridge0 = '2.215.61.223' + self.expectedIPBridge1 = '80.44.173.87' + + self.expectedFprBridge0 = 'E08B324D20AD0A13E114F027AB9AC3F32CA696A0' + if self.skip: raise unittest.SkipTest("Couldn't import Stem.")
@@ -174,9 +182,8 @@ class ParseDescriptorsTests(unittest.TestCase): self.assertIsInstance(routers, list) bridge = routers[0] self.assertIsInstance(bridge, RelayDescriptor) - self.assertEqual(bridge.address, u'152.78.9.20') - self.assertEqual(bridge.fingerprint, - u'6FA9216CF3A06E89A03121ACC31F70F8DFD7DDCC') + self.assertEqual(bridge.address, self.expectedIPBridge0) + self.assertEqual(bridge.fingerprint, self.expectedFprBridge0)
def test_parse_descriptors_parseBridgeNetworkStatusFile_return_type(self): """``b.p.descriptors.parseNetworkStatusFile`` should return a dict.""" @@ -210,14 +217,15 @@ class ParseDescriptorsTests(unittest.TestCase): BRIDGE_NETWORKSTATUS_0) routers = descriptors.parseNetworkStatusFile(descFile) bridge = routers[0] - self.assertEqual(bridge.address, u'152.78.9.20') - self.assertEqual(bridge.fingerprint, - u'6FA9216CF3A06E89A03121ACC31F70F8DFD7DDCC') + self.assertEqual(bridge.address, self.expectedIPBridge0) + self.assertEqual(bridge.fingerprint, self.expectedFprBridge0)
def test_parse_descriptors_parseBridgeNetworkStatusFile_2(self): """Test ``b.p.descriptors.parseNetworkStatusFile`` with two bridge networkstatus descriptors. """ + expectedIPs = [self.expectedIPBridge0, self.expectedIPBridge1] + # Write the descriptor to a file for testing. This is necessary # because the function opens the networkstatus file to read it. descFile = self.writeTestDescriptorsToFile('networkstatus-bridges', @@ -225,9 +233,9 @@ class ParseDescriptorsTests(unittest.TestCase): BRIDGE_NETWORKSTATUS_1) routers = descriptors.parseNetworkStatusFile(descFile) bridge = routers[0] - self.assertEqual(bridge.address, u'152.78.9.20') - self.assertEqual(bridge.fingerprint, - u'6FA9216CF3A06E89A03121ACC31F70F8DFD7DDCC') + + self.assertIn(bridge.address, expectedIPs) + self.assertEqual(bridge.fingerprint, self.expectedFprBridge0)
def test_parse_descriptors_parseBridgeExtraInfoFiles_return_type(self): """The return type of ``b.p.descriptors.parseBridgeExtraInfoFiles`` @@ -253,9 +261,13 @@ class ParseDescriptorsTests(unittest.TestCase): descFile = io.BytesIO(BRIDGE_EXTRA_INFO_DESCRIPTOR) routers = descriptors.parseBridgeExtraInfoFiles(descFile) bridge = routers.values()[0] - self.assertEqual(len(bridge.transport), 2) - self.assertEqual(bridge.fingerprint, - u'6FA9216CF3A06E89A03121ACC31F70F8DFD7DDCC') + + # The number of transports we parsed should be equal to the number of + # 'transport' lines in the descriptor: + self.assertEqual(len(bridge.transport), + BRIDGE_EXTRA_INFO_DESCRIPTOR.count('transport ')) + + self.assertEqual(bridge.fingerprint, self.expectedFprBridge0)
def test_parse_descriptors_parseBridgeExtraInfoFiles_two_files(self): """Test for ``b.p.descriptors.parseBridgeExtraInfoFiles`` with two
tor-commits@lists.torproject.org