]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - testdata/09-unbound-control.tdir/09-unbound-control.test
Vendor import of Unbound 1.6.6.
[FreeBSD/FreeBSD.git] / testdata / 09-unbound-control.tdir / 09-unbound-control.test
1 # #-- 09-unbound-control.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
7 PRE="../.."
8
9 # exit value is 1 on usage
10 $PRE/unbound-control -h
11 if test $? -ne 1; then
12         echo "wrong exit value for usage."
13         exit 1
14 else
15         echo "exit value for usage: OK"
16 fi
17
18 # use lock-verify if possible
19
20 # test if the server is up.
21 echo "> dig www.example.com."
22 dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile
23 echo "> check answer"
24 if grep "10.20.30.40" outfile; then
25         echo "OK"
26 else
27         echo "> cat logfiles"
28         cat fwd.log 
29         cat unbound.log
30         echo "Not OK"
31         exit 1
32 fi
33
34 # exit value is 1 when a bad command is given.
35 echo "$PRE/unbound-control -c ub.conf blablargh"
36 $PRE/unbound-control -c ub.conf blablargh
37 if test $? -ne 1; then
38         echo "wrong exit value on error."
39         echo "> cat logfiles"
40         cat fwd.log 
41         cat unbound.lo
42         exit 1
43 else
44         echo "correct exit value on error"
45 fi
46
47 # reload the server. test if the server came up by putting a new
48 # local-data element in the server.
49 echo "server: local-data: 'afterreload. IN A 5.6.7.8'" >> ub.conf
50 echo "$PRE/unbound-control -c ub.conf reload"
51 $PRE/unbound-control -c ub.conf reload
52 if test $? -ne 0; then
53         echo "wrong exit value after success"
54         exit 1
55 fi
56
57 echo "> dig afterreload."
58 dig @127.0.0.1 -p $UNBOUND_PORT afterreload. | tee outfile
59 echo "> check answer"
60 if grep "5.6.7.8" outfile; then
61         echo "OK"
62 else
63         echo "> cat logfiles"
64         cat fwd.log 
65         cat unbound.log
66         echo "Not OK"
67         exit 1
68 fi
69
70 # must have had queries now.  1 since reload.
71 echo "$PRE/unbound-control -c ub.conf stats"
72 $PRE/unbound-control -c ub.conf stats > tmp.$$
73 if test $? -ne 0; then
74         echo "wrong exit value after success"
75         exit 1
76 fi
77 if grep "^total.num.queries=[1-9][0-9]*$" tmp.$$; then
78         echo "OK"
79 else
80         echo "bad stats"
81         cat tmp.$$
82         exit 1
83 fi
84
85 # verbosity
86 echo "$PRE/unbound-control -c ub.conf verbosity 2"
87 $PRE/unbound-control -c ub.conf verbosity 2
88 if test $? -ne 0; then
89         echo "wrong exit value after success"
90         exit 1
91 fi
92
93 # check syntax error in parse 
94 echo "$PRE/unbound-control -c ub.conf verbosity jkdf"
95 $PRE/unbound-control -c ub.conf verbosity jkdf
96 if test $? -ne 1; then
97         echo "wrong exit value after failure"
98         exit 1
99 fi
100
101 # check bad credentials
102 cp ub.conf bad.conf
103 echo "remote-control:" >> bad.conf
104 echo "  server-key-file: bad_server.key" >> bad.conf
105 echo "  server-cert-file: bad_server.pem" >> bad.conf
106 echo "  control-key-file: bad_control.key" >> bad.conf
107 echo "  control-cert-file: bad_control.pem" >> bad.conf
108 echo "$PRE/unbound-control -c bad.conf verbosity 2"
109 $PRE/unbound-control -c bad.conf verbosity 2
110 if test $? -ne 1; then
111         echo "wrong exit value after failure"
112         exit 1
113 fi
114
115 # check spoofedclient credentials
116 rm -f bad.conf
117 cp ub.conf bad.conf
118 echo "remote-control:" >> bad.conf
119 echo "  server-key-file: unbound_server.key" >> bad.conf
120 echo "  server-cert-file: unbound_server.pem" >> bad.conf
121 echo "  control-key-file: bad_control.key" >> bad.conf
122 echo "  control-cert-file: bad_control.pem" >> bad.conf
123 echo "$PRE/unbound-control -c bad.conf verbosity 2"
124 $PRE/unbound-control -c bad.conf verbosity 2
125 if test $? -ne 1; then
126         echo "wrong exit value after failure"
127         exit 1
128 fi
129
130 # create a new local zone
131 echo "> test of local zone"
132 echo "$PRE/unbound-control -c ub.conf local_zone example.net static"
133 $PRE/unbound-control -c ub.conf local_zone example.net static
134 if test $? -ne 0; then
135         echo "wrong exit value after success"
136         exit 1
137 fi
138 echo "$PRE/unbound-control -c ub.conf local_data www.example.net A 192.0.2.1"
139 $PRE/unbound-control -c ub.conf local_data www.example.net A 192.0.2.1
140 if test $? -ne 0; then
141         echo "wrong exit value after success"
142         exit 1
143 fi
144
145 # check that www.example.net exists
146 echo "> dig www.example.net."
147 dig @127.0.0.1 -p $UNBOUND_PORT www.example.net. | tee outfile
148 echo "> check answer"
149 if grep "192.0.2.1" outfile; then
150         echo "OK"
151 else
152         echo "> cat logfiles"
153         cat fwd.log 
154         cat unbound.log
155         echo "Not OK"
156         exit 1
157 fi
158
159 # check that mail.example.net has nxdomain
160 echo "> dig mail.example.net."
161 dig @127.0.0.1 -p $UNBOUND_PORT mail.example.net. | tee outfile
162 echo "> check answer"
163 if grep "NXDOMAIN" outfile; then
164         echo "OK"
165 else
166         echo "> cat logfiles"
167         cat fwd.log 
168         cat unbound.log
169         echo "Not OK"
170         exit 1
171 fi
172
173 # remove www.example.net - check it gets nxdomain
174 echo "$PRE/unbound-control -c ub.conf local_data_remove www.example.net"
175 $PRE/unbound-control -c ub.conf local_data_remove www.example.net
176 if test $? -ne 0; then
177         echo "wrong exit value after success"
178         exit 1
179 fi
180 echo "> dig www.example.net."
181 dig @127.0.0.1 -p $UNBOUND_PORT www.example.net. | tee outfile
182 echo "> check answer"
183 if grep "NXDOMAIN" outfile; then
184         echo "OK"
185 else
186         echo "> cat logfiles"
187         cat fwd.log 
188         cat unbound.log
189         echo "Not OK"
190         exit 1
191 fi
192
193 # remove nonexistent name - check bug#287(segfault) does not happen.
194 echo "$PRE/unbound-control -c ub.conf local_data_remove test.example.net"
195 $PRE/unbound-control -c ub.conf local_data_remove test.example.net
196 # if crash then then we get: error: could not SSL_read from unbound-control
197 if test $? -ne 0; then
198         echo "wrong exit value after success"
199         cat unbound.log
200         echo "Not OK"
201         exit 1
202 fi
203
204 # remove example.net - check its gone.
205 echo "$PRE/unbound-control -c ub.conf local_zone_remove example.net"
206 $PRE/unbound-control -c ub.conf local_zone_remove example.net
207 if test $? -ne 0; then
208         echo "wrong exit value after success"
209         exit 1
210 fi
211 echo "> dig www.example.net."
212 dig @127.0.0.1 -p $UNBOUND_PORT www.example.net. | tee outfile
213 echo "> check answer"
214 if grep "SERVFAIL" outfile; then
215         echo "OK"
216 else
217         echo "> cat logfiles"
218         cat fwd.log 
219         cat unbound.log
220         echo "Not OK"
221         exit 1
222 fi
223
224 # dump the cache
225 echo "> test cache dump"
226 # fillup cache
227 echo "dig www.example.com"
228 dig @127.0.0.1 -p $UNBOUND_PORT www.example.com.
229 echo "$PRE/unbound-control -c ub.conf dump_cache"
230 $PRE/unbound-control -c ub.conf dump_cache > tmp.$$
231 if test $? -ne 0; then
232         echo "wrong exit value after success"
233         exit 1
234 fi
235 cat tmp.$$
236 if grep 10.20.30.40 tmp.$$; then
237         echo "OK example.com is in cache dump"
238 else
239         echo "Not OK cache dump"
240         exit 1
241 fi
242
243 # test lookup 
244 echo "$PRE/unbound-control -c ub.conf lookup www.example.com"
245 $PRE/unbound-control -c ub.conf lookup www.example.com
246 if test $? -ne 0; then
247         echo "wrong exit value after success"
248         exit 1
249 fi
250 # answer to lookup is meaningless because of use a forwarder, oh well.
251
252 # load the cache dump.
253 echo "$PRE/unbound-control -c ub.conf load_cache < tmp.$$"
254 $PRE/unbound-control -c ub.conf load_cache < tmp.$$
255 if test $? -ne 0; then
256         echo "wrong exit value after success"
257         exit 1
258 fi
259 echo "> dig www.example.com."
260 dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile
261 echo "> check answer"
262 if grep "10.20.30.40" outfile; then
263         echo "OK"
264 else
265         echo "> cat logfiles"
266         cat fwd.log 
267         cat unbound.log
268         echo "Not OK"
269         exit 1
270 fi
271
272 # load local-zones from file
273 echo "$PRE/unbound-control -c ub.conf local_zones < local_zones"
274 $PRE/unbound-control -c ub.conf local_zones < local_zones
275 if test $? -ne 0; then
276         echo "wrong exit value after success"
277         exit 1
278 fi
279 echo "> dig localzonefromfile."
280 dig @127.0.0.1 -p $UNBOUND_PORT localzonefromfile | tee outfile
281 echo "> check answer"
282 if grep "REFUSED" outfile; then
283         echo "OK"
284 else
285         echo "Not OK"
286         exit 1
287 fi
288
289 # load local-data from file
290 echo "$PRE/unbound-control -c ub.conf local_datas < local_data"
291 $PRE/unbound-control -c ub.conf local_datas < local_data
292 if test $? -ne 0; then
293         echo "wrong exit value after success"
294         exit 1
295 fi
296 echo "> dig localdatafromfile."
297 dig @127.0.0.1 -p $UNBOUND_PORT -t txt localdatafromfile | tee outfile
298 echo "> check answer"
299 if grep "local data from file OK" outfile; then
300         echo "OK"
301 else
302         echo "Not OK"
303         exit 1
304 fi
305
306 # remove local-zone and local-data from file
307 echo "$PRE/unbound-control -c ub.conf local_zones_remove < local_zones_remove"
308 $PRE/unbound-control -c ub.conf local_zones_remove < local_zones_remove
309 if test $? -ne 0; then
310         echo "wrong exit value after success"
311         exit 1
312 fi
313 echo "$PRE/unbound-control -c ub.conf local_datas_remove < local_data_remove"
314 $PRE/unbound-control -c ub.conf local_datas_remove < local_data_remove
315 if test $? -ne 0; then
316         echo "wrong exit value after success"
317         exit 1
318 fi
319 echo "> check zone and data removal list_local_zones"
320 $PRE/unbound-control -c ub.conf list_local_zones | tee outfile
321 if grep "localzonefromfile" outfile; then
322         echo "Not OK"
323         exit 1
324 fi
325 if grep "local data from file OK" outfile; then
326         echo "Not OK"
327         exit 1
328 fi
329 if grep "otherlocalzone" outfile; then
330         echo "OK"
331 else
332         echo "Not OK"
333         exit 1
334 fi
335
336 # flushing
337 echo "$PRE/unbound-control -c ub.conf flush www.example.net"
338 $PRE/unbound-control -c ub.conf flush www.example.net
339 if test $? -ne 0; then
340         echo "wrong exit value after success"
341         exit 1
342 fi
343
344 echo "$PRE/unbound-control -c ub.conf flush_type www.example.net TXT"
345 $PRE/unbound-control -c ub.conf flush_type www.example.net TXT
346 if test $? -ne 0; then
347         echo "wrong exit value after success"
348         exit 1
349 fi
350
351 echo "$PRE/unbound-control -c ub.conf flush_zone example.net"
352 $PRE/unbound-control -c ub.conf flush_zone example.net
353 if test $? -ne 0; then
354         echo "wrong exit value after success"
355         exit 1
356 fi
357
358 # now stop the server
359 echo "$PRE/unbound-control -c ub.conf stop"
360 $PRE/unbound-control -c ub.conf stop
361 if test $? -ne 0; then
362         echo "wrong exit value after success"
363         exit 1
364 fi
365 # see if the server has really exited.
366 TRY_MAX=20
367 for (( try=0 ; try <= $TRY_MAX ; try++ )) ; do
368         if kill -0 $UNBOUND_PID 2>&1 | tee tmp.$$; then
369                 echo "not stopped yet, waiting"
370                 sleep 1
371         else
372                 echo "stopped OK; break"
373                 break;
374         fi
375         if grep "No such process" tmp.$$; then
376                 echo "stopped OK; break"
377                 break;
378         fi
379 done
380 if kill -0 $UNBOUND_PID; then
381         echo "still up!"
382         echo "> cat logfiles"
383         cat fwd.log 
384         cat unbound.log
385         echo "not stopped, failure"
386         exit 1
387 else
388         echo "stopped OK"
389
390         if test -f ublocktrace.0; then
391                 if $PRE/lock-verify ublocktrace.*; then
392                         echo "lock-verify test worked."
393                 else
394                         echo "lock-verify test failed."
395                         cat fwd.log 
396                         cat unbound.log
397                         exit 1
398                 fi
399         fi
400 fi
401
402 echo "> cat logfiles"
403 cat fwd.log 
404 cat unbound.log
405 echo "> OK"
406 exit 0