def setUp(self): self.helper = DomainListArgHelper() self.logger = logging.getLogger() for handler in self.logger.handlers: self.logger.removeHandler(handler) self.logger.addHandler(logging.NullHandler()) try: ArgHelper.bindable_ip('::1') except argparse.ArgumentTypeError: self.use_ipv6 = False else: self.use_ipv6 = True self.first_port = ZoneFileToServe._next_free_port self.custom_query_mixin_edns_options_orig = CustomQueryMixin.edns_options[:]
def setUp(self): self.tm = transport.DNSQueryTransportManager() self.resolver = Resolver.from_file('/etc/resolv.conf', StandardRecursiveQueryCD, transport_manager=self.tm) self.helper = DomainListArgHelper(self.resolver) self.logger = logging.getLogger() for handler in self.logger.handlers: self.logger.removeHandler(handler) self.logger.addHandler(logging.NullHandler()) try: ArgHelper.bindable_ip('::1') except argparse.ArgumentTypeError: self.use_ipv6 = False else: self.use_ipv6 = True self.first_port = ZoneFileToServe._next_free_port self.custom_query_mixin_edns_options_orig = CustomQueryMixin.edns_options[:]
def test_bindable_ip(self): self.assertEqual(ArgHelper.bindable_ip('127.0.0.1'), IPAddr('127.0.0.1')) if self.use_ipv6: self.assertEqual(ArgHelper.bindable_ip('::1'), IPAddr('::1')) # invalid IPv4 address with self.assertRaises(argparse.ArgumentTypeError): ArgHelper.bindable_ip('192.') # invalid IPv6 address with self.assertRaises(argparse.ArgumentTypeError): ArgHelper.bindable_ip('2001:') # invalid IPv4 to bind to with self.assertRaises(argparse.ArgumentTypeError): ArgHelper.bindable_ip('192.0.2.1') # invalid IPv6 to bind to with self.assertRaises(argparse.ArgumentTypeError): ArgHelper.bindable_ip('2001:db8::1')