1# #-- 08-host-lib.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 7PRE="../.." 8. ../common.sh 9 10# test if fwder is up 11echo "> dig @127.0.0.1 -p $FWD_PORT www.example.com | tee outfile" 12dig @127.0.0.1 -p $FWD_PORT www.example.com | tee outfile 13if grep "10.20.30.40" outfile; then 14 echo "fwder is up" 15else 16 cat fwd.log 17 echo "fwder not up" 18 exit 1 19fi 20rm outfile 21 22# create asynclook 23get_make 24echo "> (cd $PRE ; $MAKE asynclook)" 25(cd $PRE ; $MAKE asynclook) 26if test ! -x $PRE/asynclook; then 27 echo "cannot build asynclook test program" 28 exit 1 29fi 30(cd $PRE ; $MAKE lock-verify) 31 32# check the locks. 33function locktest() { 34 if test -x $PRE/lock-verify -a -f ublocktrace.0; then 35 $PRE/lock-verify ublocktrace.* 36 if test $? -ne 0; then 37 echo "lock-verify error" 38 exit 1 39 fi 40 fi 41} 42 43# test hosts reading (directed at local auth info) 44echo '> $PRE/asynclook -H 08-host-lib.hosts virtual.virtual.virtual.local 2>&1 | tee outfile' 45$PRE/asynclook -H 08-host-lib.hosts virtual.virtual.virtual.local 2>&1 | tee outfile 46if grep "virtual.virtual.virtual.local: 10.20.30.40" outfile; then 47 echo "OK" 48else 49 echo "Not OK" 50 exit 1 51fi 52locktest 53rm outfile 54 55# test async lookups (directed at testns) 56echo '> $PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com 2>&1 | tee outfile' 57$PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com 2>&1 | tee outfile 58if grep "www.example.com: 10.20.30.40" outfile; then 59 echo "OK" 60else 61 cat fwd.log 62 echo "Not OK" 63 exit 1 64fi 65locktest 66rm outfile 67 68echo '> $PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile' 69$PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile 70if grep "www.example.com: 10.20.30.40" outfile; then 71 echo "OK" 72else 73 cat fwd.log 74 echo "Not OK" 75 exit 1 76fi 77if grep "www2.example.com: 10.20.30.42" outfile; then 78 echo "OK" 79else 80 cat fwd.log 81 echo "Not OK" 82 exit 1 83fi 84locktest 85rm outfile 86 87echo '> $PRE/asynclook -t -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile' 88$PRE/asynclook -t -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile 89if grep "www.example.com: 10.20.30.40" outfile; then 90 echo "OK" 91else 92 cat fwd.log 93 echo "Not OK" 94 exit 1 95fi 96if grep "www2.example.com: 10.20.30.42" outfile; then 97 echo "OK" 98else 99 cat fwd.log 100 echo "Not OK" 101 exit 1 102fi 103locktest 104rm outfile 105 106# test cancellation 107echo '> $PRE/asynclook -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile' 108$PRE/asynclook -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile 109if grep "www.example.com: cancelled" outfile; then 110 echo "OK" 111else 112 cat fwd.log 113 echo "Not OK" 114 exit 1 115fi 116if grep "www2.example.com: cancelled" outfile; then 117 echo "OK" 118else 119 cat fwd.log 120 echo "Not OK" 121 exit 1 122fi 123locktest 124rm outfile 125 126echo '> $PRE/asynclook -t -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile' 127$PRE/asynclook -t -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile 128if grep "www.example.com: cancelled" outfile; then 129 echo "OK" 130else 131 cat fwd.log 132 echo "Not OK" 133 exit 1 134fi 135if grep "www2.example.com: cancelled" outfile; then 136 echo "OK" 137else 138 cat fwd.log 139 echo "Not OK" 140 exit 1 141fi 142locktest 143rm outfile 144 145# test blocking mode 146echo '> $PRE/asynclook -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile' 147$PRE/asynclook -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile 148if grep "www.example.com: 10.20.30.40" outfile; then 149 echo "OK" 150else 151 cat fwd.log 152 echo "Not OK" 153 exit 1 154fi 155if grep "www2.example.com: 10.20.30.42" outfile; then 156 echo "OK" 157else 158 cat fwd.log 159 echo "Not OK" 160 exit 1 161fi 162locktest 163rm outfile 164 165echo '> $PRE/asynclook -t -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile' 166$PRE/asynclook -t -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile 167if grep "www.example.com: 10.20.30.40" outfile; then 168 echo "OK" 169else 170 cat fwd.log 171 echo "Not OK" 172 exit 1 173fi 174if grep "www2.example.com: 10.20.30.42" outfile; then 175 echo "OK" 176else 177 cat fwd.log 178 echo "Not OK" 179 exit 1 180fi 181locktest 182rm outfile 183 184echo "> cat logfiles" 185cat fwd.log 186exit 0 187