tests.sh 11.9 KB
Newer Older
1 2
#!/bin/sh
#
3
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Mark Andrews's avatar
Mark Andrews committed
4
#
5 6 7
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 9 10
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
Mark Andrews's avatar
Mark Andrews committed
11

12 13 14 15 16

# WARNING: The test labelled "testing request-ixfr option in view vs zone"
#          is fragile because it depends upon counting instances of records
#          in the log file - need a better approach <sdm> - until then,
#          if you add any tests above that point, you will break the test.
17

18
. ../conf.sh
19

20 21 22 23 24 25
wait_for_serial() (
    $DIG $DIGOPTS "@$1" "$2" SOA > "$4"
    serial=$(awk '$4 == "SOA" { print $7 }' "$4")
    [ "$3" -eq "${serial:--1}" ]
)

Andreas Gustafsson's avatar
Andreas Gustafsson committed
26
status=0
27
n=0
Andreas Gustafsson's avatar
Andreas Gustafsson committed
28

Evan Hunt's avatar
Evan Hunt committed
29 30
DIGOPTS="+tcp +noadd +nosea +nostat +noquest +nocomm +nocmd -p ${PORT}"
RNDCCMD="$RNDC -p ${CONTROLPORT} -c ../common/rndc.conf -s"
31

32 33 34 35 36
sendcmd() {
    send 10.53.0.2 "${EXTRAPORT1}"
}


37 38
n=$((n+1))
echo_i "testing initial AXFR ($n)"
39
ret=0
40

41
sendcmd <<EOF
42 43 44 45
/SOA/
nil.      	300	SOA	ns.nil. root.nil. 1 300 300 604800 300
/AXFR/
nil.      	300	SOA	ns.nil. root.nil. 1 300 300 604800 300
46
/AXFR/
47 48 49 50
nil.      	300	NS	ns.nil.
nil.		300	TXT	"initial AXFR"
a.nil.		60	A	10.0.0.61
b.nil.		60	A	10.0.0.62
51
/AXFR/
52 53 54 55 56 57 58
nil.      	300	SOA	ns.nil. root.nil. 1 300 300 604800 300
EOF

sleep 1

# Initially, ns1 is not authoritative for anything (see setup.sh).
# Now that ans is up and running with the right data, we make it
59
# a secondary for nil.
60 61 62

cat <<EOF >>ns1/named.conf
zone "nil" {
63
	type secondary;
64
	file "myftp.db";
65
	primaries { 10.53.0.2; };
66 67 68
};
EOF

69
rndc_reload ns1 10.53.0.1
70

71
retry_quiet 10 wait_for_serial 10.53.0.1 nil. 1 dig.out.test$n || ret=1
72

73 74 75
$DIG $DIGOPTS @10.53.0.1 nil. TXT | grep 'initial AXFR' >/dev/null || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))
76

77 78
n=$((n+1))
echo_i "testing successful IXFR ($n)"
79
ret=0
80 81 82 83

# We change the IP address of a.nil., and the TXT record at the apex.
# Then we do a SOA-only update.

84
sendcmd <<EOF
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
/SOA/
nil.      	300	SOA	ns.nil. root.nil. 3 300 300 604800 300
/IXFR/
nil.      	300	SOA	ns.nil. root.nil. 3 300 300 604800 300
nil.      	300	SOA	ns.nil. root.nil. 1 300 300 604800 300
a.nil.      	60	A	10.0.0.61
nil.		300	TXT	"initial AXFR"
nil.      	300	SOA	ns.nil. root.nil. 2 300 300 604800 300
nil.		300	TXT	"successful IXFR"
a.nil.      	60	A	10.0.1.61
nil.      	300	SOA	ns.nil. root.nil. 2 300 300 604800 300
nil.      	300	SOA	ns.nil. root.nil. 3 300 300 604800 300
nil.      	300	SOA	ns.nil. root.nil. 3 300 300 604800 300
EOF

sleep 1

102
$RNDCCMD 10.53.0.1 refresh nil | sed 's/^/ns1 /' | cat_i
103 104 105

sleep 2

106 107 108
$DIG $DIGOPTS @10.53.0.1 nil. TXT | grep 'successful IXFR' >/dev/null || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))
109

110 111
n=$((n+1))
echo_i "testing AXFR fallback after IXFR failure ($n)"
112
ret=0
113 114 115

# Provide a broken IXFR response and a working fallback AXFR response

