diff options
Diffstat (limited to 'testdata/http_user_agent.tdir/http_user_agent.test')
| -rw-r--r-- | testdata/http_user_agent.tdir/http_user_agent.test | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/testdata/http_user_agent.tdir/http_user_agent.test b/testdata/http_user_agent.tdir/http_user_agent.test new file mode 100644 index 000000000000..afc0fbbe6f4b --- /dev/null +++ b/testdata/http_user_agent.tdir/http_user_agent.test @@ -0,0 +1,103 @@ +# #-- http_user_agent.test --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master +# use .tpkg.var.test for in test variable passing +[ -f .tpkg.var.test ] && source .tpkg.var.test + +PRE="../.." + +# Query and check check that we get the correct answer from the auth_zone +query () { + echo "> dig www.example.com." + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile + if grep SERVFAIL outfile; then + echo "> try again" + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile + fi + if grep SERVFAIL outfile; then + echo "> try again" + sleep 1 + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile + fi + if grep SERVFAIL outfile; then + echo "> try again" + sleep 1 + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile + fi + if grep SERVFAIL outfile; then + echo "> try again" + sleep 1 + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile + fi + if grep SERVFAIL outfile; then + echo "> try again" + sleep 10 + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile + fi + if grep SERVFAIL outfile; then + echo "> try again" + sleep 10 + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile + fi + echo "> check answer" + if grep "1.2.3.4" outfile; then + echo "OK" + else + echo "Not OK" + exit 1 + fi +} + +# Reload the configuration and retransfer the zone +reload_and_retransfer () { + echo "> Reloading Unbound" + echo "$PRE/unbound-control -c ub.conf reload" + $PRE/unbound-control -c ub.conf reload + if test $? -ne 0; then + echo "wrong exit value from unbound-control" + exit 1 + fi + echo "> Refetching example.com" + echo "$PRE/unbound-control -c ub.conf auth_zone_transfer example.com" + $PRE/unbound-control -c ub.conf auth_zone_transfer example.com + if test $? -ne 0; then + echo "wrong exit value from unbound-control" + exit 1 + fi +} + +# do the test +query +# add custom http-user-agent +echo "server: http-user-agent: customUA" >> ub.conf +reload_and_retransfer +query +# hide http-user-agent +echo "server: hide-http-user-agent: yes" >> ub.conf +reload_and_retransfer +query + +echo "> cat logfiles" +cat petal.log +cat unbound.log + +# check petal.log for the correct number of occurences. +# It should be 2 User-Agents, one being the custom. +echo "> check User-Agent occurences" +occurences=`grep "User-Agent:" petal.log | wc -l` +echo $occurences +if test $occurences -eq 2; then + echo "OK" +else + echo "Not OK" + exit 1 +fi +echo "> check custom User-Agent" +if grep "User-Agent: customUA" petal.log; then + echo "OK" +else + echo "Not OK" + exit 1 +fi + +exit 0 |
