File: proxy_protocol.test.scenario

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 (193 lines) | stat: -rw-r--r-- 4,131 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# #-- proxy_protocol.test.scenario --#
# 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="../.."
. ../common.sh

ip addr add 127.0.0.1 dev lo
ip link set lo up

ip link add $INTERFACE_ALLOW type dummy
ip addr add $INTERFACE_ALLOW_ADDR dev $INTERFACE_ALLOW
ip link set $INTERFACE_ALLOW up

ip link add $INTERFACE_REFUSE type dummy
ip addr add $INTERFACE_REFUSE_ADDR dev $INTERFACE_REFUSE
ip link set $INTERFACE_REFUSE up

# start forwarder in the background
get_ldns_testns
$LDNS_TESTNS -p $FWD_PORT proxy_protocol.testns >fwd.log 2>&1 &
FWD_PID=$!
echo "FWD_PID=$FWD_PID" >> .tpkg.var.test

# start unbound in the background
$PRE/unbound -d -c ub.conf >unbound.log 2>&1 &
UNBOUND_PID=$!
echo "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test

wait_ldns_testns_up fwd.log
wait_unbound_up unbound.log

# call streamtcp and check return value
do_streamtcp () {
	$PRE/streamtcp $* A IN >outfile 2>&1
	if test "$?" -ne 0; then
		echo "exit status not OK"
		echo "> cat logfiles"
		cat outfile
		cat unbound.log
		echo "Not OK"
		exit 1
	fi
}

send_query () {
	server=$1
	client=$2
	prot=$3
	query=$4
	echo -n "> query $query to $server"
	port=$UNBOUND_PORT
	if test ! -z "$client"; then
		port=$PROXY_PORT
	fi
	case $prot in
		-u)
			echo -n " (over UDP)"
			;;
		-s)
			echo -n " (over TLS)"
			port=$PROXY_TLS_PORT
			;;
		*)
			echo -n " (over TCP)"
	esac
	if test ! -z "$client"; then
		echo -n " ($client proxied)"
	fi
	echo
	do_streamtcp $prot -f $server@$port $client $query
	#cat outfile
}

expect_answer () {
	#query=$1
	#answer=$2
	if grep "$query" outfile | grep "$answer"; then
		echo "content OK"
		echo
	else
		echo "> cat logfiles"
		cat outfile
		cat unbound.log
		echo "result contents not OK"
		exit 1
	fi
}

expect_refuse () {
	if grep "rcode: REFUSE" outfile; then
		echo "content OK"
		echo
	else
		echo "> cat logfiles"
		cat outfile
		cat unbound.log
		echo "result contents not OK"
		exit 1
	fi
}

# Start the test

# Query without PROXYv2
# Client localhost
# Expect the result back
server=127.0.0.1
client=""
query="two.example.net."
answer="2.2.2.2"
for prot in "-u" ""; do
	send_query "$server" "$client" "$prot" "$query"
	expect_answer
done

# Query with PROXYv2
# Client $CLIENT_ADDR_ALLOW should be allowed
# Expect the result back
server=127.0.0.1
client="-p $CLIENT_ADDR_ALLOW@1234"
query="one.example.net."
answer="1.1.1.1"
for prot in "-u" "" "-s"; do
	send_query "$server" "$client" "$prot" "$query"
	expect_answer
done

# Query with PROXYv2
# Client $CLIENT_ADDR_ALLOW6 should be allowed
# Expect the result back
server=127.0.0.1
client="-p $CLIENT_ADDR_ALLOW6@1234"
query="one.example.net."
answer="1.1.1.1"
for prot in "-u" "" "-s"; do
	send_query "$server" "$client" "$prot" "$query"
	expect_answer
done

# Query with PROXYv2
# Client $CLIENT_ADDR_REFUSE should be refused
# Expect the REFUSE back
server=127.0.0.1
client="-p $CLIENT_ADDR_REFUSE"
query="one.example.net."
answer=""
for prot in "-u" "" "-s"; do
	send_query "$server" "$client" "$prot" "$query"
	expect_refuse
done

# Query with PROXYv2
# Client $CLIENT_ADDR_REFUSE6 should be refused
# Expect the REFUSE back
server=127.0.0.1
client="-p $CLIENT_ADDR_REFUSE6"
query="one.example.net."
answer=""
for prot in "-u" "" "-s"; do
	send_query "$server" "$client" "$prot" "$query"
	expect_refuse
done

# Query with PROXYv2
# Client $CLIENT_ADDR_ALLOW should be allowed; proxy source address should be allowed
# Expect the result back
server=$INTERFACE_ALLOW_ADDR
client="-p $CLIENT_ADDR_ALLOW@1234"
query="one.example.net."
answer="1.1.1.1"
for prot in "-u" "" "-s"; do
	send_query "$server" "$client" "$prot" "$query"
	expect_answer
done

# Query with PROXYv2
# Client $CLIENT_ADDR_ALLOW should be allowed; proxy source address should be refused
# Expect the REFUSE back
server=$INTERFACE_REFUSE_ADDR
client="-p $CLIENT_ADDR_ALLOW@1234"
query="one.example.net."
answer=""
for prot in "-u" "" "-s"; do
	send_query "$server" "$client" "$prot" "$query"
	expect_refuse
done

echo "OK"
exit 0