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