1# #-- dnstap_tcp.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 7. ../common.sh 8PRE="../.." 9 10# test if the server is up. 11echo "> dig www.example.com." 12dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile 13echo "> check answer" 14if grep "10.20.30.40" outfile; then 15 echo "OK" 16else 17 echo "> cat logfiles" 18 cat tap.log 19 cat tap.errlog 20 cat fwd.log 21 cat unbound.log 22 echo "Not OK" 23 exit 1 24fi 25 26echo "> check tap.log for dnstap info" 27# see if it logged the information in tap.log 28# wait for a moment for filesystem to catch up. 29if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 30if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 31if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 32if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 33if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 34if grep "www.example.com" tap.log >/dev/null; then :; else sleep 10; fi 35if grep "www.example.com" tap.log; then echo "yes it is in tap.log"; 36else 37 echo "information not in tap.log" 38 echo "failed" 39 echo "> cat logfiles" 40 cat tap.log 41 cat tap.errlog 42 cat fwd.log 43 cat unbound.log 44 echo "Not OK" 45 exit 1 46fi 47 48echo "" 49echo "> test disconnect from the upstream server" 50 51kill_pid $DNSTAP_SOCKET_PID 52dig @127.0.0.1 -p $UNBOUND_PORT down.example.net. 53 54# bring log socket back up 55$PRE/unbound-dnstap-socket -s "127.0.0.1@$TAP_PORT" -l -vvvv 2>tap2.errlog >tap2.log & 56if test $? -ne 0; then 57 echo "could not start (again) unbound-dnstap-socket server" 58 exit 1 59fi 60DNSTAP_SOCKET_PID=$! 61echo "DNSTAP_SOCKET_PID=$DNSTAP_SOCKET_PID" >> .tpkg.var.test 62# wait for the server to go up 63wait_server_up "tap2.errlog" "start of service" 64 65dig @127.0.0.1 -p $UNBOUND_PORT up.example.net. 66sleep 2 67dig @127.0.0.1 -p $UNBOUND_PORT up2.example.net. 68 69for x in down up up2; do 70 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 71 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 72 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 73 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 74 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 75 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 10; fi 76 if grep "$x.example.net" tap2.log; then echo "yes it is in tap2.log"; 77 else 78 echo "$x.example.net. information not in tap2.log" 79 echo "failed" 80 echo "> cat logfiles" 81 cat tap.log 82 cat tap.errlog 83 echo "> tap2 logfiles" 84 cat tap2.log 85 cat tap2.errlog 86 cat fwd.log 87 cat unbound.log 88 echo "Not OK" 89 exit 1 90 fi 91done 92 93echo "> OK" 94exit 0 95