xref: /netbsd-src/external/bsd/unbound/dist/testdata/08-host-lib.tdir/08-host-lib.test (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1# #-- 08-host-lib.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
10if grep FORK $PRE/config.h | grep "define" >/dev/null 2>&1; then
11	# nothing
12	:
13else
14	echo "forking is not available; test skipped."
15	exit 0
16fi
17
18# test if fwder is up
19echo "> dig @127.0.0.1 -p $FWD_PORT www.example.com | tee outfile"
20dig @127.0.0.1 -p $FWD_PORT www.example.com | tee outfile
21if grep "10.20.30.40" outfile; then
22	echo "fwder is up"
23else
24	cat fwd.log
25	echo "fwder not up"
26	exit 1
27fi
28rm outfile
29
30# create asynclook
31get_make
32echo "> (cd $PRE ; $MAKE asynclook)"
33(cd $PRE ; $MAKE asynclook)
34if test ! -x $PRE/asynclook; then
35	echo "cannot build asynclook test program"
36	exit 1
37fi
38(cd $PRE ; $MAKE lock-verify)
39
40# check the locks.
41function locktest() {
42	if test -x $PRE/lock-verify -a -f ublocktrace.0; then
43		$PRE/lock-verify ublocktrace.*
44		if test $? -ne 0; then
45			echo "lock-verify error"
46			exit 1
47		fi
48	fi
49}
50
51# test hosts reading (directed at local auth info)
52echo '> $PRE/asynclook -H 08-host-lib.hosts virtual.virtual.virtual.local 2>&1 | tee outfile'
53$PRE/asynclook -H 08-host-lib.hosts virtual.virtual.virtual.local 2>&1 | tee outfile
54if grep "virtual.virtual.virtual.local: 10.20.30.40" outfile; then
55	echo "OK"
56else
57	echo "Not OK"
58	exit 1
59fi
60locktest
61rm outfile
62
63# test async lookups (directed at testns)
64echo '> $PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com 2>&1 | tee outfile'
65$PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com 2>&1 | tee outfile
66if grep "www.example.com: 10.20.30.40" outfile; then
67	echo "OK"
68else
69	cat fwd.log
70	echo "Not OK"
71	exit 1
72fi
73locktest
74rm outfile
75
76echo '> $PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
77$PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
78if grep "www.example.com: 10.20.30.40" outfile; then
79	echo "OK"
80else
81	cat fwd.log
82	echo "Not OK"
83	exit 1
84fi
85if grep "www2.example.com: 10.20.30.42" outfile; then
86	echo "OK"
87else
88	cat fwd.log
89	echo "Not OK"
90	exit 1
91fi
92locktest
93rm outfile
94
95echo '> $PRE/asynclook -t -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
96$PRE/asynclook -t -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
97if grep "www.example.com: 10.20.30.40" outfile; then
98	echo "OK"
99else
100	cat fwd.log
101	echo "Not OK"
102	exit 1
103fi
104if grep "www2.example.com: 10.20.30.42" outfile; then
105	echo "OK"
106else
107	cat fwd.log
108	echo "Not OK"
109	exit 1
110fi
111locktest
112rm outfile
113
114# test cancellation
115echo '> $PRE/asynclook -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
116$PRE/asynclook -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
117if grep "www.example.com: cancelled" outfile; then
118	echo "OK"
119else
120	cat fwd.log
121	echo "Not OK"
122	exit 1
123fi
124if grep "www2.example.com: cancelled" outfile; then
125	echo "OK"
126else
127	cat fwd.log
128	echo "Not OK"
129	exit 1
130fi
131locktest
132rm outfile
133
134echo '> $PRE/asynclook -t -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
135$PRE/asynclook -t -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
136if grep "www.example.com: cancelled" outfile; then
137	echo "OK"
138else
139	cat fwd.log
140	echo "Not OK"
141	exit 1
142fi
143if grep "www2.example.com: cancelled" outfile; then
144	echo "OK"
145else
146	cat fwd.log
147	echo "Not OK"
148	exit 1
149fi
150locktest
151rm outfile
152
153# test blocking mode
154echo '> $PRE/asynclook -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
155$PRE/asynclook -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
156if grep "www.example.com: 10.20.30.40" outfile; then
157	echo "OK"
158else
159	cat fwd.log
160	echo "Not OK"
161	exit 1
162fi
163if grep "www2.example.com: 10.20.30.42" outfile; then
164	echo "OK"
165else
166	cat fwd.log
167	echo "Not OK"
168	exit 1
169fi
170locktest
171rm outfile
172
173echo '> $PRE/asynclook -t -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
174$PRE/asynclook -t -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
175if grep "www.example.com: 10.20.30.40" outfile; then
176	echo "OK"
177else
178	cat fwd.log
179	echo "Not OK"
180	exit 1
181fi
182if grep "www2.example.com: 10.20.30.42" outfile; then
183	echo "OK"
184else
185	cat fwd.log
186	echo "Not OK"
187	exit 1
188fi
189locktest
190rm outfile
191
192echo "> cat logfiles"
193cat fwd.log
194exit 0
195