116
sendcmd <<EOF
117 118 119 120 121 122 123 124 125 126 127
/SOA/
nil.      	300	SOA	ns.nil. root.nil. 4 300 300 604800 300
/IXFR/
nil.      	300	SOA	ns.nil. root.nil. 4 300 300 604800 300
nil.      	300	SOA	ns.nil. root.nil. 3 300 300 604800 300
nil.      	300	TXT	"delete-nonexistent-txt-record"
nil.      	300	SOA	ns.nil. root.nil. 4 300 300 604800 300
nil.      	300	TXT	"this-txt-record-would-be-added"
nil.      	300	SOA	ns.nil. root.nil. 4 300 300 604800 300
/AXFR/
nil.      	300	SOA	ns.nil. root.nil. 3 300 300 604800 300
128
/AXFR/
129 130
nil.      	300	NS	ns.nil.
nil.      	300	TXT	"fallback AXFR"
131
/AXFR/
132 133 134 135 136
nil.      	300	SOA	ns.nil. root.nil. 3 300 300 604800 300
EOF

sleep 1

137
$RNDCCMD 10.53.0.1 refresh nil | sed 's/^/ns1 /' | cat_i
138 139 140

sleep 2

141 142 143
$DIG $DIGOPTS @10.53.0.1 nil. TXT | grep 'fallback AXFR' >/dev/null || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))
144

145 146
n=$((n+1))
echo_i "testing ixfr-from-differences option ($n)"
147
# ns3 is primary; ns4 is secondary
148 149 150
$CHECKZONE test. ns3/mytest.db > /dev/null 2>&1
if [ $? -ne 0 ]
then
Evan Hunt's avatar
Evan Hunt committed
151
    echo_i "named-checkzone returned failure on ns3/mytest.db"
152
fi
153 154 155 156

retry_quiet 10 wait_for_serial 10.53.0.4 test. 1 dig.out.test$n || ret=1

nextpart ns4/named.run > /dev/null
157

158
# modify the primary
159
cp ns3/mytest1.db ns3/mytest.db
Evan Hunt's avatar
Evan Hunt committed
160
$RNDCCMD 10.53.0.3 reload | sed 's/^/ns3 /' | cat_i
161

162
# wait for primary to reload
163 164
retry_quiet 10 wait_for_serial 10.53.0.3 test. 2 dig.out.test$n || ret=1

165
# wait for secondary to reload
166 167 168 169 170 171
tret=0
retry_quiet 5 wait_for_serial 10.53.0.4 test. 2 dig.out.test$n || tret=1
if [ $tret -eq 1 ]; then
    # re-noitfy after 5 seconds, then wait another 10
    $RNDCCMD 10.53.0.3 notify test | set 's/^/ns3 /' | cat_i
    retry_quiet 10 wait_for_serial 10.53.0.4 test. 2 dig.out.test$n || ret=1
172 173
fi

174 175 176 177
wait_for_log 10 'got incremental' ns4/named.run || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))

178
n=$((n+1))
179 180
echo_i "testing 'request-ixfr no' option inheritance from view ($n)"
ret=0
181 182 183 184 185 186
# There's a view with 2 zones. In the view, "request-ixfr yes"
# but in the zone "sub.test", request-ixfr no"
# we want to make sure that a change to sub.test results in AXFR, while
# changes to test. result in IXFR

cp ns3/subtest1.db ns3/subtest.db # change to sub.test zone, should be AXFR
187
nextpart ns4/named.run > /dev/null
Evan Hunt's avatar
Evan Hunt committed
188
$RNDCCMD 10.53.0.3 reload | sed 's/^/ns3 /' | cat_i
189

190
# wait for primary to reload
191
retry_quiet 10 wait_for_serial 10.53.0.3 sub.test. 3 dig.out.test$n || ret=1
192

193
# wait for secondary to reload
194 195 196 197 198 199
tret=0
retry_quiet 5 wait_for_serial 10.53.0.4 sub.test. 3 dig.out.test$n || tret=1
if [ $tret -eq 1 ]; then
    # re-noitfy after 5 seconds, then wait another 10
    $RNDCCMD 10.53.0.3 notify sub.test | set 's/^/ns3 /' | cat_i
    retry_quiet 10 wait_for_serial 10.53.0.4 sub.test. 3 dig.out.test$n || ret=1
200 201
fi

202 203 204 205 206 207 208
wait_for_log 10 'got nonincremental response' ns4/named.run || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))

