xref: /netbsd-src/external/bsd/unbound/dist/testdata/tls_reuse.tdir/tls_reuse.test (revision d0eba39ba71d0ccd0f91ae4c5ff83442e84710bf)
1# #-- tls_reuse.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. ../common.sh
9
10get_make
11(cd $PRE; $MAKE streamtcp)
12
13echo "> query www1.example.com."
14$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www1.example.com. A IN >outfile 2>&1
15cat outfile
16if test "$?" -ne 0; then
17	echo "exit status not OK"
18	echo "> cat logfiles"
19	cat outfile
20	cat unbound2.log
21	cat unbound.log
22	echo "Not OK"
23	exit 1
24fi
25if grep "www1.example.com" outfile | grep "10.20.30.41"; then
26	echo "content OK"
27else
28	echo "result contents not OK, for www1.example.com"
29	echo "> cat logfiles"
30	cat outfile
31	cat unbound2.log
32	cat unbound.log
33	echo "result contents not OK, for www1.example.com"
34	exit 1
35fi
36echo "OK"
37echo ""
38
39# this should be reused on the same tcp stream:
40echo "> query www2.example.com."
41$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www2.example.com. A IN >outfile 2>&1
42cat outfile
43if test "$?" -ne 0; then
44	echo "exit status not OK"
45	echo "> cat logfiles"
46	cat outfile
47	cat unbound2.log
48	cat unbound.log
49	echo "Not OK"
50	exit 1
51fi
52if grep "www2.example.com" outfile | grep "10.20.30.42"; then
53	echo "content OK"
54else
55	echo "result contents not OK, for www2.example.com"
56	echo "> cat logfiles"
57	cat outfile
58	cat unbound2.log
59	cat unbound.log
60	echo "result contents not OK, for www2.example.com"
61	exit 1
62fi
63
64echo "> query refuse.net."
65$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT refuse.net. A IN >outfile 2>&1
66cat outfile
67if test "$?" -ne 0; then
68	echo "exit status not OK"
69	echo "> cat logfiles"
70	cat outfile
71	cat unbound2.log
72	cat unbound.log
73	echo "Not OK"
74	exit 1
75fi
76if grep "rcode: SERVFAIL" outfile; then
77	echo "content OK"
78else
79	echo "result contents not OK, for refuse.net"
80	echo "> cat logfiles"
81	cat outfile
82	cat unbound2.log
83	cat unbound.log
84	echo "result contents not OK, for refuse.net"
85	exit 1
86fi
87
88echo "> query www3.example.com."
89echo "> query www4.example.com."
90echo "> query www5.example.com."
91echo "> query www6.example.com."
92$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www3.example.com. A IN >outfile3 2>&1 &
93$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www4.example.com. A IN >outfile4 2>&1 &
94$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www5.example.com. A IN >outfile5 2>&1 &
95$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT www6.example.com. A IN >outfile6 2>&1 &
96wait
97if test "$?" -ne 0; then
98	echo "exit status not OK"
99	echo "> cat logfiles"
100	cat outfile3
101	cat outfile4
102	cat outfile5
103	cat outfile6
104	cat unbound2.log
105	cat unbound.log
106	echo "Not OK"
107	exit 1
108fi
109if grep "www3.example.com" outfile3 | grep "10.20.30.43"; then
110	echo "content OK"
111else
112	echo "result contents not OK, for www3.example.com"
113	echo "> cat logfiles"
114	cat outfile3
115	cat outfile4
116	cat outfile5
117	cat outfile6
118	cat unbound2.log
119	cat unbound.log
120	echo "result contents not OK, for www3.example.com"
121	exit 1
122fi
123if grep "www4.example.com" outfile4 | grep "10.20.30.44"; then
124	echo "content OK"
125else
126	echo "result contents not OK, for www4.example.com"
127	echo "> cat logfiles"
128	cat outfile3
129	cat outfile4
130	cat outfile5
131	cat outfile6
132	cat unbound2.log
133	cat unbound.log
134	echo "result contents not OK, for www4.example.com"
135	exit 1
136fi
137if grep "www5.example.com" outfile5 | grep "10.20.30.45"; then
138	echo "content OK"
139else
140	echo "result contents not OK, for www5.example.com"
141	echo "> cat logfiles"
142	cat outfile3
143	cat outfile4
144	cat outfile5
145	cat outfile6
146	cat unbound2.log
147	cat unbound.log
148	echo "result contents not OK, for www5.example.com"
149	exit 1
150fi
151if grep "www6.example.com" outfile6 | grep "10.20.30.46"; then
152	echo "content OK"
153else
154	echo "result contents not OK, for www6.example.com"
155	echo "> cat logfiles"
156	cat outfile3
157	cat outfile4
158	cat outfile5
159	cat outfile6
160	cat unbound2.log
161	cat unbound.log
162	echo "result contents not OK, for www6.example.com"
163	exit 1
164fi
165
166echo "> query a1.more.net a2.more.net a3.more.net a4.more.net a5.more.net"
167$PRE/streamtcp -a -f 127.0.0.1@$UNBOUND_PORT a1.more.net A IN a2.more.net A IN a3.more.net A IN a4.more.net A IN a5.more.net A IN >outfile 2>&1
168if test "$?" -ne 0; then
169	echo "exit status not OK"
170	echo "> cat logfiles"
171	cat outfile
172	cat unbound2.log
173	cat unbound.log
174	echo "Not OK"
175	exit 1
176fi
177cat outfile
178for x in a1.more.net a2.more.net a3.more.net a4.more.net a5.more.net; do
179	if grep "$x" outfile | grep "10.20.30.40"; then
180		echo "content OK for $x"
181	else
182		echo "result contents not OK, for $x"
183		echo "> cat logfiles"
184		cat outfile
185		cat unbound2.log
186		cat unbound.log
187		echo "result contents not OK, for $x"
188		exit 1
189	fi
190done
191
192# make the server timeout to drop the upstream connection
193echo "> sleep 15"
194sleep 15
195# see if we are still up.
196echo "> query a7.more.net"
197$PRE/streamtcp -a -f 127.0.0.1@$UNBOUND_PORT a7.more.net A IN >outfile 2>&1
198if test "$?" -ne 0; then
199	echo "exit status not OK"
200	echo "> cat logfiles"
201	cat outfile
202	cat unbound2.log
203	cat unbound.log
204	echo "Not OK"
205	exit 1
206fi
207cat outfile
208for x in a7.more.net; do
209	if grep "$x" outfile | grep "10.20.30.40"; then
210		echo "content OK for $x"
211	else
212		echo "result contents not OK, for $x"
213		echo "> cat logfiles"
214		cat outfile
215		cat unbound2.log
216		cat unbound.log
217		echo "result contents not OK, for $x"
218		exit 1
219	fi
220done
221
222# dropconn.drop.net make the server drop the connection.
223echo "> query a11.more.net a12.more.net dropconn.drop.net a14.more.net a15.more.net"
224$PRE/streamtcp -a -f 127.0.0.1@$UNBOUND_PORT a11.more.net A IN a12.more.net A IN dropconn.drop.net A IN a14.more.net A IN a15.more.net A IN >outfile 2>&1
225if test "$?" -ne 0; then
226	echo "exit status not OK"
227	echo "> cat logfiles"
228	cat outfile
229	cat unbound2.log
230	cat unbound.log
231	echo "Not OK"
232	exit 1
233fi
234cat outfile
235# cannot really check outfile, because it may or may not have answers depending
236# on how fast the other server responds or the drop happens, but there are
237# a bunch of connection drops, whilst resolving the other queries.
238
239echo "> query drop.net."
240$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT drop.net. A IN >outfile 2>&1
241cat outfile
242if test "$?" -ne 0; then
243	echo "exit status not OK"
244	echo "> cat logfiles"
245	cat outfile
246	cat unbound2.log
247	cat unbound.log
248	echo "Not OK"
249	exit 1
250fi
251if grep "rcode: SERVFAIL" outfile; then
252	echo "content OK"
253else
254	echo "result contents not OK, for drop.net"
255	echo "> cat logfiles"
256	cat outfile
257	cat unbound2.log
258	cat unbound.log
259	echo "result contents not OK, for drop.net"
260	exit 1
261fi
262
263# timeouts at the end. (so that the server is not marked as failed for
264# the other tests).
265echo "> query q1.drop.net."
266echo "> query q2.drop.net."
267$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT q1.drop.net. A IN >outfile1 2>&1 &
268$PRE/streamtcp -f 127.0.0.1@$UNBOUND_PORT q2.drop.net. A IN >outfile2 2>&1 &
269wait
270if test "$?" -ne 0; then
271	echo "exit status not OK"
272	echo "> cat logfiles"
273	cat outfile1
274	cat outfile2
275	cat unbound2.log
276	cat unbound.log
277	echo "Not OK"
278	exit 1
279fi
280cat outfile1
281cat outfile2
282if grep "rcode: SERVFAIL" outfile1; then
283	echo "content OK"
284else
285	echo "result contents not OK, for q1.drop.net"
286	echo "> cat logfiles"
287	cat outfile1
288	cat outfile2
289	cat unbound2.log
290	cat unbound.log
291	echo "result contents not OK, for q1.drop.net"
292	exit 1
293fi
294if grep "rcode: SERVFAIL" outfile2; then
295	echo "content OK"
296else
297	echo "result contents not OK, for q2.drop.net"
298	echo "> cat logfiles"
299	cat outfile1
300	cat outfile2
301	cat unbound2.log
302	cat unbound.log
303	echo "result contents not OK, for q2.drop.net"
304	exit 1
305fi
306
307echo "OK"
308exit 0
309