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# shellcheck disable=SC2086
17. ../conf.sh
18
19status=0
20n=0
21
22n=$((n + 1))
23echo_i "Check A only lookup ($n)"
24ret=0
25$HOST -p ${PORT} a-only.example.net 10.53.0.1 2>host.err${n} >host.out${n} || ret=1
26lines=$(wc -l <host.err${n})
27test $lines -eq 0 || ret=1
28lines=$(grep -c "Address:" host.out${n})
29test $lines -eq 1 || ret=1
30lines=$(grep -c a-only.example.net host.out${n})
31test $lines -eq 1 || ret=1
32grep "1.2.3.4" host.out${n} >/dev/null || ret=1
33if [ $ret != 0 ]; then echo_i "failed"; fi
34status=$((status + ret))
35
36n=$((n + 1))
37echo_i "Check AAAA only lookup ($n)"
38ret=0
39$HOST -p ${PORT} aaaa-only.example.net 10.53.0.1 2>host.err${n} >host.out${n} || ret=1
40lines=$(wc -l <host.err${n})
41test $lines -eq 0 || ret=1
42lines=$(grep -c "Address:" host.out${n})
43test $lines -eq 1 || ret=1
44lines=$(grep -c aaaa-only.example.net host.out${n})
45test $lines -eq 1 || ret=1
46grep "2001::ffff" host.out${n} >/dev/null || ret=1
47if [ $ret != 0 ]; then echo_i "failed"; fi
48status=$((status + ret))
49
50n=$((n + 1))
51echo_i "Check dual A + AAAA lookup ($n)"
52ret=0
53$HOST -p ${PORT} dual.example.net 10.53.0.1 2>host.err${n} >host.out${n} || ret=1
54lines=$(wc -l <host.err${n})
55test $lines -eq 0 || ret=1
56lines=$(grep -c "Address:" host.out${n})
57test $lines -eq 1 || ret=1
58lines=$(grep -c dual.example.net host.out${n})
59test $lines -eq 2 || ret=1
60grep "1.2.3.4" host.out${n} >/dev/null || ret=1
61grep "2001::ffff" host.out${n} >/dev/null || ret=1
62if [ $ret != 0 ]; then echo_i "failed"; fi
63status=$((status + ret))
64
65n=$((n + 1))
66echo_i "Check CNAME to A only lookup ($n)"
67ret=0
68$HOST -p ${PORT} cname-a-only.example.net 10.53.0.1 2>host.err${n} >host.out${n} || ret=1
69lines=$(wc -l <host.err${n})
70test $lines -eq 0 || ret=1
71lines=$(grep -c "Address:" host.out${n})
72test $lines -eq 1 || ret=1
73lines=$(grep -c "cname-a-only.example.net is an alias for a-only.example.net" host.out${n})
74test $lines -eq 1 || ret=1
75lines=$(grep a-only.example.net host.out${n} | grep -cv "is an alias for")
76test $lines -eq 1 || ret=1
77grep "1.2.3.4" host.out${n} >/dev/null || ret=1
78if [ $ret != 0 ]; then echo_i "failed"; fi
79status=$((status + ret))
80
81n=$((n + 1))
82echo_i "Check CNAME to AAAA only lookup ($n)"
83ret=0
84$HOST -p ${PORT} cname-aaaa-only.example.net 10.53.0.1 2>host.err${n} >host.out${n} || ret=1
85lines=$(wc -l <host.err${n})
86test $lines -eq 0 || ret=1
87lines=$(grep -c "Address:" host.out${n})
88test $lines -eq 1 || ret=1
89lines=$(grep -c "cname-aaaa-only.example.net is an alias for aaaa-only.example.net" host.out${n})
90test $lines -eq 1 || ret=1
91lines=$(grep aaaa-only.example.net host.out${n} | grep -cv "is an alias for")
92test $lines -eq 1 || ret=1
93grep "2001::ffff" host.out${n} >/dev/null || ret=1
94if [ $ret != 0 ]; then echo_i "failed"; fi
95status=$((status + ret))
96
97n=$((n + 1))
98echo_i "Check CNAME to dual A + AAAA lookup ($n)"
99ret=0
100$HOST -p ${PORT} cname-dual.example.net 10.53.0.1 2>host.err${n} >host.out${n} || ret=1
101lines=$(wc -l <host.err${n})
102test $lines -eq 0 || ret=1
103lines=$(grep -c "Address:" host.out${n})
104test $lines -eq 1 || ret=1
105lines=$(grep -c "cname-dual.example.net is an alias for dual.example.net." host.out${n})
106test $lines -eq 1 || ret=1
107lines=$(grep -c "dual.example.net has address 1.2.3.4" host.out${n})
108test $lines -eq 1 || ret=1
109lines=$(grep -c "dual.example.net has IPv6 address 2001::ffff" host.out${n})
110test $lines -eq 1 || ret=1
111if [ $ret != 0 ]; then echo_i "failed"; fi
112status=$((status + ret))
113
114n=$((n + 1))
115echo_i "Check ANY lookup ($n)"
116ret=0
117$HOST -p ${PORT} -t ANY example.net 10.53.0.1 2>host.err${n} >host.out${n} || ret=1
118lines=$(grep -c 'Address:.10\.53\.0\.1#'"${PORT}" host.out${n})
119test $lines -eq 1 || ret=1
120lines=$(grep -c 'example.net has SOA record ns1.example.net. hostmaster.example.net. 1397051952 5 5 1814400 3600' host.out${n})
121test $lines -eq 1 || ret=1
122lines=$(grep -c 'example.net name server ns1.example.net.' host.out${n})
123test $lines -eq 1 || ret=1
124if [ $ret != 0 ]; then echo_i "failed"; fi
125status=$((status + ret))
126
127echo_i "exit status: $status"
128[ $status -eq 0 ] || exit 1
129