n=$((n+1))
echo_i "testing 'request-ixfr yes' option inheritance from view ($n)"
ret=0
209
cp ns3/mytest2.db ns3/mytest.db # change to test zone, should be IXFR
210
nextpart ns4/named.run > /dev/null
Evan Hunt's avatar
Evan Hunt committed
211
$RNDCCMD 10.53.0.3 reload | sed 's/^/ns3 /' | cat_i
212

213
# wait for primary to reload
214
retry_quiet 10 wait_for_serial 10.53.0.3 test. 3 dig.out.test$n || ret=1
215

216
# wait for secondary to reload
217 218 219 220 221 222
tret=0
retry_quiet 5 wait_for_serial 10.53.0.4 test. 3 dig.out.test$n || tret=1
if [ $tret -eq 1 ]; then
    # re-noitfy after 5 seconds, then wait another 10
    $RNDCCMD 10.53.0.3 notify test | set 's/^/ns3 /' | cat_i
    retry_quiet 10 wait_for_serial 10.53.0.4 test. 3 dig.out.test$n || ret=1
223 224
fi

225 226 227 228
wait_for_log 10 'got incremental response' ns4/named.run || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))

229
n=$((n+1))
230
ret=0
231
echo_i "testing DiG's handling of a multi message AXFR style IXFR response ($n)"
232 233 234
(
(sleep 10 && kill $$) 2>/dev/null &
sub=$!
235
$DIG -p ${PORT} ixfr=0 large @10.53.0.3 > dig.out.test$n
236 237
kill $sub
)
238
lines=`grep hostmaster.large dig.out.test$n | wc -l`
239
test ${lines:-0} -eq 2 || ret=1
240
messages=`sed -n 's/^;;.*messages \([0-9]*\),.*/\1/p' dig.out.test$n`
241 242 243
test ${messages:-0} -gt 1 || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))
244

245 246
n=$((n+1))
echo_i "test 'dig +notcp ixfr=<value>' vs 'dig ixfr=<value> +notcp' vs 'dig ixfr=<value>' ($n)"
247 248
ret=0
# Should be "switch to TCP" response
249 250 251 252
$DIG $DIGOPTS +notcp ixfr=1 test @10.53.0.4 > dig.out1.test$n || ret=1
$DIG $DIGOPTS ixfr=1 +notcp test @10.53.0.4 > dig.out2.test$n || ret=1
digcomp dig.out1.test$n dig.out2.test$n || ret=1
awk '$4 == "SOA" { soacnt++} END {if (soacnt == 1) exit(0); else exit(1);}' dig.out1.test$n || ret=1
253
awk '$4 == "SOA" { if ($7 == 3) exit(0); else exit(1);}' dig.out1.test$n || ret=1
254
# Should be incremental transfer.
255 256
$DIG $DIGOPTS ixfr=1 test @10.53.0.4 > dig.out3.test$n || ret=1
awk '$4 == "SOA" { soacnt++} END { if (soacnt == 6) exit(0); else exit(1);}' dig.out3.test$n || ret=1
257 258
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))
259

260
# make sure ns5 has transfered the zone
261
# wait for secondary to reload
262 263 264 265 266 267 268
tret=0
retry_quiet 5 wait_for_serial 10.53.0.5 test. 4 dig.out.test$n || tret=1
if [ $tret -eq 1 ]; then
    # re-noitfy after 5 seconds, then wait another 10
    $RNDCCMD 10.53.0.3 notify test | set 's/^/ns3 /' | cat_i
    retry_quiet 10 wait_for_serial 10.53.0.5 test. 3 dig.out.test$n || ret=1
fi
269 270

n=$((n+1))
271
echo_i "test 'provide-ixfr no;' (serial < current) ($n)"
272
ret=0
273
nextpart ns5/named.run > /dev/null
274 275 276 277 278 279
# Should be "AXFR style" response
$DIG $DIGOPTS ixfr=1 test @10.53.0.5 > dig.out1.test$n || ret=1
# Should be "switch to TCP" response
$DIG $DIGOPTS ixfr=1 +notcp test @10.53.0.5 > dig.out2.test$n || ret=1
awk '$4 == "SOA" { soacnt++} END {if (soacnt == 2) exit(0); else exit(1);}' dig.out1.test$n || ret=1
awk '$4 == "SOA" { soacnt++} END {if (soacnt == 1) exit(0); else exit(1);}' dig.out2.test$n || ret=1
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
msg="IXFR delta response disabled due to 'provide-ixfr no;' being set"
nextpart ns5/named.run | grep "$msg" > /dev/null || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))

