summaryrefslogtreecommitdiffstats
path: root/bin/tests/system/pending/tests.sh
blob: 362cef3ef85d971b34359121b00bcfae6bd70d2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/sh

# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0.  If a copy of the MPL was not distributed with this
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.

set -e

. ../conf.sh

# replace_data dname RR old_data new_data
replace_data()
{
	if [ $# -ne 4 ]; then
		echo_i "unexpected input for replace_data"
		return 1
	fi

	_dname=$1
	_rr=$2
	_olddata=$3
	_newdata=$4

	_ret=0
	$NSUPDATE -d <<END >> nsupdate.out.test 2>&1 || _ret=1
server 10.53.0.2 ${PORT}
update delete ${_dname} 30 ${_rr} ${_olddata}
update add ${_dname} 30 ${_rr} ${_newdata}
send
END

	if [ $_ret != 0 ]; then
		echo_i "failed to update the test data"
		return 1
	fi

	return 0
}

status=0
n=0

DIGOPTS="+short +tcp -p ${PORT}"
DIGOPTS_CD="$DIGOPTS +cd"

echo_i "Priming cache."
ret=0
expect="10 mail.example."
ans=$($DIG $DIGOPTS_CD @10.53.0.4 hostile MX) || ret=1
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

echo_i "Checking that bogus additional is not returned with +CD."
ret=0
expect="10.0.0.2"
ans=$($DIG $DIGOPTS_CD @10.53.0.4 mail.example A) || ret=1
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

#
# Prime cache with pending additional records.  These should not be promoted
# to answer.
#
echo_i "Priming cache (pending additional A and AAAA)"
ret=0
expect="10 mail.example.com."
ans=$($DIG $DIGOPTS @10.53.0.4 example.com MX) || ret=1
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

echo_i "Replacing pending A"
ret=0
replace_data mail.example.com. A 192.0.2.2 192.0.2.3 || ret=1
status=$((status + ret))

echo_i "Replacing pending AAAA"
ret=0
replace_data mail.example.com. AAAA 2001:db8::2 2001:db8::3 || ret=1
status=$((status + ret))

echo_i "Checking updated data to be returned (without CD)"
ret=0
expect="192.0.2.3"
ans=$($DIG $DIGOPTS @10.53.0.4 mail.example.com A) || ret=1
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

echo_i "Checking updated data to be returned (with CD)"
ret=0
expect="2001:db8::3"
ans=$($DIG $DIGOPTS_CD @10.53.0.4 mail.example.com AAAA) || ret=1
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

#
# Prime cache with a pending answer record.  It can be returned (without
# validation) with +CD.
#
echo_i "Priming cache (pending answer)"
ret=0
expect="192.0.2.2"
ans=$($DIG $DIGOPTS_CD @10.53.0.4 pending-ok.example.com A) || ret=1
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

echo_i "Replacing pending data"
ret=0
replace_data pending-ok.example.com. A 192.0.2.2 192.0.2.3 || ret=1
status=$((status + ret))

echo_i "Confirming cached pending data to be returned with CD"
ret=0
expect="192.0.2.2"
ans=$($DIG $DIGOPTS_CD @10.53.0.4 pending-ok.example.com A) || ret=1
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

#
# Prime cache with a pending answer record.  It should not be returned
# to no-DNSSEC clients.
#
echo_i "Priming cache (pending answer)"
ret=0
expect="192.0.2.102"
ans=$($DIG $DIGOPTS_CD @10.53.0.4 pending-ng.example.com A) || ret=1
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

echo_i "Replacing pending data"
ret=0
replace_data pending-ng.example.com. A 192.0.2.102 192.0.2.103 || ret=1
status=$((status + ret))

echo_i "Confirming updated data returned, not the cached one, without CD"
ret=0
expect="192.0.2.103"
ans=$($DIG $DIGOPTS @10.53.0.4 pending-ng.example.com A) || ret=1
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

#
# Try to fool the resolver with an out-of-bailiwick CNAME
#
echo_i "Trying to Prime out-of-bailiwick pending answer with CD"
ret=0
expect="10.10.10.10"
ans=$($DIG $DIGOPTS_CD @10.53.0.4 bad.example. A) || ret=1
ans=$(echo $ans | awk '{print $NF}')
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

echo_i "Confirming the out-of-bailiwick answer is not cached or reused with CD"
ret=0
expect="10.10.10.10"
ans=$($DIG $DIGOPTS_CD @10.53.0.4 nice.good. A) || ret=1
ans=$(echo $ans | awk '{print $NF}')
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

#
# Make sure the resolver doesn't cache bogus NXDOMAIN
#
echo_i "Trying to Prime bogus NXDOMAIN"
ret=0
expect="SERVFAIL"
ans=$($DIG +tcp -p ${PORT} @10.53.0.4 removed.example.com. A) || ret=1
ans=$(echo $ans | sed 's/^.*status: \([A-Z][A-Z]*\).*$/\1/')
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

echo_i "Confirming the bogus NXDOMAIN was not cached"
ret=0
expect="SERVFAIL"
ans=$($DIG +tcp -p ${PORT} @10.53.0.4 removed.example.com. A) || ret=1
ans=$(echo $ans | sed 's/^.*status: \([A-Z][A-Z]*\).*$/\1/')
test "$ans" = "$expect" || ret=1
test $ret = 0 || echo_i "failed, got '$ans', expected '$expect'"
status=$((status + ret))

echo_i "exit status: $status"
[ $status -eq 0 ] || exit 1