Home | History | Annotate | Line # | Download | only in nslookup
      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 
     14 set -e
     15 
     16 # shellcheck disable=SC2086
     17 . ../conf.sh
     18 
     19 status=0
     20 n=0
     21 
     22 n=$((n + 1))
     23 echo_i "Check that domain names that are too big when applying a search list entry are handled cleanly ($n)"
     24 ret=0
     25 l=012345678901234567890123456789012345678901234567890123456789012
     26 t=0123456789012345678901234567890123456789012345678901234567890
     27 d=$l.$l.$l.$t
     28 $NSLOOKUP -port=${PORT} -domain=$d -type=soa example 10.53.0.1 2>nslookup.err${n} >nslookup.out${n} || ret=1
     29 lines=$(wc -l <nslookup.err${n})
     30 test $lines -eq 0 || ret=1
     31 grep "origin = ns1.example" nslookup.out${n} >/dev/null || ret=1
     32 if [ $ret != 0 ]; then echo_i "failed"; fi
     33 status=$((status + ret))
     34 
     35 n=$((n + 1))
     36 echo_i "Check A only lookup ($n)"
     37 ret=0
     38 $NSLOOKUP -port=${PORT} a-only.example.net 10.53.0.1 2>nslookup.err${n} >nslookup.out${n} || ret=1
     39 lines=$(wc -l <nslookup.err${n})
     40 test $lines -eq 0 || ret=1
     41 lines=$(grep -c "Server:" nslookup.out${n})
     42 test $lines -eq 1 || ret=1
     43 lines=$(grep -c a-only.example.net nslookup.out${n})
     44 test $lines -eq 1 || ret=1
     45 grep "1.2.3.4" nslookup.out${n} >/dev/null || ret=1
     46 if [ $ret != 0 ]; then echo_i "failed"; fi
     47 status=$((status + ret))
     48 
     49 n=$((n + 1))
     50 echo_i "Check AAAA only lookup ($n)"
     51 ret=0
     52 $NSLOOKUP -port=${PORT} aaaa-only.example.net 10.53.0.1 2>nslookup.err${n} >nslookup.out${n} || ret=1
     53 lines=$(wc -l <nslookup.err${n})
     54 test $lines -eq 0 || ret=1
     55 lines=$(grep -c "Server:" nslookup.out${n})
     56 test $lines -eq 1 || ret=1
     57 lines=$(grep -c aaaa-only.example.net nslookup.out${n})
     58 test $lines -eq 1 || ret=1
     59 grep "2001::ffff" nslookup.out${n} >/dev/null || ret=1
     60 if [ $ret != 0 ]; then echo_i "failed"; fi
     61 status=$((status + ret))
     62 
     63 n=$((n + 1))
     64 echo_i "Check dual A + AAAA lookup ($n)"
     65 ret=0
     66 $NSLOOKUP -port=${PORT} dual.example.net 10.53.0.1 2>nslookup.err${n} >nslookup.out${n} || ret=1
     67 lines=$(wc -l <nslookup.err${n})
     68 test $lines -eq 0 || ret=1
     69 lines=$(grep -c "Server:" nslookup.out${n})
     70 test $lines -eq 1 || ret=1
     71 lines=$(grep -c dual.example.net nslookup.out${n})
     72 test $lines -eq 2 || ret=1
     73 grep "1.2.3.4" nslookup.out${n} >/dev/null || ret=1
     74 grep "2001::ffff" nslookup.out${n} >/dev/null || ret=1
     75 if [ $ret != 0 ]; then echo_i "failed"; fi
     76 status=$((status + ret))
     77 
     78 n=$((n + 1))
     79 echo_i "Check CNAME to A only lookup ($n)"
     80 ret=0
     81 $NSLOOKUP -port=${PORT} cname-a-only.example.net 10.53.0.1 2>nslookup.err${n} >nslookup.out${n} || ret=1
     82 lines=$(wc -l <nslookup.err${n})
     83 test $lines -eq 0 || ret=1
     84 lines=$(grep -c "Server:" nslookup.out${n})
     85 test $lines -eq 1 || ret=1
     86 lines=$(grep -c "canonical name" nslookup.out${n})
     87 test $lines -eq 1 || ret=1
     88 lines=$(grep a-only.example.net nslookup.out${n} | grep -cEv "(canonical name|^;;)")
     89 test $lines -eq 1 || ret=1
     90 grep "1.2.3.4" nslookup.out${n} >/dev/null || ret=1
     91 if [ $ret != 0 ]; then echo_i "failed"; fi
     92 status=$((status + ret))
     93 
     94 n=$((n + 1))
     95 echo_i "Check CNAME to AAAA only lookup ($n)"
     96 ret=0
     97 $NSLOOKUP -port=${PORT} cname-aaaa-only.example.net 10.53.0.1 2>nslookup.err${n} >nslookup.out${n} || ret=1
     98 lines=$(wc -l <nslookup.err${n})
     99 test $lines -eq 0 || ret=1
    100 lines=$(grep -c "Server:" nslookup.out${n})
    101 test $lines -eq 1 || ret=1
    102 lines=$(grep -c "canonical name" nslookup.out${n})
    103 test $lines -eq 1 || ret=1
    104 lines=$(grep aaaa-only.example.net nslookup.out${n} | grep -cEv "(canonical name|^;;)")
    105 test $lines -eq 1 || ret=1
    106 grep "2001::ffff" nslookup.out${n} >/dev/null || ret=1
    107 if [ $ret != 0 ]; then echo_i "failed"; fi
    108 status=$((status + ret))
    109 
    110 n=$((n + 1))
    111 echo_i "Check CNAME to dual A + AAAA lookup ($n)"
    112 ret=0
    113 $NSLOOKUP -port=${PORT} cname-dual.example.net 10.53.0.1 2>nslookup.err${n} >nslookup.out${n} || ret=1
    114 lines=$(wc -l <nslookup.err${n})
    115 test $lines -eq 0 || ret=1
    116 lines=$(grep -c "Server:" nslookup.out${n})
    117 test $lines -eq 1 || ret=1
    118 lines=$(grep -c "canonical name" nslookup.out${n})
    119 test $lines -eq 1 || ret=1
    120 lines=$(grep dual.example.net nslookup.out${n} | grep -cEv "(canonical name|^;;)")
    121 test $lines -eq 2 || ret=1
    122 grep "1.2.3.4" nslookup.out${n} >/dev/null || ret=1
    123 grep "2001::ffff" nslookup.out${n} >/dev/null || ret=1
    124 if [ $ret != 0 ]; then echo_i "failed"; fi
    125 status=$((status + ret))
    126 
    127 n=$((n + 1))
    128 echo_i "Check ANY lookup ($n)"
    129 ret=0
    130 $NSLOOKUP -port=${PORT} -type=ANY example.net 10.53.0.1 2>nslookup.err${n} >nslookup.out${n} || ret=1
    131 lines=$(grep -c 'Address:.10\.53\.0\.1#'"${PORT}" nslookup.out${n})
    132 test $lines -eq 1 || ret=1
    133 lines=$(grep -c 'origin = ns1\.example\.net' nslookup.out${n})
    134 test $lines -eq 1 || ret=1
    135 lines=$(grep -c 'mail addr = hostmaster\.example\.net' nslookup.out${n})
    136 test $lines -eq 1 || ret=1
    137 lines=$(grep -c 'nameserver = ns1\.example\.net.' nslookup.out${n})
    138 test $lines -eq 1 || ret=1
    139 if [ $ret != 0 ]; then echo_i "failed"; fi
    140 status=$((status + ret))
    141 
    142 echo_i "exit status: $status"
    143 [ $status -eq 0 ] || exit 1
    144