Test: Add wslua.
[metze/wireshark/wip.git] / test / suite_nameres.py
1 #
2 # -*- coding: utf-8 -*-
3 # Wireshark tests
4 # By Gerald Combs <gerald@wireshark.org>
5 #
6 # Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
7 #
8 # SPDX-License-Identifier: GPL-2.0-or-later
9 #
10 '''Name resolution tests'''
11
12 import config
13 import os.path
14 import subprocesstest
15 import unittest
16
17 dns_icmp_pcapng = os.path.join(config.capture_dir, 'dns+icmp.pcapng.gz')
18
19 tf_str = { True: 'TRUE', False: 'FALSE' }
20
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],
27         )
28     if custom_profile:
29         tshark_cmd += ('-C', config.custom_profile_name)
30     self.assertRun(tshark_cmd, env=config.test_env)
31     if fail_on_match:
32         self.assertFalse(self.grepOutput(grep_str))
33     else:
34         self.assertTrue(self.grepOutput(grep_str))
35
36
37 class case_name_resolution(subprocesstest.SubprocessTestCase):
38
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
44         # Profile: Default
45         check_name_resolution(self, True, False, False, False, 'global-8-8-8-8')
46
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
52         # Profile: Default
53         check_name_resolution(self, True, False, False, False, 'personal-8-8-4-4')
54
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
60         # Profile: Custom
61         check_name_resolution(self, True, False, False, True, 'custom-4-2-2-2')
62
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
68         # Profile: Default
69         check_name_resolution(self, True, False, True, False, 'global-8-8-8-8', True)
70
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
76         # Profile: Default
77         check_name_resolution(self, True, False, True, False, 'personal-8-8-4-4')
78
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
84         # Profile: Custom
85         check_name_resolution(self, True, False, True, True, 'custom-4-2-2-2')