Tests: Pi-hole PTR generation check

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2021-10-04 12:14:13 +02:00
parent 695c7a9371
commit c87945ecf2
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
2 changed files with 38 additions and 0 deletions

32
test/hostnames.sh Normal file
View File

@ -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

View File

@ -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"* ]]
}