2 # -*- coding: utf-8 -*-
4 # By Gerald Combs <gerald@wireshark.org>
6 # Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
8 # SPDX-License-Identifier: GPL-2.0-or-later
10 '''Name resolution tests'''
17 dns_icmp_pcapng = os.path.join(config.capture_dir, 'dns+icmp.pcapng.gz')
19 tf_str = { True: 'TRUE', False: 'FALSE' }
21 def check_name_resolution(self, o_net_name, o_external_name_res, o_hosts_file, custom_profile, grep_str, fail_on_match=False):
22 tshark_cmd = (config.cmd_tshark,
23 '-r', dns_icmp_pcapng,
24 '-o', 'nameres.network_name: ' + tf_str[o_net_name],
25 '-o', 'nameres.use_external_name_resolver: ' + tf_str[o_external_name_res],
26 '-o', 'nameres.hosts_file_handling: ' + tf_str[o_hosts_file],
29 tshark_cmd += ('-C', config.custom_profile_name)
30 self.assertRun(tshark_cmd, env=config.test_env)
32 self.assertFalse(self.grepOutput(grep_str))
34 self.assertTrue(self.grepOutput(grep_str))
37 class case_name_resolution(subprocesstest.SubprocessTestCase):
39 def test_name_resolution_net_t_ext_f_hosts_f_global(self):
40 '''Name resolution, no external, no profile hosts, global profile.'''
41 # nameres.network_name: True
42 # nameres.use_external_name_resolver: False
43 # nameres.hosts_file_handling: False
45 check_name_resolution(self, True, False, False, False, 'global-8-8-8-8')
47 def test_name_resolution_net_t_ext_f_hosts_f_personal(self):
48 '''Name resolution, no external, no profile hosts, personal profile.'''
49 # nameres.network_name: True
50 # nameres.use_external_name_resolver: False
51 # nameres.hosts_file_handling: False
53 check_name_resolution(self, True, False, False, False, 'personal-8-8-4-4')
55 def test_name_resolution_net_t_ext_f_hosts_f_custom(self):
56 '''Name resolution, no external, no profile hosts, custom profile.'''
57 # nameres.network_name: True
58 # nameres_use_external_name_resolver: False
59 # nameres.hosts_file_handling: False
61 check_name_resolution(self, True, False, False, True, 'custom-4-2-2-2')
63 def test_name_resolution_net_t_ext_f_hosts_t_global(self):
64 '''Name resolution, no external, profile hosts, global profile.'''
65 # nameres.network_name: True
66 # nameres.use_external_name_resolver: False
67 # nameres.hosts_file_handling: True
69 check_name_resolution(self, True, False, True, False, 'global-8-8-8-8', True)
71 def test_name_resolution_net_t_ext_f_hosts_t_personal(self):
72 '''Name resolution, no external, profile hosts, personal profile.'''
73 # nameres.network_name: True
74 # nameres.use_external_name_resolver: False
75 # nameres.hosts_file_handling: True
77 check_name_resolution(self, True, False, True, False, 'personal-8-8-4-4')
79 def test_name_resolution_net_t_ext_f_hosts_t_custom(self):
80 '''Name resolution, no external, profile hosts, custom profile.'''
81 # nameres.network_name: True
82 # nameres_use_external_name_resolver: False
83 # nameres.hosts_file_handling: True
85 check_name_resolution(self, True, False, True, True, 'custom-4-2-2-2')
87 def test_hosts_any(self):
88 self.runProcess((config.cmd_tshark,
89 '-r', dns_icmp_pcapng,
93 self.assertTrue(self.grepOutput('174.137.42.65\twww.wireshark.org'))
94 self.assertTrue(self.grepOutput('fe80::6233:4bff:fe13:c558\tCrunch.local'))
96 def test_hosts_ipv4(self):
97 self.runProcess((config.cmd_tshark,
98 '-r', dns_icmp_pcapng,
102 self.assertTrue(self.grepOutput('174.137.42.65\twww.wireshark.org'))
103 self.assertFalse(self.grepOutput('fe80::6233:4bff:fe13:c558\tCrunch.local'))
105 def test_hosts_ipv6(self):
106 self.runProcess((config.cmd_tshark,
107 '-r', dns_icmp_pcapng,
111 self.assertTrue(self.grepOutput('fe80::6233:4bff:fe13:c558\tCrunch.local'))
112 self.assertFalse(self.grepOutput('174.137.42.65\twww.wireshark.org'))