n=$((n+1))
echo_i "test 'provide-ixfr no;' (serial = current) ($n)"
ret=0
# Should be "AXFR style" response
$DIG $DIGOPTS ixfr=3 test @10.53.0.5 > dig.out1.test$n || ret=1
# Should be "switch to TCP" response
$DIG $DIGOPTS ixfr=3 +notcp test @10.53.0.5 > dig.out2.test$n || ret=1
awk '$4 == "SOA" { soacnt++} END {if (soacnt == 1) exit(0); else exit(1);}' dig.out1.test$n || ret=1
awk '$4 == "SOA" { soacnt++} END {if (soacnt == 1) exit(0); else exit(1);}' dig.out2.test$n || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))

n=$((n+1))
echo_i "test 'provide-ixfr no;' (serial > current) ($n)"
ret=0
# Should be "AXFR style" response
$DIG $DIGOPTS ixfr=4 test @10.53.0.5 > dig.out1.test$n || ret=1
# Should be "switch to TCP" response
$DIG $DIGOPTS ixfr=4 +notcp test @10.53.0.5 > dig.out2.test$n || ret=1
awk '$4 == "SOA" { soacnt++} END {if (soacnt == 1) exit(0); else exit(1);}' dig.out1.test$n || ret=1
awk '$4 == "SOA" { soacnt++} END {if (soacnt == 1) exit(0); else exit(1);}' dig.out2.test$n || ret=1
306 307
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))
308 309 310

n=$((n+1))
echo_i "checking whether dig calculates IXFR statistics correctly ($n)"
311
ret=0
312 313
$DIG $DIGOPTS +noedns +stat -b 10.53.0.4 @10.53.0.4 test. ixfr=2 > dig.out1.test$n
get_dig_xfer_stats dig.out1.test$n > stats.dig
314
diff ixfr-stats.good stats.dig > /dev/null || ret=1
315
if [ $ret != 0 ]; then echo_i "failed"; fi
316
status=$((status+ret))
317 318 319 320

# Note: in the next two tests, we use ns4 logs for checking both incoming and
# outgoing transfer statistics as ns4 is both a secondary server (for ns3) and a
# primary server (for dig queries from the previous test) for "test".
321 322 323 324 325 326 327

_wait_for_stats () {
    get_named_xfer_stats ns4/named.run "$1" test "$2" > "$3"
    diff ixfr-stats.good "$3" > /dev/null || return 1
    return 0
}

328 329
n=$((n+1))
echo_i "checking whether named calculates incoming IXFR statistics correctly ($n)"
330
ret=0
331
retry_quiet 10 _wait_for_stats 10.53.0.3 "Transfer completed" stats.incoming
332
if [ $ret != 0 ]; then echo_i "failed"; fi
333
status=$((status+ret))
334

335 336
n=$((n+1))
echo_i "checking whether named calculates outgoing IXFR statistics correctly ($n)"
337 338 339 340 341 342 343 344 345 346 347 348
retry_quiet 10 _wait_for_stats 10.53.0.4 "IXFR ended" stats.outgoing
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status+ret))

n=$((n+1))
ret=0
echo_i "testing fallback to AXFR when max-ixfr-ratio is exceeded ($n)"
nextpart ns4/named.run > /dev/null

cp ns3/mytest3.db ns3/mytest.db # change to test zone, too big for IXFR
$RNDCCMD 10.53.0.3 reload | sed 's/^/ns3 /' | cat_i

349
# wait for secondary to reload
350 351 352 353 354 355 356 357 358
tret=0
retry_quiet 5 wait_for_serial 10.53.0.4 test. 4 dig.out.test$n || tret=1
if [ $tret -eq 1 ]; then
    # re-noitfy after 5 seconds, then wait another 10
    $RNDCCMD 10.53.0.3 notify test | set 's/^/ns3 /' | cat_i
    retry_quiet 10 wait_for_serial 10.53.0.4 test. 4 dig.out.test$n || ret=1
fi

wait_for_log 10 'got nonincremental response' ns4/named.run || ret=1
359
if [ $ret != 0 ]; then echo_i "failed"; fi
360
status=$((status+ret))
361

Evan Hunt's avatar
Evan Hunt committed
362
echo_i "exit status: $status"
363
[ $status -eq 0 ] || exit 1