xref: /netbsd-src/external/bsd/unbound/dist/testdata/http_user_agent.tdir/http_user_agent.test (revision 7a540f2bd4f5b968566c2607d6462c7f2fb452cf)
1# #-- http_user_agent.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
9# Query and check check that we get the correct answer from the auth_zone
10query () {
11	echo "> dig www.example.com."
12	dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile
13	if grep SERVFAIL outfile; then
14		echo "> try again"
15		dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile
16	fi
17	if grep SERVFAIL outfile; then
18		echo "> try again"
19		sleep 1
20		dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile
21	fi
22	if grep SERVFAIL outfile; then
23		echo "> try again"
24		sleep 1
25		dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile
26	fi
27	if grep SERVFAIL outfile; then
28		echo "> try again"
29		sleep 1
30		dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile
31	fi
32	if grep SERVFAIL outfile; then
33		echo "> try again"
34		sleep 10
35		dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile
36	fi
37	if grep SERVFAIL outfile; then
38		echo "> try again"
39		sleep 10
40		dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile
41	fi
42	echo "> check answer"
43	if grep "1.2.3.4" outfile; then
44		echo "OK"
45	else
46		echo "Not OK"
47		exit 1
48	fi
49}
50
51# Reload the configuration and retransfer the zone
52reload_and_retransfer () {
53	echo "> Reloading Unbound"
54	echo "$PRE/unbound-control -c ub.conf reload"
55	$PRE/unbound-control -c ub.conf reload
56	if test $? -ne 0; then
57		echo "wrong exit value from unbound-control"
58		exit 1
59	fi
60	echo "> Refetching example.com"
61	echo "$PRE/unbound-control -c ub.conf auth_zone_transfer example.com"
62	$PRE/unbound-control -c ub.conf auth_zone_transfer example.com
63	if test $? -ne 0; then
64		echo "wrong exit value from unbound-control"
65		exit 1
66	fi
67}
68
69# do the test
70query
71# add custom http-user-agent
72echo "server: http-user-agent: customUA" >> ub.conf
73reload_and_retransfer
74query
75# hide http-user-agent
76echo "server: hide-http-user-agent: yes" >> ub.conf
77reload_and_retransfer
78query
79
80echo "> cat logfiles"
81cat petal.log
82cat unbound.log
83
84# check petal.log for the correct number of occurrences.
85# It should be 2 User-Agents, one being the custom.
86echo "> check User-Agent occurrences"
87occurrences=`grep "User-Agent:" petal.log | wc -l`
88echo $occurrences
89if test $occurrences -eq 2; then
90	echo "OK"
91else
92	echo "Not OK"
93	exit 1
94fi
95echo "> check custom User-Agent"
96if grep "User-Agent: customUA" petal.log; then
97	echo "OK"
98else
99	echo "Not OK"
100	exit 1
101fi
102
103exit 0
104