Test: Add wslua.
[metze/wireshark/wip.git] / test / suite-nameres.sh
1 #!/bin/bash
2 #
3 # Test for correct name resolution behavior
4 #
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 2005 Ulf Lamping
8 #
9 # SPDX-License-Identifier: GPL-2.0-or-later
10 #
11
12 # common exit status values
13 EXIT_OK=0
14 EXIT_COMMAND_LINE=1
15 EXIT_ERROR=2
16
17 #TS_ARGS="-Tfields -e frame.number -e frame.time_epoch -e frame.time_delta"
18 TS_NR_ARGS="-r $CAPTURE_DIR/dns+icmp.pcapng.gz"
19
20 CUSTOM_PROFILE_NAME="Custom-$$"
21
22 # nameres.network_name: True
23 # nameres.use_external_name_resolver: False
24 # nameres.hosts_file_handling: False
25 # Profile: Default
26 name_resolution_net_t_ext_f_hosts_f_global() {
27         $TESTS_DIR/run_and_catch_crashes env $TS_NR_ENV $TSHARK $TS_NR_ARGS \
28                 -o "nameres.network_name: TRUE" \
29                 -o "nameres.use_external_name_resolver: FALSE" \
30                 -o "nameres.hosts_file_handling: FALSE" \
31                 | grep global-8-8-8-8 > /dev/null 2>&1
32         RETURNVALUE=$?
33         if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
34                 test_step_failed "Failed to resolve 8.8.8.8 using global hosts file."
35                 return
36         fi
37         test_step_ok
38 }
39
40 # nameres.network_name: True
41 # nameres.use_external_name_resolver: False
42 # nameres.hosts_file_handling: False
43 # Profile: Default
44 name_resolution_net_t_ext_f_hosts_f_personal() {
45         $TESTS_DIR/run_and_catch_crashes env $TS_NR_ENV $TSHARK $TS_NR_ARGS \
46                 -o "nameres.network_name: TRUE" \
47                 -o "nameres.use_external_name_resolver: FALSE" \
48                 -o "nameres.hosts_file_handling: FALSE" \
49                 | grep personal-8-8-4-4 > /dev/null 2>&1
50         RETURNVALUE=$?
51         if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
52                 test_step_failed "Failed to resolve 8.8.4.4 using personal hosts file."
53                 return
54         fi
55         test_step_ok
56 }
57
58 # nameres.network_name: True
59 # nameres_use_external_name_resolver: False
60 # nameres.hosts_file_handling: False
61 # Profile: Custom
62 name_resolution_net_t_ext_f_hosts_f_custom() {
63         $TESTS_DIR/run_and_catch_crashes env $TS_NR_ENV $TSHARK $TS_NR_ARGS \
64                 -o "nameres.network_name: TRUE" \
65                 -o "nameres.use_external_name_resolver: FALSE" \
66                 -o "nameres.hosts_file_handling: FALSE" \
67                 -C "$CUSTOM_PROFILE_NAME" \
68                 | grep custom-4-2-2-2 > /dev/null 2>&1
69         RETURNVALUE=$?
70         if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
71                 test_step_failed "Failed to resolve 4.2.2.2 using profile $CUSTOM_PROFILE_NAME."
72                 return
73         fi
74         test_step_ok
75 }
76
77 # nameres.network_name: True
78 # nameres.use_external_name_resolver: False
79 # nameres.hosts_file_handling: True
80 # Profile: Default
81 name_resolution_net_t_ext_f_hosts_t_global() {
82         $TESTS_DIR/run_and_catch_crashes env $TS_NR_ENV $TSHARK $TS_NR_ARGS \
83                 -o "nameres.network_name: TRUE" \
84                 -o "nameres.use_external_name_resolver: FALSE" \
85                 -o "nameres.hosts_file_handling: TRUE" \
86                 | grep global-8-8-8-8 > /dev/null 2>&1
87         RETURNVALUE=$?
88         if [ ! $RETURNVALUE -ne $EXIT_OK ]; then
89                 test_step_failed "Global hosts information showed up when it shouldn't."
90                 return
91         fi
92         test_step_ok
93 }
94
95 # nameres.network_name: True
96 # nameres.use_external_name_resolver: False
97 # nameres.hosts_file_handling: True
98 # Profile: Default
99 name_resolution_net_t_ext_f_hosts_t_personal() {
100         $TESTS_DIR/run_and_catch_crashes env $TS_NR_ENV $TSHARK $TS_NR_ARGS \
101                 -o "nameres.network_name: TRUE" \
102                 -o "nameres.use_external_name_resolver: FALSE" \
103                 -o "nameres.hosts_file_handling: TRUE" \
104                 | grep personal-8-8-4-4 > /dev/null 2>&1
105         RETURNVALUE=$?
106         if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
107                 test_step_failed "Personal hosts information showed up when it shouldn't."
108                 return
109         fi
110         test_step_ok
111 }
112
113 # nameres.network_name: True
114 # nameres_use_external_name_resolver: False
115 # nameres.hosts_file_handling: True
116 # Profile: Custom
117 name_resolution_net_t_ext_f_hosts_t_custom() {
118         $TESTS_DIR/run_and_catch_crashes env $TS_NR_ENV $TSHARK $TS_NR_ARGS \
119                 -o "nameres.network_name: TRUE" \
120                 -o "nameres.use_external_name_resolver: FALSE" \
121                 -o "nameres.hosts_file_handling: TRUE" \
122                 -C "$CUSTOM_PROFILE_NAME" \
123                 | grep custom-4-2-2-2 > /dev/null 2>&1
124         RETURNVALUE=$?
125         if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
126                 test_step_failed "Failed to resolve 4.2.2.2 using profile $CUSTOM_PROFILE_NAME."
127                 return
128         fi
129         test_step_ok
130 }
131
132 tshark_name_resolution_suite() {
133         test_step_add "Name resolution, no external, no profile hosts, global profile" name_resolution_net_t_ext_f_hosts_f_global
134         test_step_add "Name resolution, no external, no profile hosts, personal profile" name_resolution_net_t_ext_f_hosts_f_personal
135         test_step_add "Name resolution, no external, no profile hosts, custom profile" name_resolution_net_t_ext_f_hosts_f_custom
136
137         test_step_add "Name resolution, no external, profile hosts, global profile" name_resolution_net_t_ext_f_hosts_t_global
138         test_step_add "Name resolution, no external, profile hosts, personal profile" name_resolution_net_t_ext_f_hosts_t_personal
139         test_step_add "Name resolution, no external, profile hosts, custom profile" name_resolution_net_t_ext_f_hosts_t_custom
140 }
141
142 name_resolution_cleanup_step() {
143         rm -f $WS_BIN_PATH/hosts
144 }
145
146 name_resolution_prep_step() {
147         CUSTOM_PROFILE_PATH="$CONF_PATH/profiles/$CUSTOM_PROFILE_NAME"
148         TS_NR_ENV="${HOME_ENV}=${HOME_PATH}"
149
150         name_resolution_cleanup_step
151         mkdir -p "$CUSTOM_PROFILE_PATH"
152         cp "$TESTS_DIR/hosts.global" "$WS_BIN_PATH/hosts"
153         cp "$TESTS_DIR/hosts.personal" "$CONF_PATH/hosts"
154         cp "$TESTS_DIR/hosts.custom" "$CUSTOM_PROFILE_PATH/hosts"
155 }
156
157 name_resolution_suite() {
158         test_step_set_pre name_resolution_prep_step
159         test_step_set_post name_resolution_cleanup_step
160         test_suite_add "TShark name resolution" tshark_name_resolution_suite
161 }
162
163 #
164 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
165 #
166 # Local variables:
167 # sh-basic-offset: 8
168 # tab-width: 8
169 # indent-tabs-mode: t
170 # End:
171 #
172 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
173 # :indentSize=8:tabSize=8:noTabs=false:
174 #
175