1#!/bin/sh 2 3# Copyright (C) Internet Systems Consortium, Inc. ("ISC") 4# 5# SPDX-License-Identifier: MPL-2.0 6# 7# This Source Code Form is subject to the terms of the Mozilla Public 8# License, v. 2.0. If a copy of the MPL was not distributed with this 9# file, you can obtain one at https://mozilla.org/MPL/2.0/. 10# 11# See the COPYRIGHT file distributed with this work for additional 12# information regarding copyright ownership. 13 14set -e 15 16. ../conf.sh 17 18status=0 19n=0 20 21DIGOPTS="-p ${PORT}" 22 23dig_cmd() { 24 # shellcheck disable=SC2086 25 "$DIG" $DIGOPTS "$@" | grep -v '^;' 26} 27 28n=$((n + 1)) 29echo_i "querying for various representations of an IN A record ($n)" 30for i in 1 2 3 4 5 6 7 8 9 10 11 12; do 31 ret=0 32 dig_cmd +short @10.53.0.1 a$i.example a in >dig.out.$i.test$n 33 echo 10.0.0.1 | diff - dig.out.$i.test$n || ret=1 34 if [ $ret != 0 ]; then 35 echo_i "#$i failed" 36 fi 37 status=$((status + ret)) 38done 39 40n=$((n + 1)) 41echo_i "querying for various representations of an IN TXT record ($n)" 42for i in 1 2 3 4 5 6 7; do 43 ret=0 44 dig_cmd +short @10.53.0.1 txt$i.example txt in >dig.out.$i.test$n 45 echo '"hello"' | diff - dig.out.$i.test$n || ret=1 46 if [ $ret != 0 ]; then 47 echo_i "#$i failed" 48 fi 49 status=$((status + ret)) 50done 51 52n=$((n + 1)) 53echo_i "querying for various representations of an IN TYPE123 record ($n)" 54for i in 1 2 3; do 55 ret=0 56 dig_cmd +short @10.53.0.1 unk$i.example type123 in >dig.out.$i.test$n 57 echo '\# 1 00' | diff - dig.out.$i.test$n || ret=1 58 if [ $ret != 0 ]; then 59 echo_i "#$i failed" 60 fi 61 status=$((status + ret)) 62done 63 64n=$((n + 1)) 65echo_i "querying for NULL record ($n)" 66ret=0 67dig_cmd +short @10.53.0.1 null.example null in >dig.out.test$n 68echo '\# 1 00' | diff - dig.out.test$n || ret=1 69[ $ret = 0 ] || echo_i "failed" 70status=$((status + ret)) 71 72n=$((n + 1)) 73echo_i "querying for empty NULL record ($n)" 74ret=0 75dig_cmd +short @10.53.0.1 empty.example null in >dig.out.test$n 76echo '\# 0' | diff - dig.out.test$n || ret=1 77[ $ret = 0 ] || echo_i "failed" 78status=$((status + ret)) 79 80n=$((n + 1)) 81echo_i "querying for various representations of a CLASS10 TYPE1 record ($n)" 82for i in 1 2; do 83 ret=0 84 dig_cmd +short @10.53.0.1 a$i.example a class10 >dig.out.$i.test$n 85 echo '\# 4 0A000001' | diff - dig.out.$i.test$n || ret=1 86 if [ $ret != 0 ]; then 87 echo_i "#$i failed" 88 fi 89 status=$((status + ret)) 90done 91 92n=$((n + 1)) 93echo_i "querying for various representations of a CLASS10 TXT record ($n)" 94for i in 1 2 3 4; do 95 ret=0 96 dig_cmd +short @10.53.0.1 txt$i.example txt class10 >dig.out.$i.test$n 97 echo '"hello"' | diff - dig.out.$i.test$n || ret=1 98 if [ $ret != 0 ]; then 99 echo_i "#$i failed" 100 fi 101 status=$((status + ret)) 102done 103 104n=$((n + 1)) 105echo_i "querying for various representations of a CLASS10 TYPE123 record ($n)" 106for i in 1 2; do 107 ret=0 108 dig_cmd +short @10.53.0.1 unk$i.example type123 class10 >dig.out.$i.test$n 109 echo '\# 1 00' | diff - dig.out.$i.test$n || ret=1 110 if [ $ret != 0 ]; then 111 echo_i "#$i failed" 112 fi 113 status=$((status + ret)) 114done 115 116n=$((n + 1)) 117echo_i "querying for SOAs of zone that should have failed to load ($n)" 118for i in 1 2 3 4; do 119 ret=0 120 $DIG $DIGOPTS @10.53.0.1 broken$i. soa in >dig.out.$i.test$n || ret=1 121 grep "SERVFAIL" dig.out.$i.test$n >/dev/null || ret=1 122 if [ $ret != 0 ]; then 123 echo_i "#$i failed" 124 fi 125 status=$((status + ret)) 126done 127 128n=$((n + 1)) 129echo_i "checking large unknown record loading on primary ($n)" 130for try in 0 1 2 3 4 5 6 7 8 9; do 131 ret=0 132 dig_cmd @10.53.0.1 +tcp +short large.example TYPE45234 >dig.out.$i.test$n 133 diff -s large.out dig.out.$i.test$n >/dev/null || { 134 ret=1 135 echo_i "diff failed" 136 } 137 [ "$ret" -eq 0 ] && break 138 sleep 1 139done 140[ $ret = 0 ] || echo_i "failed" 141status=$((status + ret)) 142 143n=$((n + 1)) 144echo_i "checking large unknown record loading on secondary ($n)" 145for try in 0 1 2 3 4 5 6 7 8 9; do 146 ret=0 147 dig_cmd @10.53.0.2 +tcp +short large.example TYPE45234 >dig.out.$i.test$n 148 diff -s large.out dig.out.$i.test$n >/dev/null || { 149 ret=1 150 echo_i "diff failed" 151 } 152 [ "$ret" -eq 0 ] && break 153 sleep 1 154done 155[ $ret = 0 ] || echo_i "failed" 156status=$((status + ret)) 157 158echo_i "stop and restart secondary" 159stop_server ns2 160start_server --noclean --restart --port ${PORT} ns2 161 162# server may be answering queries before zones are loaded, 163# so retry a few times if this query fails 164n=$((n + 1)) 165echo_i "checking large unknown record loading on secondary ($n)" 166for try in 0 1 2 3 4 5 6 7 8 9; do 167 ret=0 168 dig_cmd @10.53.0.2 +tcp +short large.example TYPE45234 >dig.out.$i.test$n 169 diff -s large.out dig.out.$i.test$n >/dev/null || { 170 ret=1 171 echo_i "diff failed" 172 } 173 [ "$ret" -eq 0 ] && break 174 sleep 1 175done 176[ $ret = 0 ] || echo_i "failed" 177status=$((status + ret)) 178 179n=$((n + 1)) 180echo_i "checking large unknown record loading on inline secondary ($n)" 181ret=0 182dig_cmd @10.53.0.3 +tcp +short large.example TYPE45234 >dig.out.test$n 183diff large.out dig.out.test$n >/dev/null || { 184 ret=1 185 echo_i "diff failed" 186} 187[ $ret = 0 ] || echo_i "failed" 188status=$((status + ret)) 189 190echo_i "stop and restart inline secondary" 191stop_server ns3 192start_server --noclean --restart --port ${PORT} ns3 193 194# server may be answering queries before zones are loaded, 195# so retry a few times if this query fails 196n=$((n + 1)) 197echo_i "checking large unknown record loading on inline secondary ($n)" 198for try in 0 1 2 3 4 5 6 7 8 9; do 199 ret=0 200 dig_cmd @10.53.0.3 +tcp +short large.example TYPE45234 >dig.out.$i.test$n 201 diff large.out dig.out.$i.test$n >/dev/null || { 202 ret=1 203 echo_i "diff failed" 204 } 205 [ "$ret" -eq 0 ] && break 206 sleep 1 207done 208[ $ret = 0 ] || echo_i "failed" 209status=$((status + ret)) 210 211n=$((n + 1)) 212echo_i "check that '"'"\\#"'"' is not treated as the unknown escape sequence ($n)" 213ret=0 214dig_cmd @10.53.0.1 +tcp +short txt8.example txt >dig.out.test$n 215echo '"#" "2" "0145"' | diff - dig.out.test$n || ret=1 216[ $ret = 0 ] || echo_i "failed" 217status=$((status + ret)) 218 219n=$((n + 1)) 220echo_i "check that 'TXT \# text' is not treated as the unknown escape sequence ($n)" 221ret=0 222dig_cmd @10.53.0.1 +tcp +short txt9.example txt >dig.out.test$n 223echo '"#" "text"' | diff - dig.out.test$n || ret=1 224[ $ret = 0 ] || echo_i "failed" 225status=$((status + ret)) 226 227n=$((n + 1)) 228echo_i "check that 'TYPE353 \# cat' produces 'not a valid number' ($n)" 229ret=0 230$CHECKZONE nan.bad zones/nan.bad >check.out 2>&1 && ret=1 231grep "not a valid number" check.out >/dev/null || ret=1 232[ $ret = 0 ] || echo_i "failed" 233status=$((status + ret)) 234 235echo_i "exit status: $status" 236[ $status -eq 0 ] || exit 1 237