1#!/bin/sh 2# 3# Copyright (C) 2011-2013 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 2011/03/22 16:51:50 smann Exp 18 19SYSTEMTESTTOP=.. 20. $SYSTEMTESTTOP/conf.sh 21THISDIR=`pwd` 22CONFDIR="ns1" 23PLAINCONF="${THISDIR}/${CONFDIR}/named.plain" 24DIRCONF="${THISDIR}/${CONFDIR}/named.dirconf" 25PIPECONF="${THISDIR}/${CONFDIR}/named.pipeconf" 26SYMCONF="${THISDIR}/${CONFDIR}/named.symconf" 27PLAINFILE="named_log" 28DIRFILE="named_dir" 29PIPEFILE="named_pipe" 30SYMFILE="named_sym" 31PIDFILE="${THISDIR}/${CONFDIR}/named.pid" 32myRNDC="$RNDC -c ${THISDIR}/${CONFDIR}/rndc.conf" 33myNAMED="$NAMED -c ${THISDIR}/${CONFDIR}/named.conf -m record,size,mctx -T clienttest -T nosyslog -d 99 -U 4" 34 35status=0 36 37cd $CONFDIR 38 39echo "I:testing log file validity (named -g + only plain files allowed)" 40 41# First run with a known good config. 42echo > $PLAINFILE 43cp $PLAINCONF named.conf 44$myRNDC reconfig 45grep "reloading configuration failed" named.run > /dev/null 2>&1 46if [ $? -ne 0 ] 47then 48 echo "I: testing plain file succeeded" 49else 50 echo "I: testing plain file failed (unexpected)" 51 echo "I:exit status: 1" 52 exit 1 53fi 54 55# Now try directory, expect failure 56echo "I: testing directory as log file (named -g)" 57echo > named.run 58rm -rf $DIRFILE 59mkdir -p $DIRFILE >/dev/null 2>&1 60if [ $? -eq 0 ] 61then 62 cp $DIRCONF named.conf 63 echo > named.run 64 $myRNDC reconfig 65 grep "checking logging configuration failed: invalid file" named.run > /dev/null 2>&1 66 if [ $? -ne 0 ] 67 then 68 echo "I: testing directory as file succeeded (UNEXPECTED)" 69 echo "I:exit status: 1" 70 exit 1 71 else 72 echo "I: testing directory as log file failed (expected)" 73 fi 74else 75 echo "I: skipping directory test (unable to create directory)" 76fi 77 78# Now try pipe file, expect failure 79echo "I: testing pipe file as log file (named -g)" 80echo > named.run 81rm -f $PIPEFILE 82mkfifo $PIPEFILE >/dev/null 2>&1 83if [ $? -eq 0 ] 84then 85 cp $PIPECONF named.conf 86 echo > named.run 87 $myRNDC reconfig 88 grep "checking logging configuration failed: invalid file" named.run > /dev/null 2>&1 89 if [ $? -ne 0 ] 90 then 91 echo "I: testing pipe file as log file succeeded (UNEXPECTED)" 92 echo "I:exit status: 1" 93 exit 1 94 else 95 echo "I: testing pipe file as log file failed (expected)" 96 fi 97else 98 echo "I: skipping pipe test (unable to create pipe)" 99fi 100 101# Now try symlink file to plain file, expect success 102echo "I: testing symlink to plain file as log file (named -g)" 103# Assume success 104echo > named.run 105echo > $PLAINFILE 106rm -f $SYMFILE $SYMFILE 107ln -s $PLAINFILE $SYMFILE >/dev/null 2>&1 108if [ $? -eq 0 ] 109then 110 cp $SYMCONF named.conf 111 $myRNDC reconfig 112 echo > named.run 113 grep "reloading configuration failed" named.run > /dev/null 2>&1 114 if [ $? -ne 0 ] 115 then 116 echo "I: testing symlink to plain file succeeded" 117 else 118 echo "I: testing symlink to plain file failed (unexpected)" 119 echo "I:exit status: 1" 120 exit 1 121 fi 122else 123 echo "I: skipping symlink test (unable to create symlink)" 124fi 125# Stop the server and run through a series of tests with various config 126# files while controlling the stop/start of the server. 127# Have to stop the stock server because it uses "-g" 128# 129$PERL ../../stop.pl .. ns1 130 131$myNAMED > /dev/null 2>&1 132 133if [ $? -ne 0 ] 134then 135 echo "I:failed to start $myNAMED" 136 echo "I:exit status: $status" 137 exit $status 138fi 139 140status=0 141 142echo "I:testing log file validity (only plain files allowed)" 143 144# First run with a known good config. 145echo > $PLAINFILE 146cp $PLAINCONF named.conf 147$myRNDC reconfig 148grep "reloading configuration failed" named.run > /dev/null 2>&1 149if [ $? -ne 0 ] 150then 151 echo "I: testing plain file succeeded" 152else 153 echo "I: testing plain file failed (unexpected)" 154 echo "I:exit status: 1" 155 exit 1 156fi 157 158# Now try directory, expect failure 159echo "I: testing directory as log file" 160echo > named.run 161rm -rf $DIRFILE 162mkdir -p $DIRFILE >/dev/null 2>&1 163if [ $? -eq 0 ] 164then 165 cp $DIRCONF named.conf 166 echo > named.run 167 $myRNDC reconfig 168 grep "configuring logging: invalid file" named.run > /dev/null 2>&1 169 if [ $? -ne 0 ] 170 then 171 echo "I: testing directory as file succeeded (UNEXPECTED)" 172 echo "I:exit status: 1" 173 exit 1 174 else 175 echo "I: testing directory as log file failed (expected)" 176 fi 177else 178 echo "I: skipping directory test (unable to create directory)" 179fi 180 181# Now try pipe file, expect failure 182echo "I: testing pipe file as log file" 183echo > named.run 184rm -f $PIPEFILE 185mkfifo $PIPEFILE >/dev/null 2>&1 186if [ $? -eq 0 ] 187then 188 cp $PIPECONF named.conf 189 echo > named.run 190 $myRNDC reconfig 191 grep "configuring logging: invalid file" named.run > /dev/null 2>&1 192 if [ $? -ne 0 ] 193 then 194 echo "I: testing pipe file as log file succeeded (UNEXPECTED)" 195 echo "I:exit status: 1" 196 exit 1 197 else 198 echo "I: testing pipe file as log file failed (expected)" 199 fi 200else 201 echo "I: skipping pipe test (unable to create pipe)" 202fi 203 204# Now try symlink file to plain file, expect success 205echo "I: testing symlink to plain file as log file" 206# Assume success 207status=0 208echo > named.run 209echo > $PLAINFILE 210rm -f $SYMFILE 211ln -s $PLAINFILE $SYMFILE >/dev/null 2>&1 212if [ $? -eq 0 ] 213then 214 cp $SYMCONF named.conf 215 $myRNDC reconfig 216 echo > named.run 217 grep "reloading configuration failed" named.run > /dev/null 2>&1 218 if [ $? -ne 0 ] 219 then 220 echo "I: testing symlink to plain file succeeded" 221 else 222 echo "I: testing symlink to plain file failed (unexpected)" 223 echo "I:exit status: 1" 224 exit 1 225 fi 226else 227 echo "I: skipping symlink test (unable to create symlink)" 228fi 229 230echo "I:exit status: $status" 231exit $status 232