1#!/bin/sh
2#
3# Copyright (C) 2011-2014  Internet Systems Consortium, Inc. ("ISC")
4#
5# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15# PERFORMANCE OF THIS SOFTWARE.
16
17# Id: tests.sh,v 1.4.154.1 2012/01/04 20:05:03 smann Exp
18
19SYSTEMTESTTOP=..
20. $SYSTEMTESTTOP/conf.sh
21
22DIGOPTS="+tcp +noadd +nosea +nostat +noquest +nocomm +nocmd"
23DIGCMD="$DIG $DIGOPTS @10.53.0.2 -p 5300"
24RNDCCMD="$RNDC -s 10.53.0.2 -p 9953 -c ../common/rndc.conf"
25
26status=0
27
28echo "I:preparing"
29ret=0
30$NSUPDATE -p 5300 -k ns2/session.key > /dev/null 2>&1 <<END || ret=1
31server 10.53.0.2
32zone nil.
33update add text1.nil. 600 IN TXT "addition 1"
34send
35zone other.
36update add text1.other. 600 IN TXT "addition 1"
37send
38END
39[ -s ns2/nil.db.jnl ] || ret=1
40[ -s ns2/other.db.jnl ] || ret=1
41if [ $ret != 0 ]; then echo "I:failed"; fi
42status=`expr $status + $ret`
43
44echo "I:rndc freeze"
45$RNDCCMD freeze | sed 's/^/I:ns2 /'
46
47echo "I:checking zone was dumped"
48ret=0
49grep "addition 1" ns2/nil.db > /dev/null 2>&1 || ret=1
50if [ $ret != 0 ]; then echo "I:failed"; fi
51status=`expr $status + $ret`
52
53echo "I:checking journal file is still present"
54ret=0
55[ -s ns2/nil.db.jnl ] || ret=1
56if [ $ret != 0 ]; then echo "I:failed"; fi
57status=`expr $status + $ret`
58
59echo "I:checking zone not writable"
60ret=0
61$NSUPDATE -p 5300 -k ns2/session.key > /dev/null 2>&1 <<END && ret=1
62server 10.53.0.2
63zone nil.
64update add text2.nil. 600 IN TXT "addition 2"
65send
66END
67
68$DIGCMD text2.nil. TXT | grep 'addition 2' >/dev/null && ret=1
69if [ $ret != 0 ]; then echo "I:failed"; fi
70status=`expr $status + $ret`
71
72echo "I:rndc thaw"
73$RNDCCMD thaw | sed 's/^/I:ns2 /'
74
75echo "I:checking zone now writable"
76ret=0
77$NSUPDATE -p 5300 -k ns2/session.key > /dev/null 2>&1 <<END || ret=1
78server 10.53.0.2
79zone nil.
80update add text3.nil. 600 IN TXT "addition 3"
81send
82END
83$DIGCMD text3.nil. TXT | grep 'addition 3' >/dev/null || ret=1
84if [ $ret != 0 ]; then echo "I:failed"; fi
85status=`expr $status + $ret`
86
87echo "I:rndc sync"
88ret=0
89$RNDCCMD sync nil | sed 's/^/I:ns2 /'
90
91echo "I:checking zone was dumped"
92ret=0
93grep "addition 3" ns2/nil.db > /dev/null 2>&1 || ret=1
94if [ $ret != 0 ]; then echo "I:failed"; fi
95status=`expr $status + $ret`
96
97echo "I:checking journal file is still present"
98ret=0
99[ -s ns2/nil.db.jnl ] || ret=1
100if [ $ret != 0 ]; then echo "I:failed"; fi
101status=`expr $status + $ret`
102
103echo "I:checking zone is still writable"
104ret=0
105$NSUPDATE -p 5300 -k ns2/session.key > /dev/null 2>&1 <<END || ret=1
106server 10.53.0.2
107zone nil.
108update add text4.nil. 600 IN TXT "addition 4"
109send
110END
111
112$DIGCMD text4.nil. TXT | grep 'addition 4' >/dev/null || ret=1
113if [ $ret != 0 ]; then echo "I:failed"; fi
114status=`expr $status + $ret`
115
116echo "I:rndc sync -clean"
117ret=0
118$RNDCCMD sync -clean nil | sed 's/^/I:ns2 /'
119
120echo "I:checking zone was dumped"
121ret=0
122grep "addition 4" ns2/nil.db > /dev/null 2>&1 || ret=1
123if [ $ret != 0 ]; then echo "I:failed"; fi
124status=`expr $status + $ret`
125
126echo "I:checking journal file is deleted"
127ret=0
128[ -s ns2/nil.db.jnl ] && ret=1
129if [ $ret != 0 ]; then echo "I:failed"; fi
130status=`expr $status + $ret`
131
132echo "I:checking zone is still writable"
133ret=0
134$NSUPDATE -p 5300 -k ns2/session.key > /dev/null 2>&1 <<END || ret=1
135server 10.53.0.2
136zone nil.
137update add text5.nil. 600 IN TXT "addition 5"
138send
139END
140
141$DIGCMD text4.nil. TXT | grep 'addition 4' >/dev/null || ret=1
142if [ $ret != 0 ]; then echo "I:failed"; fi
143status=`expr $status + $ret`
144
145echo "I:checking other journal files not removed"
146ret=0
147[ -s ns2/other.db.jnl ] || ret=1
148if [ $ret != 0 ]; then echo "I:failed"; fi
149status=`expr $status + $ret`
150
151echo "I:cleaning all zones"
152$RNDCCMD sync -clean | sed 's/^/I:ns2 /'
153
154echo "I:checking all journals removed"
155ret=0
156[ -s ns2/nil.db.jnl ] && ret=1
157[ -s ns2/other.db.jnl ] && ret=1
158if [ $ret != 0 ]; then echo "I:failed"; fi
159status=`expr $status + $ret`
160
161echo "I:checking that freezing static zones is not allowed"
162ret=0
163$RNDCCMD freeze static 2>&1 | grep 'not dynamic' > /dev/null || ret=1
164if [ $ret != 0 ]; then echo "I:failed"; fi
165status=`expr $status + $ret`
166
167echo "I:checking that journal is removed when serial is changed before thaw"
168ret=0
169sleep 1
170$NSUPDATE -p 5300 -k ns2/session.key > /dev/null 2>&1 <<END || ret=1
171server 10.53.0.2
172zone other.
173update add text6.other. 600 IN TXT "addition 6"
174send
175END
176[ -s ns2/other.db.jnl ] || ret=1
177$RNDCCMD freeze other 2>&1 | sed 's/^/I:ns2 /'
178serial=`awk '$3 == "serial" {print $1}' ns2/other.db`
179newserial=`expr $serial + 1`
180sed s/$serial/$newserial/ ns2/other.db > ns2/other.db.new
181echo 'frozen TXT "frozen addition"' >> ns2/other.db.new
182mv -f ns2/other.db.new ns2/other.db
183$RNDCCMD thaw 2>&1 | sed 's/^/I:ns2 /'
184sleep 1
185[ -f ns2/other.db.jnl ] && ret=1
186$NSUPDATE -p 5300 -k ns2/session.key > /dev/null 2>&1 <<END || ret=1
187server 10.53.0.2
188zone other.
189update add text7.other. 600 IN TXT "addition 7"
190send
191END
192$DIGCMD text6.other. TXT | grep 'addition 6' >/dev/null || ret=1
193$DIGCMD text7.other. TXT | grep 'addition 7' >/dev/null || ret=1
194$DIGCMD frozen.other. TXT | grep 'frozen addition' >/dev/null || ret=1
195if [ $ret != 0 ]; then echo "I:failed"; fi
196status=`expr $status + $ret`
197
198echo "I:checking that journal is kept when ixfr-from-differences is in use"
199ret=0
200$NSUPDATE -p 5300 -k ns2/session.key > /dev/null 2>&1 <<END || ret=1
201server 10.53.0.2
202zone nil.
203update add text6.nil. 600 IN TXT "addition 6"
204send
205END
206[ -s ns2/nil.db.jnl ] || ret=1
207$RNDCCMD freeze nil 2>&1 | sed 's/^/I:ns2 /'
208serial=`awk '$3 == "serial" {print $1}' ns2/nil.db`
209newserial=`expr $serial + 1`
210sed s/$serial/$newserial/ ns2/nil.db > ns2/nil.db.new
211echo 'frozen TXT "frozen addition"' >> ns2/nil.db.new
212mv -f ns2/nil.db.new ns2/nil.db
213$RNDCCMD thaw 2>&1 | sed 's/^/I:ns2 /'
214sleep 1
215[ -s ns2/nil.db.jnl ] || ret=1
216$NSUPDATE -p 5300 -k ns2/session.key > /dev/null 2>&1 <<END || ret=1
217server 10.53.0.2
218zone nil.
219update add text7.nil. 600 IN TXT "addition 7"
220send
221END
222$DIGCMD text6.nil. TXT | grep 'addition 6' >/dev/null || ret=1
223$DIGCMD text7.nil. TXT | grep 'addition 7' >/dev/null || ret=1
224$DIGCMD frozen.nil. TXT | grep 'frozen addition' >/dev/null || ret=1
225if [ $ret != 0 ]; then echo "I:failed"; fi
226status=`expr $status + $ret`
227
228# temp test
229echo "I:dumping stats"
230$RNDCCMD stats
231echo "I: verifying adb records in named.stats"
232grep "ADB stats" ns2/named.stats > /dev/null || ret=1
233if [ $ret != 0 ]; then echo "I:failed"; fi
234status=`expr $status + $ret`
235
236echo "I:test using second key"
237ret=0
238$RNDC -s 10.53.0.2 -p 9953 -c ns2/secondkey.conf status > /dev/null || ret=1
239if [ $ret != 0 ]; then echo "I:failed"; fi
240status=`expr $status + $ret`
241
242echo "I:test 'rndc dumpdb' on a empty cache"
243ret=0
244$RNDC -s 10.53.0.3 -p 9953 -c ../common/rndc.conf dumpdb > /dev/null || ret=1
245for i in 1 2 3 4 5 6 7 8 9
246do
247	tmp=0
248	grep "Dump complete" ns3/named_dump.db > /dev/null || tmp=1
249	[ $tmp -eq 0 ] && break
250	sleep 1
251done
252[ $tmp -eq 1 ] && ret=1
253if [ $ret != 0 ]; then echo "I:failed"; fi
254status=`expr $status + $ret`
255
256echo "I:test 'rndc reload' on a zone with include files"
257ret=0
258grep "incl/IN: skipping load" ns2/named.run > /dev/null && ret=1
259loads=`grep "incl/IN: starting load" ns2/named.run | wc -l`
260[ "$loads" -eq 1 ] || ret=1
261$RNDC -s 10.53.0.2 -p 9953 -c ../common/rndc.conf reload > /dev/null || ret=1
262for i in 1 2 3 4 5 6 7 8 9
263do
264    tmp=0
265    grep "incl/IN: skipping load" ns2/named.run > /dev/null || tmp=1
266    [ $tmp -eq 0 ] && break
267    sleep 1
268done
269[ $tmp -eq 1 ] && ret=1
270touch ns2/static.db
271$RNDC -s 10.53.0.2 -p 9953 -c ../common/rndc.conf reload > /dev/null || ret=1
272for i in 1 2 3 4 5 6 7 8 9
273do
274    tmp=0
275    loads=`grep "incl/IN: starting load" ns2/named.run | wc -l`
276    [ "$loads" -eq 2 ] || tmp=1
277    [ $tmp -eq 0 ] && break
278    sleep 1
279done
280[ $tmp -eq 1 ] && ret=1
281if [ $ret != 0 ]; then echo "I:failed"; fi
282status=`expr $status + $ret`
283
284echo "I:testing rndc with hmac-md5"
285ret=0
286$RNDC -s 10.53.0.4 -p 9951 -c ns4/key1.conf status > /dev/null 2>&1 || ret=1
287for i in 2 3 4 5 6
288do
289        $RNDC -s 10.53.0.4 -p 9951 -c ns4/key${i}.conf status > /dev/null 2>&1 && ret=1
290done
291if [ $ret != 0 ]; then echo "I:failed"; fi
292status=`expr $status + $ret`
293
294echo "I:testing rndc with hmac-sha1"
295ret=0
296$RNDC -s 10.53.0.4 -p 9952 -c ns4/key2.conf status > /dev/null 2>&1 || ret=1
297for i in 1 3 4 5 6
298do
299        $RNDC -s 10.53.0.4 -p 9952 -c ns4/key${i}.conf status > /dev/null 2>&1 && ret=1
300done
301if [ $ret != 0 ]; then echo "I:failed"; fi
302status=`expr $status + $ret`
303
304echo "I:testing rndc with hmac-sha224"
305ret=0
306$RNDC -s 10.53.0.4 -p 9953 -c ns4/key3.conf status > /dev/null 2>&1 || ret=1
307for i in 1 2 4 5 6
308do
309        $RNDC -s 10.53.0.4 -p 9953 -c ns4/key${i}.conf status > /dev/null 2>&1 && ret=1
310done
311if [ $ret != 0 ]; then echo "I:failed"; fi
312status=`expr $status + $ret`
313
314echo "I:testing rndc with hmac-sha256"
315ret=0
316$RNDC -s 10.53.0.4 -p 9954 -c ns4/key4.conf status > /dev/null 2>&1 || ret=1
317for i in 1 2 3 5 6
318do
319        $RNDC -s 10.53.0.4 -p 9954 -c ns4/key${i}.conf status > /dev/null 2>&1 && ret=1
320done
321if [ $ret != 0 ]; then echo "I:failed"; fi
322status=`expr $status + $ret`
323
324echo "I:testing rndc with hmac-sha384"
325ret=0
326$RNDC -s 10.53.0.4 -p 9955 -c ns4/key5.conf status > /dev/null 2>&1 || ret=1
327for i in 1 2 3 4 6
328do
329        $RNDC -s 10.53.0.4 -p 9955 -c ns4/key${i}.conf status > /dev/null 2>&1 && ret=1
330done
331if [ $ret != 0 ]; then echo "I:failed"; fi
332status=`expr $status + $ret`
333
334echo "I:testing rndc with hmac-sha512"
335ret=0
336$RNDC -s 10.53.0.4 -p 9956 -c ns4/key6.conf status > /dev/null 2>&1 || ret=1
337for i in 1 2 3 4 5
338do
339        $RNDC -s 10.53.0.4 -p 9956 -c ns4/key${i}.conf status > /dev/null 2>&1 2>&1 && ret=1
340done
341if [ $ret != 0 ]; then echo "I:failed"; fi
342status=`expr $status + $ret`
343
344echo "I:testing rndc with null command"
345ret=0
346$RNDC -s 10.53.0.4 -p 9956 -c ns4/key6.conf null || ret=1
347if [ $ret != 0 ]; then echo "I:failed"; fi
348status=`expr $status + $ret`
349
350echo "I:testing rndc with unknown control channel command"
351ret=0
352$RNDC -s 10.53.0.4 -p 9956 -c ns4/key6.conf obviouslynotacommand >/dev/null 2>&1 && ret=1
353# rndc: 'obviouslynotacommand' failed: unknown command
354if [ $ret != 0 ]; then echo "I:failed"; fi
355status=`expr $status + $ret`
356
357echo "I:testing rndc with querylog command"
358ret=0
359# first enable it with querylog on option
360$RNDC -s 10.53.0.4 -p 9956 -c ns4/key6.conf querylog on >/dev/null 2>&1 || ret=1
361# query for builtin and check if query was logged
362$DIG @10.53.0.4 -p 5300 -c ch -t txt foo12345.bind > /dev/null || ret 1
363grep "query logging is now on" ns4/named.run > /dev/null || ret=1
364grep "query: foo12345.bind CH TXT" ns4/named.run > /dev/null || ret=1
365# toggle query logging and check again
366$RNDC -s 10.53.0.4 -p 9956 -c ns4/key6.conf querylog > /dev/null 2>&1 || ret=1
367# query for another builtin zone and check if query was logged
368$DIG @10.53.0.4 -p 5300 -c ch -t txt foo9876.bind > /dev/null || ret 1
369grep "query logging is now off" ns4/named.run > /dev/null || ret=1
370grep "query: foo9876.bind CH TXT" ns4/named.run > /dev/null && ret=1
371if [ $ret != 0 ]; then echo "I:failed"; fi
372status=`expr $status + $ret`
373
374echo "I:exit status: $status"
375exit $status
376