Debian Codegraph @

debian/tests/validation

raw
1 #!/bin/sh
2 # some ideas came from validation script of bind9
3 # https://sources.debian.org/src/bind9/1:9.17.19-3/debian/tests/validation
4
5 # not used `set -e' because dig can fail
6
7 # DNSA = authoritative DNS server
8 # DNSR = recursive DNS server
9
10 STATUS_ERROR=1
11 STATUS_SKIP=77
12
13 PORT_DNSA=53001
14 PORT_DNSR=53002
15 PORT_DNSPROXY=53000
16
17 setup() {
18 stop_dnsproxy
19 service named stop
20
21 start_dnsa
22 start_dnsr
23 start_dnsproxy
24 }
25
26 start_dnsa() {
27 named -u bind -p $PORT_DNSA -f &
28 pid_dnsa="$!"
29 }
30
31 start_dnsr() {
32 named -u bind -p $PORT_DNSR -f &
33 pid_dnsr="$!"
34 }
35
36 # $1 = pid of dnsa/dnsr
37 stop_dnsi() {
38 kill -9 $1
39 }
40
41 start_dnsproxy() {
42 service dnsproxy start
43 }
44
45 stop_dnsproxy() {
46 service dnsproxy stop
47 }
48
49 # remove 127.0.0.1 from allowed recursive queries
50 dnsproxy_conf_update() {
51 srcconf="/etc/dnsproxy.conf"
52 newconf="$AUTOPKGTEST_TMP/dnsproxy.conf"
53
54 # not used `sed' due lack of compatibility in multiple systems
55 head -n -1 $srcconf > $newconf
56 mv $newconf $srcconf
57 }
58
59 # $1 port to query
60 # $2 status to return on error
61 run_dig() {
62 port=$1
63 status=$2
64
65 MAXTRY=5
66 itry=0
67 while [ $itry -lt $MAXTRY ]; do
68 dig -x 127.0.0.1 @127.0.0.1 -p $port | grep -o \
69 'status: NOERROR' 2>/dev/null && break
70 itry=`expr $itry + 1`
71
72 sleep 1
73 done
74
75 if [ "$itry" -eq "$MAXTRY" ]; then
76 echo "dig query on port $port failed $MAXTRY times"
77 echo "ending $0 with status $status"
78 exit $status
79 fi
80 }
81
82 pretests() {
83 echo "PRETEST1: bind running with PID $pid_dnsa"
84 ps -p $pid_dnsa || exit $STATUS_SKIP
85
86 echo "PRETEST2: bind running with PID $pid_dnsr"
87 ps -p $pid_dnsr || exit $STATUS_SKIP
88
89 echo "PRETEST3: query bind on port $PORT_DNSA"
90 run_dig $PORT_DNSA $STATUS_SKIP
91
92 echo "PRETEST4: query bind on port $PORT_DNSR"
93 run_dig $PORT_DNSR $STATUS_SKIP
94 }
95
96 test1() {
97 echo "TEST1: dnsproxy with authoritative and recursive servers DNS servers"
98
99 run_dig $PORT_DNSPROXY $STATUS_ERROR
100 }
101
102 test2() {
103 echo "TEST2: dnsproxy with only a recursive server [UDP PORT=$PORT_DNSR]"
104
105 stop_dnsproxy
106 stop_dnsi $pid_dnsa
107 start_dnsproxy
108
109 run_dig $PORT_DNSPROXY $STATUS_ERROR
110 }
111
112 test3() {
113 echo "TEST3: dnsproxy with only an authoritative server [UDP PORT=$PORT_DNSA]"
114
115 stop_dnsproxy
116 stop_dnsi $pid_dnsr
117 start_dnsa
118 dnsproxy_conf_update
119 start_dnsproxy
120
121 run_dig $PORT_DNSPROXY $STATUS_ERROR
122 }
123
124 stop_at_end() {
125 stop_dnsi $pid_dnsa
126 stop_dnsproxy
127 }
128
129 ## main
130 setup
131 pretests
132 test1
133 test2
134 test3
135 stop_at_end
136
137 exit 0