From c87945ecf2fad378a183c15a25ddb7e166c4b55a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 4 Oct 2021 12:14:13 +0200 Subject: [PATCH] Tests: Pi-hole PTR generation check Signed-off-by: DL6ER --- test/hostnames.sh | 32 ++++++++++++++++++++++++++++++++ test/test_suite.bats | 6 ++++++ 2 files changed, 38 insertions(+) create mode 100644 test/hostnames.sh diff --git a/test/hostnames.sh b/test/hostnames.sh new file mode 100644 index 00000000..a988269d --- /dev/null +++ b/test/hostnames.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Test script to test names returned for local interfaces +# The logic of this mechanism has been extracted from piholeDebug.sh + +getIPs() { + local dig_result addr + local addr_type + addr_type=$1 + local protocol + protocol=$2 + + addresses="$(ip address show | sed "/${addr_type} /!d;s/^.*${addr_type} //g;s/\/.*$//g;")" + if [ -n "${addresses}" ]; then + while IFS= read -r addr ; do + # Check if Pi-hole can use itself to block a domain + dig_result=$(dig +tries=1 +time=2 -"${protocol}" -x "${addr}" @127.0.0.1 +short) + if [[ $addr == "127.0.0.1" && $dig_result == "localhost." ]] || [[ $addr == "::1" && $dig_result == "ip6-localhost." ]] || [[ $dig_result == "pi.hole." ]]; then + echo "${addr} is \"${dig_result}\": OK" + else + # Otherwise, show a failure + echo "${addr}: ERROR" + echo "${dig_result}" + echo "" + fi + done <<< "${addresses}" + fi +} + +# Test PTR responses on all available IPv4 addresses +getIPs inet 4 +# Test PTR responses on all available IPv6 addresses +getIPs inet6 6 diff --git a/test/test_suite.bats b/test/test_suite.bats index add8bc46..24a1dfb6 100644 --- a/test/test_suite.bats +++ b/test/test_suite.bats @@ -1283,3 +1283,9 @@ [[ ${lines[0]} == "Hello from LUA" ]] rm abc.lua } + +@test "Pi-hole PTR generation check" { + run bash -c "bash test/hostnames.sh | tee dig.log" + printf "%s\n" "${lines[@]}" + [[ "${lines[@]}" != *"ERROR"* ]] +}