Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / test / suite_nameres.py
blob31030af5c0acd655ba7b48aef1c1342262ec7a34
2 # Wireshark tests
3 # By Gerald Combs <gerald@wireshark.org>
5 # Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
7 # SPDX-License-Identifier: GPL-2.0-or-later
9 '''Name resolution tests'''
11 import os.path
12 import shutil
13 import subprocess
14 from subprocesstest import grep_output
15 import pytest
17 tf_str = { True: 'TRUE', False: 'FALSE' }
19 custom_profile_name = 'Custom Profile'
21 @pytest.fixture
22 def nameres_setup(program_path, conf_path):
23 bundle_path = os.path.join(program_path, 'Wireshark.app', 'Contents', 'MacOS')
24 if os.path.isdir(bundle_path):
25 # Don't modify our application bundle.
26 global_path = None
27 else:
28 global_path = program_path
29 custom_profile_path = os.path.join(conf_path, 'profiles', custom_profile_name)
30 os.makedirs(custom_profile_path)
31 this_dir = os.path.dirname(__file__)
32 hosts_path_pfx = os.path.join(this_dir, 'hosts.')
34 if global_path is not None:
35 shutil.copyfile(hosts_path_pfx + 'global', os.path.join(global_path, 'hosts'))
36 shutil.copyfile(hosts_path_pfx + 'personal', os.path.join(conf_path, 'hosts'))
37 shutil.copyfile(hosts_path_pfx + 'custom', os.path.join(custom_profile_path, 'hosts'))
38 return global_path is not None
41 @pytest.fixture
42 def check_name_resolution(cmd_tshark, capture_file, nameres_setup, test_env):
43 def check_name_resolution_real(o_net_name, o_external_name_res, custom_profile, grep_str, fail_on_match=False):
44 if grep_str.startswith('global') and not nameres_setup:
45 pytest.skip('Global name resolution tests would require modifying the application bundle')
46 tshark_cmd = (cmd_tshark,
47 '-r', capture_file('dns+icmp.pcapng.gz'),
48 '-o', 'nameres.network_name: ' + tf_str[o_net_name],
49 '-o', 'nameres.use_external_name_resolver: ' + tf_str[o_external_name_res],
51 if custom_profile:
52 tshark_cmd += ('-C', custom_profile_name)
53 proc = subprocess.run(tshark_cmd, check=True, capture_output=True, encoding='utf-8', env=test_env)
54 if fail_on_match:
55 assert not grep_output(proc.stdout, grep_str)
56 else:
57 assert grep_output(proc.stdout, grep_str)
58 return check_name_resolution_real
61 class TestNameResolution:
63 def test_name_resolution_net_t_ext_f_hosts_f_global(self, check_name_resolution):
64 '''Name resolution, no external, global profile.'''
65 # nameres.network_name: True
66 # nameres.use_external_name_resolver: False
67 # Profile: Default
68 check_name_resolution(True, False, False, 'global-8-8-8-8')
70 def test_name_resolution_net_t_ext_f_hosts_f_personal(self, check_name_resolution):
71 '''Name resolution, no external, personal profile.'''
72 # nameres.network_name: True
73 # nameres.use_external_name_resolver: False
74 # Profile: Default
75 check_name_resolution(True, False, False, 'personal-8-8-4-4')
77 def test_name_resolution_net_t_ext_f_hosts_f_custom(self, check_name_resolution):
78 '''Name resolution, no external, no profile hosts, custom profile.'''
79 # nameres.network_name: True
80 # nameres_use_external_name_resolver: False
81 # Profile: Custom
82 check_name_resolution(True, False, True, 'custom-4-2-2-2')
84 def test_hosts_any(self, cmd_tshark, capture_file, base_env):
85 stdout = subprocess.check_output((cmd_tshark,
86 '-r', capture_file('dns+icmp.pcapng.gz'),
87 '-qz', 'hosts',
88 ), encoding='utf-8', env=base_env)
89 assert '174.137.42.65\twww.wireshark.org' in stdout
90 assert 'fe80::6233:4bff:fe13:c558\tCrunch.local' in stdout
92 def test_hosts_ipv4(self, cmd_tshark, capture_file, base_env):
93 stdout = subprocess.check_output((cmd_tshark,
94 '-r', capture_file('dns+icmp.pcapng.gz'),
95 '-qz', 'hosts,ipv4',
96 ), encoding='utf-8', env=base_env)
97 assert '174.137.42.65\twww.wireshark.org' in stdout
98 assert 'fe80::6233:4bff:fe13:c558\tCrunch.local' not in stdout
100 def test_hosts_ipv6(self, cmd_tshark, capture_file, base_env):
101 stdout = subprocess.check_output((cmd_tshark,
102 '-r', capture_file('dns+icmp.pcapng.gz'),
103 '-qz', 'hosts,ipv6',
104 ), encoding='utf-8', env=base_env)
105 assert '174.137.42.65\twww.wireshark.org' not in stdout
106 assert 'fe80::6233:4bff:fe13:c558\tCrunch.local' in stdout