commit 96678f167f210d10f65c14d977e9f764c4d70dbd Author: Damian Johnson atagar@torproject.org Date: Sat Apr 14 17:09:37 2012 -0700
Adding a test for descriptor content from 2005
Version 2 relay server descriptors were first introduced in 2005 so adding a descriptor from back then. This in theory doesn't exercise anything that the unit tests don't already do, but it still provides some good use cases (mostly around deprecated attributes).
I ran over the full December 2005 metrics tarball and all descriptors were happily parsed. --- test/integ/descriptor/data/old_descriptor | 47 +++++++++++++++++++++++ test/integ/descriptor/server_descriptor.py | 56 ++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/test/integ/descriptor/data/old_descriptor b/test/integ/descriptor/data/old_descriptor new file mode 100644 index 0000000..5407aa8 --- /dev/null +++ b/test/integ/descriptor/data/old_descriptor @@ -0,0 +1,47 @@ +router krypton 212.37.39.59 8000 0 0 +platform Tor 0.1.0.14 on FreeBSD i386 +published 2005-12-16 18:01:03 +opt fingerprint 3E2F 63E2 356F 5231 8B53 6A12 B644 5373 808A 5D6C +uptime 64820 +bandwidth 102400 10485760 0 +onion-key +-----BEGIN RSA PUBLIC KEY----- +MIGJAoGBAOewVPvehUE/Iy06e/NmUyzwBdkL89DP3q+I68hJJsxQgd1Fqm2CVN4E +X0l3U14e3yyihr8xz1qmvQenWyKMx6B5ZjHrRAk774nTXzqqZMbcEKGnoWKTAgfC +SrZYD4YdO2vPIA3OIBLBvj6HlyZWPVulQANpETK1TOACKeqs6vlhAgMBAAE= +-----END RSA PUBLIC KEY----- +signing-key +-----BEGIN RSA PUBLIC KEY----- +MIGJAoGBAJjsGNwSkG7xCzWEPTr2NBrC4k2Bx0SnTv8RfgUwqRg8rLss5CoZw7BV +GL3g6PNe13rWcu7rYg27mT81T4cehrl0omnx4FrhDPmnJY4d+yjUiLKujTYaijyZ +8ll4Mr1Ua3M2tTa+79sA8rXAg3zMf+BtTfIcK4avm+csipZ75r9BAgMBAAE= +-----END RSA PUBLIC KEY----- +opt write-history 2005-12-16 18:00:48 (900 s) 81,8848,8927,8927,83,8848,8931,8929,81,8846,8929,8931,81,8848,8929,8927,81,8846,8929,8929,83,8848,8931,8927,9544,23145,118733,12471330,23681225,32974322,36669050,50028191,60119352,43959405,104125876,93764839,67886465,56660787,69614721,49677518,72758978,69080350,68451562,56135957,66072248,44186182,63136414,78723340,84085493,73800911,61322609,54493047,40058835,35991325,33933884,43033805,30004913,31375439,29870384,39901793,24405790,46428634,32855040,31738054,32096150,34571772,47317095,43861120,1725009,2709813,3632379,7206137,4376659,3499688,2148089,2420819,3039400,3271931,2661625,2387027,943794,138137,167325,152659,120259,119828,120342,116812,118734,117279,116769,114764,115673,117709,117201,110668 +opt read-history 2005-12-16 18:00:48 (900 s) 20774,489973,510022,511163,20949,490665,509936,510266,20919,490429,512036,508640,20666,485937,506582,505071,20662,484684,507452,506131,20565,485822,505385,505766,28300,499433,627237,12392493,20716078,25654673,25415889,39581836,49991512,31545049,96363762,80390334,60930455,45885095,57137777,42643192,59698768,54573481,58379825,45862920,58781990,33448161,53507694,73363721,70825862,61283831,49325261,44674036,28451429,25009272,22895835,34914097,21103340,19156546,21131703,33036587,18445151,30464430,21857164,27329112,22507170,29536769,37525461,42026081,1778746,3200903,4137862,7712377,4397719,3980947,2650315,2440799,3522111,3774977,3165517,2407670,1427206,644034,672441,173113,609713,630447,632529,136977,611086,629716,629248,135385,607471,627380,625011,131334 +opt hibernating 1 +reject 169.254.0.0/255.255.0.0:* +reject 127.0.0.0/255.0.0.0:* +reject 192.168.0.0/255.255.0.0:* +reject 10.0.0.0/255.0.0.0:* +reject 172.16.0.0/255.240.0.0:* +accept *:20-22 +accept *:53 +accept *:79-81 +accept *:110 +accept *:143 +accept *:443 +accept *:706 +accept *:873 +accept *:993 +accept *:995 +accept *:6660-6669 +accept *:8008 +accept *:8080 +accept *:8888 +reject *:* +router-signature +-----BEGIN SIGNATURE----- +mHTlJGu2d2ZZgXfoI0CZBiLMCKbHox2n+Q3OGcivLj0kcYfJ/7/jk4o5ABRgyOHM +zJ7FnC2wSg19MB8jeAvKkxdd1hp0OZQp+tCRq/7p11+6E0qvJcio+RwdeZAb0dQf +suUOPIU/lHzfmraZMO3ovK4VjiWKQ7PgE1vAH7sTyZA= +-----END SIGNATURE----- diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py index f1af13c..b974098 100644 --- a/test/integ/descriptor/server_descriptor.py +++ b/test/integ/descriptor/server_descriptor.py @@ -105,6 +105,62 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= self.assertEquals([], desc.get_unrecognized_lines()) self.assertEquals("LHsnvqsEtOJFnYnKbVzRzF+Vpok", desc.digest())
+ def test_old_descriptor(self): + """ + Parses a relay server descriptor from 2005. + """ + + descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, "old_descriptor") + + descriptor_file = open(descriptor_path) + descriptor_contents = descriptor_file.read() + descriptor_file.close() + + desc = stem.descriptor.server_descriptor.RelayDescriptorV3(descriptor_contents) + self.assertEquals("krypton", desc.nickname) + self.assertEquals("3E2F63E2356F52318B536A12B6445373808A5D6C", desc.fingerprint) + self.assertEquals("212.37.39.59", desc.address) + self.assertEquals(8000, desc.or_port) + self.assertEquals(0, desc.socks_port) + self.assertEquals(0, desc.dir_port) + self.assertEquals("Tor 0.1.0.14 on FreeBSD i386", desc.platform) + self.assertEquals(stem.version.Version("0.1.0.14"), desc.tor_version) + self.assertEquals("FreeBSD i386", desc.operating_system) + self.assertEquals(64820, desc.uptime) + self.assertEquals(datetime.datetime(2005, 12, 16, 18, 1, 3), desc.published) + self.assertEquals(None, desc.contact) + self.assertEquals(None, desc.link_protocols) + self.assertEquals(None, desc.circuit_protocols) + self.assertEquals(True, desc.hibernating) + self.assertEquals(False, desc.allow_single_hop_exits) + self.assertEquals(False, desc.extra_info_cache) + self.assertEquals(None, desc.extra_info_digest) + self.assertEquals(None, desc.hidden_service_dir) + self.assertEquals([], desc.family) + self.assertEquals(102400, desc.average_bandwidth) + self.assertEquals(10485760, desc.burst_bandwidth) + self.assertEquals(0, desc.observed_bandwidth) + self.assertEquals(datetime.datetime(2005, 12, 16, 18, 0, 48), desc.read_history_end) + self.assertEquals(900, desc.read_history_interval) + self.assertEquals(datetime.datetime(2005, 12, 16, 18, 0, 48), desc.write_history_end) + self.assertEquals(900, desc.write_history_interval) + self.assertEquals([], desc.get_unrecognized_lines()) + + # The read-history and write-history lines are pretty long so just checking + # the initial contents for the line and parsed values. + + read_start = "2005-12-16 18:00:48 (900 s) 20774,489973,510022" + self.assertTrue(desc.read_history.startswith(read_start)) + + read_values_start = [20774, 489973, 510022, 511163, 20949] + self.assertEquals(read_values_start, desc.read_history_values[:5]) + + write_start = "2005-12-16 18:00:48 (900 s) 81,8848,8927,8927" + self.assertTrue(desc.write_history.startswith(write_start)) + + write_values_start = [81, 8848, 8927, 8927, 83, 8848, 8931, 8929, 81, 8846] + self.assertEquals(write_values_start, desc.write_history_values[:10]) + def test_cached_descriptor(self): """ Parses the cached descriptor file in our data directory, checking that it
tor-commits@lists.torproject.org