xref: /netbsd-src/external/bsd/unbound/dist/testdata/remote-threaded.tdir/remote-threaded.test (revision d0eba39ba71d0ccd0f91ae4c5ff83442e84710bf)
1# #-- remote-threaded.test --#
2# source the master var file when it's there
3[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
4# use .tpkg.var.test for in test variable passing
5[ -f .tpkg.var.test ] && source .tpkg.var.test
6
7PRE="../.."
8
9# exit value is 1 on usage
10$PRE/unbound-control -h
11if test $? -ne 1; then
12	echo "wrong exit value for usage."
13	exit 1
14else
15	echo "exit value for usage: OK"
16fi
17
18# use lock-verify if possible
19
20# test if the server is up.
21echo "> dig www.example.com."
22dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile
23echo "> check answer"
24if grep "10.20.30.40" outfile; then
25	echo "OK"
26else
27	echo "> cat logfiles"
28	cat fwd.log
29	cat unbound.log
30	echo "Not OK"
31	exit 1
32fi
33
34# exit value is 1 when a bad command is given.
35echo "$PRE/unbound-control -c ub.conf blablargh"
36$PRE/unbound-control -c ub.conf blablargh
37if test $? -ne 1; then
38	echo "wrong exit value on error."
39	echo "> cat logfiles"
40	cat fwd.log
41	cat unbound.log
42	exit 1
43else
44	echo "correct exit value on error"
45fi
46
47# reload the server. test if the server came up by putting a new
48# local-data element in the server.
49echo "server: local-data: 'afterreload. IN A 5.6.7.8'" >> ub.conf
50echo "$PRE/unbound-control -c ub.conf reload"
51$PRE/unbound-control -c ub.conf reload
52if test $? -ne 0; then
53	echo "wrong exit value after success"
54	exit 1
55fi
56
57echo "> dig afterreload."
58dig @127.0.0.1 -p $UNBOUND_PORT afterreload. | tee outfile
59echo "> check answer"
60if grep "5.6.7.8" outfile; then
61	echo "OK"
62else
63	echo "> cat logfiles"
64	cat fwd.log
65	cat unbound.log
66	echo "Not OK"
67	exit 1
68fi
69
70# must have had queries now.  1 since reload.
71echo "$PRE/unbound-control -c ub.conf stats"
72$PRE/unbound-control -c ub.conf stats > tmp.$$
73if test $? -ne 0; then
74	echo "wrong exit value after success"
75	cat fwd.log
76	cat unbound.log
77	exit 1
78fi
79if grep "^total.num.queries=[1-9][0-9]*$" tmp.$$; then
80	echo "OK"
81else
82	echo "bad stats"
83	cat tmp.$$
84	exit 1
85fi
86
87# verbosity
88echo "$PRE/unbound-control -c ub.conf verbosity 4"
89$PRE/unbound-control -c ub.conf verbosity 4
90if test $? -ne 0; then
91	echo "wrong exit value after success"
92	exit 1
93fi
94
95# check syntax error in parse
96echo "$PRE/unbound-control -c ub.conf verbosity jkdf"
97$PRE/unbound-control -c ub.conf verbosity jkdf
98if test $? -ne 1; then
99	echo "wrong exit value after failure"
100	exit 1
101fi
102
103# check bad credentials
104cp ub.conf bad.conf
105echo "remote-control:" >> bad.conf
106echo "	server-key-file: bad_server.key" >> bad.conf
107echo "	server-cert-file: bad_server.pem" >> bad.conf
108echo "	control-key-file: bad_control.key" >> bad.conf
109echo "	control-cert-file: bad_control.pem" >> bad.conf
110echo "$PRE/unbound-control -c bad.conf verbosity 2"
111$PRE/unbound-control -c bad.conf verbosity 2
112if test $? -ne 1; then
113	echo "wrong exit value after failure"
114	exit 1
115fi
116
117# create a new local zone
118echo "> test of local zone"
119echo "$PRE/unbound-control -c ub.conf local_zone example.net static"
120$PRE/unbound-control -c ub.conf local_zone example.net static
121if test $? -ne 0; then
122	echo "wrong exit value after success"
123	exit 1
124fi
125echo "$PRE/unbound-control -c ub.conf local_data www.example.net A 192.0.2.1"
126$PRE/unbound-control -c ub.conf local_data www.example.net A 192.0.2.1
127if test $? -ne 0; then
128	echo "wrong exit value after success"
129	exit 1
130fi
131
132# check that www.example.net exists
133echo "> dig www.example.net."
134dig @127.0.0.1 -p $UNBOUND_PORT www.example.net. | tee outfile
135echo "> check answer"
136if grep "192.0.2.1" outfile; then
137	echo "OK"
138else
139	echo "> cat logfiles"
140	cat fwd.log
141	cat unbound.log
142	echo "Not OK"
143	exit 1
144fi
145
146# check that mail.example.net has nxdomain
147echo "> dig mail.example.net."
148dig @127.0.0.1 -p $UNBOUND_PORT mail.example.net. | tee outfile
149echo "> check answer"
150if grep "NXDOMAIN" outfile; then
151	echo "OK"
152else
153	echo "> cat logfiles"
154	cat fwd.log
155	cat unbound.log
156	echo "Not OK"
157	exit 1
158fi
159
160# remove www.example.net - check it gets nxdomain
161echo "$PRE/unbound-control -c ub.conf local_data_remove www.example.net"
162$PRE/unbound-control -c ub.conf local_data_remove www.example.net
163if test $? -ne 0; then
164	echo "wrong exit value after success"
165	exit 1
166fi
167echo "> dig www.example.net."
168dig @127.0.0.1 -p $UNBOUND_PORT www.example.net. | tee outfile
169echo "> check answer"
170if grep "NXDOMAIN" outfile; then
171	echo "OK"
172else
173	echo "> cat logfiles"
174	cat fwd.log
175	cat unbound.log
176	echo "Not OK"
177	exit 1
178fi
179
180# remove example.net - check its gone.
181echo "$PRE/unbound-control -c ub.conf local_zone_remove example.net"
182$PRE/unbound-control -c ub.conf local_zone_remove example.net
183if test $? -ne 0; then
184	echo "wrong exit value after success"
185	exit 1
186fi
187echo "> dig www.example.net."
188dig @127.0.0.1 -p $UNBOUND_PORT www.example.net. | tee outfile
189echo "> check answer"
190if grep "SERVFAIL" outfile; then
191	echo "OK"
192else
193	echo "> cat logfiles"
194	cat fwd.log
195	cat unbound.log
196	echo "Not OK"
197	exit 1
198fi
199
200# dump the cache
201echo "> test cache dump"
202# fillup cache
203echo "dig www.example.com"
204dig @127.0.0.1 -p $UNBOUND_PORT www.example.com.
205echo "$PRE/unbound-control -c ub.conf dump_cache"
206$PRE/unbound-control -c ub.conf dump_cache > tmp.$$
207if test $? -ne 0; then
208	echo "wrong exit value after success"
209	exit 1
210fi
211cat tmp.$$
212# we do not look at content. Only thread 0 content.
213# because it may not be there when it is compiled with processes only.
214if grep MSG_CACHE tmp.$$; then
215	echo "OK this is a cache dump"
216else
217	echo "Not OK cache dump"
218	exit 1
219fi
220
221# test lookup
222echo "$PRE/unbound-control -c ub.conf lookup www.example.com"
223$PRE/unbound-control -c ub.conf lookup www.example.com
224if test $? -ne 0; then
225	echo "wrong exit value after success"
226	exit 1
227fi
228# answer to lookup is meaningless because of use a forwarder, oh well.
229
230# load the cache dump.
231echo "$PRE/unbound-control -c ub.conf load_cache < tmp.$$"
232$PRE/unbound-control -c ub.conf load_cache < tmp.$$
233if test $? -ne 0; then
234	echo "wrong exit value after success"
235	exit 1
236fi
237# do not check if cache dump contents are present ; other threads
238# may not have gotten it when it is compiled with processes only.
239
240# flushing
241echo "$PRE/unbound-control -c ub.conf flush www.example.net"
242$PRE/unbound-control -c ub.conf flush www.example.net
243if test $? -ne 0; then
244	echo "wrong exit value after success"
245	exit 1
246fi
247
248echo "$PRE/unbound-control -c ub.conf flush_type www.example.net TXT"
249$PRE/unbound-control -c ub.conf flush_type www.example.net TXT
250if test $? -ne 0; then
251	echo "wrong exit value after success"
252	exit 1
253fi
254
255echo "$PRE/unbound-control -c ub.conf flush_zone example.net"
256$PRE/unbound-control -c ub.conf flush_zone example.net
257if test $? -ne 0; then
258	echo "wrong exit value after success"
259	exit 1
260fi
261
262# now stop the server
263echo "$PRE/unbound-control -c ub.conf stop"
264$PRE/unbound-control -c ub.conf stop
265if test $? -ne 0; then
266	echo "wrong exit value after success"
267	exit 1
268fi
269# see if the server has really exited.
270TRY_MAX=20
271for (( try=0 ; try <= $TRY_MAX ; try++ )) ; do
272	if kill -0 $UNBOUND_PID 2>&1 | tee tmp.$$; then
273		echo "not stopped yet, waiting"
274		sleep 1
275	else
276		echo "stopped OK; break"
277		break;
278	fi
279	if grep "No such process" tmp.$$; then
280		echo "stopped OK; break"
281		break;
282	fi
283done
284if kill -0 $UNBOUND_PID; then
285	echo "still up!"
286	echo "> cat logfiles"
287	cat fwd.log
288	cat unbound.log
289	echo "not stopped, failure"
290	exit 1
291else
292	echo "stopped OK"
293
294        if test -f ublocktrace.0; then
295		if $PRE/lock-verify ublocktrace.*; then
296			echo "lock-verify test worked."
297		else
298			echo "lock-verify test failed."
299			cat fwd.log
300			cat unbound.log
301			exit 1
302		fi
303	fi
304fi
305
306echo "> cat logfiles"
307cat fwd.log
308cat unbound.log
309echo "> OK"
310exit 0
311