1#!/bin/sh 2# 3# Copyright (C) Internet Systems Consortium, Inc. ("ISC") 4# 5# This Source Code Form is subject to the terms of the Mozilla Public 6# License, v. 2.0. If a copy of the MPL was not distributed with this 7# file, You can obtain one at http://mozilla.org/MPL/2.0/. 8# 9# See the COPYRIGHT file distributed with this work for additional 10# information regarding copyright ownership. 11 12SYSTEMTESTTOP=.. 13. $SYSTEMTESTTOP/conf.sh 14THISDIR=`pwd` 15CONFDIR="ns1" 16 17PLAINCONF="${THISDIR}/${CONFDIR}/named.plainconf" 18PLAINFILE="named_log" 19DIRCONF="${THISDIR}/${CONFDIR}/named.dirconf" 20DIRFILE="named_dir" 21PIPECONF="${THISDIR}/${CONFDIR}/named.pipeconf" 22PIPEFILE="named_pipe" 23SYMCONF="${THISDIR}/${CONFDIR}/named.symconf" 24SYMFILE="named_sym" 25VERSCONF="${THISDIR}/${CONFDIR}/named.versconf" 26VERSFILE="named_vers" 27TSCONF="${THISDIR}/${CONFDIR}/named.tsconf" 28TSFILE="named_ts" 29UNLIMITEDCONF="${THISDIR}/${CONFDIR}/named.unlimited" 30UNLIMITEDFILE="named_unlimited" 31ISOCONF="${THISDIR}/${CONFDIR}/named.iso8601" 32ISOFILE="named_iso8601" 33ISOCONFUTC="${THISDIR}/${CONFDIR}/named.iso8601-utc" 34ISOUTCFILE="named_iso8601_utc" 35DLFILE="named_deflog" 36 37PIDFILE="${THISDIR}/${CONFDIR}/named.pid" 38myRNDC="$RNDC -c ${THISDIR}/${CONFDIR}/rndc.conf" 39myNAMED="$NAMED -c ${THISDIR}/${CONFDIR}/named.conf -m record,size,mctx -T nosyslog -d 99 -D logfileconfig-ns1 -X named.lock -U 4" 40 41# Test given condition. If true, test again after a second. Used for testing 42# filesystem-dependent conditions in order to prevent false negatives caused by 43# directory contents not being synchronized immediately after rename() returns. 44test_with_retry() { 45 if test "$@"; then 46 sleep 1 47 if test "$@"; then 48 return 0 49 fi 50 fi 51 return 1 52} 53 54waitforpidfile() { 55 for _w in 1 2 3 4 5 6 7 8 9 10 56 do 57 test -f $PIDFILE && break 58 sleep 1 59 done 60} 61 62status=0 63n=0 64 65cd $CONFDIR 66export SYSTEMTESTTOP=../.. 67 68echo_i "testing log file validity (named -g + only plain files allowed)" 69 70n=`expr $n + 1` 71echo_i "testing plain file (named -g) ($n)" 72# First run with a known good config. 73echo > $PLAINFILE 74copy_setports $PLAINCONF named.conf 75$myRNDC reconfig > rndc.out.test$n 2>&1 76grep "reloading configuration failed" named.run > /dev/null 2>&1 77if [ $? -ne 0 ] 78then 79 echo_i "testing plain file succeeded" 80else 81 echo_i "testing plain file failed (unexpected)" 82 echo_i "exit status: 1" 83 exit 1 84fi 85 86# Now try directory, expect failure 87n=`expr $n + 1` 88echo_i "testing directory as log file (named -g) ($n)" 89echo > named.run 90rm -rf $DIRFILE 91mkdir -p $DIRFILE >/dev/null 2>&1 92if [ $? -eq 0 ] 93then 94 copy_setports $DIRCONF named.conf 95 echo > named.run 96 $myRNDC reconfig > rndc.out.test$n 2>&1 97 grep "checking logging configuration failed: invalid file" named.run > /dev/null 2>&1 98 if [ $? -ne 0 ] 99 then 100 echo_i "testing directory as file succeeded (UNEXPECTED)" 101 echo_i "exit status: 1" 102 exit 1 103 else 104 echo_i "testing directory as log file failed (expected)" 105 fi 106else 107 echo_i "skipping directory test (unable to create directory)" 108fi 109 110# Now try pipe file, expect failure 111n=`expr $n + 1` 112echo_i "testing pipe file as log file (named -g) ($n)" 113echo > named.run 114rm -f $PIPEFILE 115mkfifo $PIPEFILE >/dev/null 2>&1 116if [ $? -eq 0 ] 117then 118 copy_setports $PIPECONF named.conf 119 echo > named.run 120 $myRNDC reconfig > rndc.out.test$n 2>&1 121 grep "checking logging configuration failed: invalid file" named.run > /dev/null 2>&1 122 if [ $? -ne 0 ] 123 then 124 echo_i "testing pipe file as log file succeeded (UNEXPECTED)" 125 echo_i "exit status: 1" 126 exit 1 127 else 128 echo_i "testing pipe file as log file failed (expected)" 129 fi 130else 131 echo_i "skipping pipe test (unable to create pipe)" 132fi 133 134# Now try symlink file to plain file, expect success 135n=`expr $n + 1` 136echo_i "testing symlink to plain file as log file (named -g) ($n)" 137# Assume success 138echo > named.run 139echo > $PLAINFILE 140rm -f $SYMFILE $SYMFILE 141ln -s $PLAINFILE $SYMFILE >/dev/null 2>&1 142if [ $? -eq 0 ] 143then 144 copy_setports $SYMCONF named.conf 145 $myRNDC reconfig > rndc.out.test$n 2>&1 146 echo > named.run 147 grep "reloading configuration failed" named.run > /dev/null 2>&1 148 if [ $? -ne 0 ] 149 then 150 echo_i "testing symlink to plain file succeeded" 151 else 152 echo_i "testing symlink to plain file failed (unexpected)" 153 echo_i "exit status: 1" 154 exit 1 155 fi 156else 157 echo_i "skipping symlink test (unable to create symlink)" 158fi 159# Stop the server and run through a series of tests with various config 160# files while controlling the stop/start of the server. 161# Have to stop the stock server because it uses "-g" 162# 163$PERL ../../stop.pl logfileconfig ns1 164 165$myNAMED > /dev/null 2>&1 166 167if [ $? -ne 0 ] 168then 169 echo_i "failed to start $myNAMED" 170 echo_i "exit status: $status" 171 exit $status 172fi 173 174status=0 175 176echo_i "testing log file validity (only plain files allowed)" 177 178n=`expr $n + 1` 179echo_i "testing plain file (named -g) ($n)" 180# First run with a known good config. 181echo > $PLAINFILE 182copy_setports $PLAINCONF named.conf 183$myRNDC reconfig > rndc.out.test$n 2>&1 184grep "reloading configuration failed" named.run > /dev/null 2>&1 185if [ $? -ne 0 ] 186then 187 echo_i "testing plain file succeeded" 188else 189 echo_i "testing plain file failed (unexpected)" 190 echo_i "exit status: 1" 191 exit 1 192fi 193 194# Now try directory, expect failure 195n=`expr $n + 1` 196echo_i "testing directory as log file ($n)" 197echo > named.run 198rm -rf $DIRFILE 199mkdir -p $DIRFILE >/dev/null 2>&1 200if [ $? -eq 0 ] 201then 202 copy_setports $DIRCONF named.conf 203 echo > named.run 204 $myRNDC reconfig > rndc.out.test$n 2>&1 205 grep "configuring logging: invalid file" named.run > /dev/null 2>&1 206 if [ $? -ne 0 ] 207 then 208 echo_i "testing directory as file succeeded (UNEXPECTED)" 209 echo_i "exit status: 1" 210 exit 1 211 else 212 echo_i "testing directory as log file failed (expected)" 213 fi 214else 215 echo_i "skipping directory test (unable to create directory)" 216fi 217 218# Now try pipe file, expect failure 219n=`expr $n + 1` 220echo_i "testing pipe file as log file ($n)" 221echo > named.run 222rm -f $PIPEFILE 223mkfifo $PIPEFILE >/dev/null 2>&1 224if [ $? -eq 0 ] 225then 226 copy_setports $PIPECONF named.conf 227 echo > named.run 228 $myRNDC reconfig > rndc.out.test$n 2>&1 229 grep "configuring logging: invalid file" named.run > /dev/null 2>&1 230 if [ $? -ne 0 ] 231 then 232 echo_i "testing pipe file as log file succeeded (UNEXPECTED)" 233 echo_i "exit status: 1" 234 exit 1 235 else 236 echo_i "testing pipe file as log file failed (expected)" 237 fi 238else 239 echo_i "skipping pipe test (unable to create pipe)" 240fi 241 242# Now try symlink file to plain file, expect success 243n=`expr $n + 1` 244echo_i "testing symlink to plain file as log file ($n)" 245# Assume success 246status=0 247echo > named.run 248echo > $PLAINFILE 249rm -f $SYMFILE 250ln -s $PLAINFILE $SYMFILE >/dev/null 2>&1 251if [ $? -eq 0 ] 252then 253 copy_setports $SYMCONF named.conf 254 $myRNDC reconfig > rndc.out.test$n 2>&1 255 echo > named.run 256 grep "reloading configuration failed" named.run > /dev/null 2>&1 257 if [ $? -ne 0 ] 258 then 259 echo_i "testing symlink to plain file succeeded" 260 else 261 echo_i "testing symlink to plain file failed (unexpected)" 262 echo_i "exit status: 1" 263 exit 1 264 fi 265else 266 echo_i "skipping symlink test (unable to create symlink)" 267fi 268 269n=`expr $n + 1` 270echo_i "testing default logfile using named -L file ($n)" 271# Now stop the server again and test the -L option 272rm -f $DLFILE 273$PERL ../../stop.pl logfileconfig ns1 274if ! test -f $PIDFILE; then 275 copy_setports $PLAINCONF named.conf 276 $myNAMED -L $DLFILE > /dev/null 2>&1 277 if [ $? -ne 0 ]; then 278 echo_i "failed to start $myNAMED" 279 echo_i "exit status: $status" 280 exit $status 281 fi 282 283 waitforpidfile 284 285 sleep 1 286 if [ -f "$DLFILE" ]; then 287 echo_i "testing default logfile using named -L succeeded" 288 else 289 echo_i "testing default logfile using named -L failed" 290 echo_i "exit status: 1" 291 exit 1 292 fi 293else 294 echo_i "failed to cleanly stop $myNAMED" 295 echo_i "exit status: 1" 296 exit 1 297fi 298 299echo_i "testing logging functionality" 300 301n=`expr $n + 1` 302echo_i "testing iso8601 timestamp ($n)" 303copy_setports $ISOCONF named.conf 304$myRNDC reconfig > rndc.out.test$n 2>&1 305if grep '^....-..-..T..:..:..\.... ' $ISOFILE > /dev/null; then 306 echo_i "testing iso8601 timestamp succeeded" 307else 308 echo_i "testing iso8601 timestamp failed" 309 status=`expr $status + 1` 310fi 311 312n=`expr $n + 1` 313echo_i "testing iso8601-utc timestamp ($n)" 314copy_setports $ISOCONFUTC named.conf 315$myRNDC reconfig > rndc.out.test$n 2>&1 316if grep '^....-..-..T..:..:..\....Z' $ISOUTCFILE > /dev/null; then 317 echo_i "testing iso8601-utc timestamp succeeded" 318else 319 echo_i "testing iso8601-utc timestamp failed" 320 status=`expr $status + 1` 321fi 322 323n=`expr $n + 1` 324echo_i "testing explicit versions ($n)" 325copy_setports $VERSCONF named.conf 326# a seconds since epoch version number 327touch $VERSFILE.1480039317 328t1=`$PERL -e 'print time()."\n";'` 329$myRNDC reconfig > rndc.out.test$n 2>&1 330$DIG version.bind txt ch @10.53.0.1 -p ${PORT} > dig.out.test$n 331t2=`$PERL -e 'print time()."\n";'` 332t=`expr ${t2:-0} - ${t1:-0}` 333if test ${t:-1000} -gt 5 334then 335 echo_i "testing explicit versions failed: cleanup of old entries took too long ($t secs)" 336 status=`expr $status + 1` 337fi 338if ! grep "status: NOERROR" dig.out.test$n > /dev/null 339then 340 echo_i "testing explicit versions failed: DiG lookup failed" 341 status=`expr $status + 1` 342fi 343if test_with_retry -f $VERSFILE.1480039317 344then 345 echo_i "testing explicit versions failed: $VERSFILE.1480039317 not removed" 346 status=`expr $status + 1` 347fi 348if test_with_retry -f $VERSFILE.5 349then 350 echo_i "testing explicit versions failed: $VERSFILE.5 exists" 351 status=`expr $status + 1` 352fi 353if test_with_retry ! -f $VERSFILE.4 354then 355 echo_i "testing explicit versions failed: $VERSFILE.4 does not exist" 356 status=`expr $status + 1` 357fi 358 359n=`expr $n + 1` 360echo_i "testing timestamped versions ($n)" 361copy_setports $TSCONF named.conf 362# a seconds since epoch version number 363touch $TSFILE.2015010112000012 364t1=`$PERL -e 'print time()."\n";'` 365$myRNDC reconfig > rndc.out.test$n 2>&1 366$DIG version.bind txt ch @10.53.0.1 -p ${PORT} > dig.out.test$n 367t2=`$PERL -e 'print time()."\n";'` 368t=`expr ${t2:-0} - ${t1:-0}` 369if test ${t:-1000} -gt 5 370then 371 echo_i "testing timestamped versions failed: cleanup of old entries took too long ($t secs)" 372 status=`expr $status + 1` 373fi 374if ! grep "status: NOERROR" dig.out.test$n > /dev/null 375then 376 echo_i "testing timestamped versions failed: DiG lookup failed" 377 status=`expr $status + 1` 378fi 379if test_with_retry -f $TSFILE.1480039317 380then 381 echo_i "testing timestamped versions failed: $TSFILE.1480039317 not removed" 382 status=`expr $status + 1` 383fi 384 385n=`expr $n + 1` 386echo_i "testing unlimited versions ($n)" 387copy_setports $UNLIMITEDCONF named.conf 388# a seconds since epoch version number 389touch $UNLIMITEDFILE.1480039317 390t1=`$PERL -e 'print time()."\n";'` 391$myRNDC reconfig > rndc.out.test$n 2>&1 392$DIG version.bind txt ch @10.53.0.1 -p ${PORT} > dig.out.test$n 393t2=`$PERL -e 'print time()."\n";'` 394t=`expr ${t2:-0} - ${t1:-0}` 395if test ${t:-1000} -gt 5 396then 397 echo_i "testing unlimited versions failed: took too long ($t secs)" 398 status=`expr $status + 1` 399fi 400if ! grep "status: NOERROR" dig.out.test$n > /dev/null 401then 402 echo_i "testing unlimited versions failed: DiG lookup failed" 403 status=`expr $status + 1` 404fi 405if test_with_retry ! -f $UNLIMITEDFILE.1480039317 406then 407 echo_i "testing unlimited versions failed: $UNLIMITEDFILE.1480039317 removed" 408 status=`expr $status + 1` 409fi 410if test_with_retry ! -f $UNLIMITEDFILE.4 411then 412 echo_i "testing unlimited versions failed: $UNLIMITEDFILE.4 does not exist" 413 status=`expr $status + 1` 414fi 415 416echo_i "exit status: $status" 417[ $status -eq 0 ] || exit 1 418