]> git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests/start-test-stop
dnsdist: Add regression tests for the new cache-miss rules chain
[thirdparty/pdns.git] / regression-tests / start-test-stop
1 #!/usr/bin/env bash
2 set -e
3 if [ "${PDNS_DEBUG}" = "YES" ]; then
4 set -x
5 fi
6
7 export PDNS=${PDNS:-${PWD}/../pdns/pdns_server}
8 export PDNS2=${PDNS2:-${PWD}/../pdns/pdns_server}
9 export PDNSRECURSOR=${PDNSRECURSOR:-${PWD}/../pdns/recursordist/pdns_recursor}
10 export RECCONTROL=${RECCONTROL:-${PWD}/../pdns/recursordist/rec_control}
11 export SDIG=${SDIG:-${PWD}/../pdns/sdig}
12 export NOTIFY=${NOTIFY:-${PWD}/../pdns/pdns_notify}
13 export NSEC3DIG=${NSEC3DIG:-${PWD}/../pdns/nsec3dig}
14 export SAXFR=${SAXFR:-${PWD}/../pdns/saxfr}
15 export ZONE2SQL=${ZONE2SQL:-${PWD}/../pdns/zone2sql}
16 export ZONE2LDAP=${ZONE2LDAP:-${PWD}/../pdns/zone2ldap}
17 export PDNSUTIL=${PDNSUTIL:-${PWD}/../pdns/pdnsutil}
18 export PDNSCONTROL=${PDNSCONTROL:-${PWD}/../pdns/pdns_control}
19 export RESOLVERIP=${RESOLVERIP:-8.8.8.8}
20 export FIX_TESTS=${FIX_TESTS:-NO}
21
22
23 ALGORITHM=${ALGORITHM:="hmac-md5"}
24 KEY=${KEY:="kp4/24gyYsEzbuTVJRUMoqGFmN3LYgVDzJ/3oRSP7ys="}
25
26 MAKE=${MAKE:-make}
27
28 export ALGORITHM
29 export KEY
30
31 _show_help=0
32 for arg; do
33 case "$arg" in
34 (--help|help)
35 _show_help=1
36 ;;
37 esac
38 done; unset -v arg
39 if [ "$_show_help" -eq 1 ]; then
40 grep -v '^#' << '__EOF__'
41
42 Usage: ./start-test-stop <port> [<context>] [wait|nowait] [<cachettl>] [<specifictest>]
43
44 context is one of:
45 bind bind-dnssec bind-dnssec-nsec3 bind-dnssec-nsec3-optout bind-dnssec-nsec3-narrow
46 geoip geoip-nsec3-narrow
47 gmysql-nodnssec gmysql gmysql-nsec3 gmysql-nsec3-optout gmysql-nsec3-narrow gmysql_sp
48 godbc_mssql-nodnssec godbc_mssql godbc_mssql-nsec3 godbc_mssql-nsec3-optout godbc_mssql-nsec3-narrow
49 godbc_sqlite3-nodnssec godbc_sqlite3 godbc_sqlite3-nsec3 godbc_sqlite3-nsec3-optout godbc_sqlite3-narrow
50 gpgsql-nodnssec gpgsql gpgsql-nsec3 gpgsql-nsec3-optout gpgsql-nsec3-narrow gpgsql_sp
51 gsqlite3-nodnssec gsqlite3 gsqlite3-nsec3 gsqlite3-nsec3-optout gsqlite3-nsec3-narrow
52 lmdb-nodnssec lmdb
53 remotebackend-pipe remotebackend-unix remotebackend-http remotebackend-zeromq
54 remotebackend-pipe-dnssec remotebackend-unix-dnssec remotebackend-http-dnssec remotebackend-zeromq-dnssec
55 #remotebackend-pipe-nsec3 remotebackend-unix-nsec3 remotebackend-http-nsec3
56 #remotebackend-pipe-nsec3-narrow remotebackend-unix-nsec3-narrow remotebackend-http-nsec3-narrow
57 tinydns
58 ldap-tree ldap-simple ldap-strict
59 lua2 lua2-dnssec lua2-nsec3 lua2-nsec3-narrow
60 #ext-nsd ext-nsd-nsec ext-nsd-nsec3 ext-bind ext-bind-nsec ext-bind-nsec3
61
62 * Add -presigned to any ext-nsd, ext-bind, bind, gmysql or gsqlite3 test (except narrow)
63 to test presigned operation.
64
65 * Add -both to any bind or gmysql test (except narrow) to
66 test normal and presigned operation.
67
68 * Add 'wait' (literally) after the context to not kill
69 pdns_server immediately after testing. 'nowait' will kill it.
70
71 * A cachettl can be supplied if you want to run tests with a
72 ttl setting set. The default cachettl is 0.
73
74 * Specifictest can be used to run only one single test.
75 __EOF__
76 exit
77 fi
78 unset -v _show_help
79
80 trap "kill_process 2" EXIT INT TERM
81
82 source ../regression-tests/common
83
84 bindwait ()
85 {
86 check_process
87 configname=$1
88 domcount=$(grep -c ^zone named.conf)
89 if [ ! -x $PDNSCONTROL ]
90 then
91 echo "No pdns_control found"
92 exit
93 fi
94 loopcount=0
95
96 while [ $loopcount -lt 20 ]
97 do
98 sleep 5
99 done=$( ($PDNSCONTROL --config-name=$configname --socket-dir=. --no-config bind-domain-status || true) | grep -c 'parsed into memory' || true )
100 if [ $done = $domcount ]
101 then
102 return
103 fi
104 let loopcount=loopcount+1
105 done
106
107 if [ $done != $domcount ]
108 then
109 echo "Domain parsing failed" >> failed_tests
110 fi
111 }
112
113 securezone ()
114 {
115 local zone=$1
116 local configname=$2
117
118 if [ -n "$configname" ]
119 then
120 configname="--config-name=$configname"
121 fi
122 if [ "${zone: 0:16}" = "secure-delegated" ]
123 then
124 $PDNSUTIL --config-dir=. $configname import-zone-key $zone $zone.private ksk 2>&1
125 $PDNSUTIL --config-dir=. $configname add-zone-key $zone rsasha256 1024 zsk active 2>&1
126 $PDNSUTIL --config-dir=. $configname rectify-zone $zone 2>&1
127 $PDNSUTIL --config-dir=. $configname set-publish-cds $zone 2>&1
128 $PDNSUTIL --config-dir=. $configname set-publish-cdnskey $zone 2>&1
129 else
130 # check if PKCS#11 should be used
131 if [ "$pkcs11" -eq 1 ]; then
132 if [ "$slot" == "" ]; then
133 slot=0
134 else
135 slot=$((slot+1))
136 fi
137 label=pdnstest-${EPOCHSECONDS}-${slot}
138 softhsm2-util --delete-token --label $label 2> /dev/null || true
139 softhsm2-util --init-token --label $label --free --pin 1234 --so-pin 1234
140 kid=`$PDNSUTIL --config-dir=. $configname hsm assign $zone ecdsa256 ksk softhsm2 $label 1234 $label 2>&1 | grep softhsm | awk '{ print $NF }'`
141 $PDNSUTIL --config-dir=. $configname hsm create-key $zone $kid
142 $PDNSUTIL --config-dir=. $configname rectify-zone $zone 2>&1
143 else
144 $PDNSUTIL --config-dir=. $configname secure-zone $zone 2>&1
145 fi
146 if [ "${zone: 0:20}" = "cdnskey-cds-test.com" ]; then
147 $PDNSUTIL --config-dir=. $configname set-publish-cds $zone 2>&1
148 $PDNSUTIL --config-dir=. $configname set-publish-cdnskey $zone 2>&1
149 fi
150 if [ "$zone" = "dnssec-parent.com" ]; then
151 $PDNSUTIL --config-dir=. $configname set-publish-cds $zone 0 2>&1
152 $PDNSUTIL --config-dir=. $configname set-publish-cdnskey $zone delete 2>&1
153 fi
154 fi
155 }
156
157 kill_process ()
158 {
159 set +e
160 trap - EXIT INT TERM
161
162 if [ $1 -gt 1 ]
163 then
164 echo "exitvalue$1" >> failed_tests
165 ./toxml
166 ./totar
167 fi
168
169 pids=$(cat pdns*.pid)
170
171 if [ -n "$pids" ]
172 then
173 kill $pids
174 # make sure they die.
175 loopcount=0
176 done=0
177 while [ $loopcount -lt 10 ] && [ $done -eq 0 ]
178 do
179 done=1
180 for pid in $pids
181 do
182 kill -0 $pid > /dev/null 2>&1
183 if [ $? -eq 0 ];
184 then
185 done=0
186 fi
187 done
188 let loopcount=loopcount+1
189 sleep 1
190 done
191
192 kill -9 $pids
193 fi
194
195 rm pdns*.pid
196 exit $1
197 }
198
199 if [ ! -x $PDNS ]
200 then
201 echo "$PDNS is not executable binary"
202 exit
203 fi
204
205 if [ ! -x $PDNS2 ]
206 then
207 echo "$PDNS2 is not executable binary"
208 exit
209 fi
210
211 address="${PDNS_LISTEN_ADDR:-127.0.0.1}"
212 port=$1
213 [ -z "$port" ] && port=5300
214 context=$2
215 [ -z "$context" ] && context=bind-dnssec
216 wait=$3
217 [ -z "$wait" ] && wait=nowait
218 cachettl=$4
219 [ -z "$cachettl" ] && cachettl=0
220 spectest=$5
221
222 testsdir=./tests
223
224 for prog in $SDIG $SAXFR $NOTIFY $NSEC3DIG; do
225 if `echo $prog | grep -q '\.\./pdns'`; then
226 ${MAKE} -C ../pdns ${prog##*../pdns/} || exit
227 fi
228 done
229
230 # Copy original zones because the test might modify them (well only the dyndns stuff, but let's make this work for others as well)
231 for zone in $(grep 'zone ' named.conf | cut -f2 -d\")
232 do
233 if [ -f zones/$zone.orig ]
234 then
235 cp -f zones/$zone.orig zones/$zone
236 fi
237 done
238
239 rm -f pdns*.pid
240 rm -f *_tests
241 rm -f pdns-*.conf
242
243 presigned=no
244 both=no
245
246 if [[ "$context" =~ .+-presigned.* ]]
247 then
248 presigned=yes
249 port=$((port-100))
250 eval "$(echo "$context" | sed -r 's/(.+)(-presigned)(-(.*))?/context=\1 presignedcontext=\4/')"
251 if [ -z "$presignedcontext" ]
252 then
253 presignedcontext=$context
254 fi
255 fi
256
257 if [ "${context: -5}" = "-both" ]
258 then
259 both=yes
260 port=$((port-100))
261 context=${context%-both}
262 presignedcontext=$context
263 fi
264
265 optout=0
266 pkcs11=0
267
268 if [ "${context: -13}" = "-nsec3-optout" ]
269 then
270 optout=1
271 fi
272
273 if [ "${context: -7}" = "-pkcs11" ]
274 then
275 pkcs11=1
276 context=${context:0:-7}
277 fi
278
279 # check for lua
280 if $PDNS --version 2>&1 | grep Features: | grep -q "lua"
281 then
282 lua_prequery="--lua-prequery-script=./check_stest_source"
283 skiplua=0
284 else
285 lua_prequery=""
286 skiplua=1
287 fi
288
289 source backends/common
290
291 start_master
292
293 if [ "$skiplua" == "1" ]; then
294 skipreasons="$skipreasons nolua"
295 fi
296
297 check_process
298
299 dotests () {
300 nameserver=127.0.0.1 ./runtests $spectest
301 ./toxml
302 ./totar
303
304 cat ./trustedkeys
305
306 if [ -s "./failed_tests" ]
307 then
308 for t in `cat failed_tests`
309 do
310 echo -e "\n\n$t"
311 cat ${testsdir}/$t/diff
312 done
313 if [ "${!1}" -eq 0 ]
314 then
315 eval "$1=1"
316 fi
317 fi
318 }
319
320 ## TODO: give sdig a timeout
321
322 RETVAL=0
323
324 export address
325 export port
326 export context
327 export extracontexts
328 export skipreasons
329 export backend
330 export testsdir
331 export optout
332
333 sleep 2
334
335 if [ $presigned = no ] || [ $both = yes ]
336 then
337 dotests RETVAL
338 fi
339
340 if [ $presigned = yes ] || [ $both = yes ]
341 then
342 start_slave
343
344 export port
345 export context
346 export skipreasons
347 export backend
348
349 dotests RETVAL
350 fi
351
352 if [ "$wait" = "wait" ]
353 then
354 echo tests done! push enter to terminate instance
355 read l
356 fi
357
358 trap "kill_process $RETVAL" EXIT