def test_recursive_aggregation(self): args1 = ['-s', 'ns1.example.com=192.0.2.1,ns1.example.com=[2001:db8::1]', '-s', 'ns1.example.com=192.0.2.4,a.root-servers.net'] explicit_delegations1 = { (WILDCARD_EXPLICIT_DELEGATION, dns.rdatatype.NS): dns.rrset.from_text_list(WILDCARD_EXPLICIT_DELEGATION, 0, dns.rdataclass.IN, dns.rdatatype.NS, ['ns1.example.com', 'a.root-servers.net']), (dns.name.from_text('ns1.example.com'), dns.rdatatype.A): dns.rrset.from_text_list(dns.name.from_text('ns1.example.com'), 0, dns.rdataclass.IN, dns.rdatatype.A, ['192.0.2.1', '192.0.2.4']), (dns.name.from_text('ns1.example.com'), dns.rdatatype.AAAA): dns.rrset.from_text_list(dns.name.from_text('ns1.example.com'), 0, dns.rdataclass.IN, dns.rdatatype.AAAA, ['2001:db8::1']), (dns.name.from_text('a.root-servers.net'), dns.rdatatype.A): dns.rrset.from_text_list(dns.name.from_text('a.root-servers.net'), 0, dns.rdataclass.IN, dns.rdatatype.A, ['198.41.0.4']), (dns.name.from_text('a.root-servers.net'), dns.rdatatype.AAAA): dns.rrset.from_text_list(dns.name.from_text('a.root-servers.net'), 0, dns.rdataclass.IN, dns.rdatatype.AAAA, ['2001:503:ba3e::2:30']) } odd_ports1 = {} arghelper1 = ArgHelper(self.logger) arghelper1.build_parser('probe') arghelper1.parse_args(args1) arghelper1.aggregate_delegation_info() self.assertEqual(arghelper1.explicit_delegations, explicit_delegations1) self.assertEqual(arghelper1.odd_ports, odd_ports1)
def test_delegation_authoritative_aggregation_errors(self): args1 = ['-A', '-N', 'example.com:ns1.example.com=192.0.2.1,ns1.example.com=[2001:db8::1]', '-x', 'com:ns1.foo.com=192.0.2.3'] arghelper1 = ArgHelper(self.logger) arghelper1.build_parser('probe') arghelper1.parse_args(args1) # com is specified with -x but example.com is specified with -N with self.assertRaises(argparse.ArgumentTypeError): arghelper1.aggregate_delegation_info()
def test_delegation_authoritative_aggregation(self): args1 = [ '-A', '-N', 'example.com:ns1.example.com=192.0.2.1,ns1.example.com=[2001:db8::1]', '-x', 'foo.com:ns1.foo.com=192.0.2.3:50503' ] explicit_delegations1 = { (dns.name.from_text('com'), dns.rdatatype.NS): dns.rrset.from_text_list(dns.name.from_text('com'), 0, dns.rdataclass.IN, dns.rdatatype.NS, ['localhost']), (dns.name.from_text('foo.com'), dns.rdatatype.NS): dns.rrset.from_text_list(dns.name.from_text('foo.com'), 0, dns.rdataclass.IN, dns.rdatatype.NS, ['ns1.foo.com']), (dns.name.from_text('ns1.foo.com'), dns.rdatatype.A): dns.rrset.from_text_list(dns.name.from_text('ns1.foo.com'), 0, dns.rdataclass.IN, dns.rdatatype.A, ['192.0.2.3']), } for ex in (explicit_delegations1, ): if self.use_ipv6: ex[(dns.name.from_text('localhost'), dns.rdatatype.AAAA)] = \ dns.rrset.from_text_list(dns.name.from_text('localhost'), 0, dns.rdataclass.IN, dns.rdatatype.AAAA, ['::1']) loopback_ip = IPAddr('::1') else: ex[(dns.name.from_text('localhost'), dns.rdatatype.A)] = \ dns.rrset.from_text_list(dns.name.from_text('localhost'), 0, dns.rdataclass.IN, dns.rdatatype.A, ['127.0.0.1']) loopback_ip = IPAddr('127.0.0.1') odd_ports1 = { (dns.name.from_text('com'), loopback_ip): self.first_port, (dns.name.from_text('foo.com'), IPAddr('192.0.2.3')): 50503, } ZoneFileToServe._next_free_port = self.first_port arghelper1 = ArgHelper(self.resolver, self.logger) arghelper1.build_parser('probe', args1) arghelper1.aggregate_delegation_info() self.assertEqual(arghelper1.explicit_delegations, explicit_delegations1) self.assertEqual(arghelper1.odd_ports, odd_ports1)
def test_delegation_aggregation(self): args1 = [ '-A', '-N', 'example.com:ns1.example.com=192.0.2.1,ns1.example.com=[2001:db8::1]', '-N', 'example.com:ns1.example.com=192.0.2.4', '-N', 'example.com:ns2.example.com=192.0.2.2', '-N', 'example.com:ns3.example.com=192.0.2.3' ] args2 = [ '-A', '-N', 'example.com:ns1.example.com=192.0.2.1', '-D', 'example.com:34983 10 1 EC358CFAAEC12266EF5ACFC1FEAF2CAFF083C418', '-D', 'example.com:34983 10 2 608D3B089D79D554A1947BD10BEC0A5B1BDBE67B4E60E34B1432ED00 33F24B49' ] args3 = [ '-A', '-N', 'example.com:ns1.example.com=192.0.2.1', '-N', 'example1.com:ns1.example1.com=192.0.2.2' ] args4 = [ '-A', '-N', 'example.com:ns1.example.com=192.0.2.1', '-N', 'example.net:ns1.example.net=192.0.2.2' ] explicit_delegations1 = { (dns.name.from_text('com'), dns.rdatatype.NS): dns.rrset.from_text_list(dns.name.from_text('com'), 0, dns.rdataclass.IN, dns.rdatatype.NS, ['localhost']), } explicit_delegations2 = { (dns.name.from_text('com'), dns.rdatatype.NS): dns.rrset.from_text_list(dns.name.from_text('com'), 0, dns.rdataclass.IN, dns.rdatatype.NS, ['localhost']), } explicit_delegations3 = { (dns.name.from_text('com'), dns.rdatatype.NS): dns.rrset.from_text_list(dns.name.from_text('com'), 0, dns.rdataclass.IN, dns.rdatatype.NS, ['localhost']), } explicit_delegations4 = { (dns.name.from_text('com'), dns.rdatatype.NS): dns.rrset.from_text_list(dns.name.from_text('com'), 0, dns.rdataclass.IN, dns.rdatatype.NS, ['localhost']), (dns.name.from_text('net'), dns.rdatatype.NS): dns.rrset.from_text_list(dns.name.from_text('net'), 0, dns.rdataclass.IN, dns.rdatatype.NS, ['localhost']), } for ex in (explicit_delegations1, explicit_delegations2, explicit_delegations3, explicit_delegations4): if self.use_ipv6: ex[(dns.name.from_text('localhost'), dns.rdatatype.AAAA)] = \ dns.rrset.from_text_list(dns.name.from_text('localhost'), 0, dns.rdataclass.IN, dns.rdatatype.AAAA, ['::1']) loopback_ip = IPAddr('::1') else: ex[(dns.name.from_text('localhost'), dns.rdatatype.A)] = \ dns.rrset.from_text_list(dns.name.from_text('localhost'), 0, dns.rdataclass.IN, dns.rdatatype.A, ['127.0.0.1']) loopback_ip = IPAddr('127.0.0.1') odd_ports1 = { (dns.name.from_text('com'), loopback_ip): self.first_port } odd_ports2 = { (dns.name.from_text('com'), loopback_ip): self.first_port } odd_ports3 = { (dns.name.from_text('com'), loopback_ip): self.first_port } odd_ports4 = { (dns.name.from_text('com'), loopback_ip): self.first_port, (dns.name.from_text('net'), loopback_ip): self.first_port + 1, } if self.use_ipv6: rdata = b'AAAA ::1' else: rdata = b'A 127.0.0.1' zone_contents1 = b'''@ 600 IN SOA localhost. root.localhost. 1 1800 900 86400 600 @ 600 IN NS @ @ 600 IN ''' + rdata + \ b''' example 0 IN NS ns1.example example 0 IN NS ns2.example example 0 IN NS ns3.example ns1.example 0 IN A 192.0.2.1 ns1.example 0 IN A 192.0.2.4 ns1.example 0 IN AAAA 2001:db8::1 ns2.example 0 IN A 192.0.2.2 ns3.example 0 IN A 192.0.2.3 ''' zone_contents2 = b'''@ 600 IN SOA localhost. root.localhost. 1 1800 900 86400 600 @ 600 IN NS @ @ 600 IN ''' + rdata + \ b''' example 0 IN DS 34983 10 1 ec358cfaaec12266ef5acfc1feaf2caff083c418 example 0 IN DS 34983 10 2 608d3b089d79d554a1947bd10bec0a5b1bdbe67b4e60e34b1432ed0033f24b49 example 0 IN NS ns1.example ns1.example 0 IN A 192.0.2.1 ''' ZoneFileToServe._next_free_port = self.first_port arghelper1 = ArgHelper(self.resolver, self.logger) arghelper1.build_parser('probe', args1) arghelper1.aggregate_delegation_info() zone_to_serve = arghelper1._zones_to_serve[0] zone_obj = dns.zone.from_file(zone_to_serve.filename, dns.name.from_text('com')) zone_obj_other = dns.zone.from_text(zone_contents1, dns.name.from_text('com')) self.assertEqual(zone_obj, zone_obj_other) self.assertEqual(arghelper1.explicit_delegations, explicit_delegations1) self.assertEqual(arghelper1.odd_ports, odd_ports1) ZoneFileToServe._next_free_port = self.first_port arghelper2 = ArgHelper(self.resolver, self.logger) arghelper2.build_parser('probe', args2) arghelper2.aggregate_delegation_info() zone_to_serve = arghelper2._zones_to_serve[0] zone_obj = dns.zone.from_file(zone_to_serve.filename, dns.name.from_text('com')) zone_obj_other = dns.zone.from_text(zone_contents2, dns.name.from_text('com')) self.assertEqual(zone_obj, zone_obj_other) self.assertEqual(arghelper2.explicit_delegations, explicit_delegations2) self.assertEqual(arghelper2.odd_ports, odd_ports2) ZoneFileToServe._next_free_port = self.first_port arghelper3 = ArgHelper(self.resolver, self.logger) arghelper3.build_parser('probe', args3) arghelper3.aggregate_delegation_info() self.assertEqual(arghelper3.explicit_delegations, explicit_delegations3) self.assertEqual(arghelper3.odd_ports, odd_ports3) ZoneFileToServe._next_free_port = self.first_port arghelper4 = ArgHelper(self.resolver, self.logger) arghelper4.build_parser('probe', args4) arghelper4.aggregate_delegation_info() self.assertEqual(arghelper4.explicit_delegations, explicit_delegations4) self.assertEqual(arghelper4.odd_ports, odd_ports4)