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