File: http_user_agent.test

package info (click to toggle)
unbound 1.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,436 kB
  • sloc: ansic: 138,476; sh: 6,860; yacc: 4,259; python: 1,950; makefile: 1,881; awk: 162; perl: 158; xml: 36
file content (103 lines) | stat: -rw-r--r-- 2,554 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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 @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile
	if grep SERVFAIL outfile; then
		echo "> try again"
		dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile
	fi
	if grep SERVFAIL outfile; then
		echo "> try again"
		sleep 1
		dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile
	fi
	if grep SERVFAIL outfile; then
		echo "> try again"
		sleep 1
		dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile
	fi
	if grep SERVFAIL outfile; then
		echo "> try again"
		sleep 1
		dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile
	fi
	if grep SERVFAIL outfile; then
		echo "> try again"
		sleep 10
		dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile
	fi
	if grep SERVFAIL outfile; then
		echo "> try again"
		sleep 10
		dig @127.0.0.1 -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 occurrences.
# It should be 2 User-Agents, one being the custom.
echo "> check User-Agent occurrences"
occurrences=`grep "User-Agent:" petal.log | wc -l`
echo $occurrences
if test $occurrences -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