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