hns_doh_loadbalancer/upstream.sh
Nathan Woodburn 95fd1044ac
All checks were successful
Build Docker / Build Docker (push) Successful in 23s
feat: Add providers to index page
2023-12-16 17:19:42 +11:00

56 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# This script is used to test an upstream server.
# Also can test with
# So test using https://dohjs.org/
# Get name of server from command line
SERVER=$1
# Test Domains
TXTDOMAIN="test.apihns"
HTTPDOMAIN="nathan.woodburn"
# Test DNS over HTTPS via GET request
GetStandard=$(curl --silent -H 'accept: application/dns-json' 'https://'$SERVER'/dns-query?name='$TXTDOMAIN'&type=TXT')
# Verify that the response is not empty and has an answer of TXT with content "DNS SUCCESS"
test=$(jq -e '.Answer[] | select(.type == 16)' <<< $GetStandard)
if [[ $test == *"DNS SUCCESS"* ]]; then
echo "DNS over HTTPS GET plain request test passed with content:"
echo $test | jq .
else
echo "DNS over HTTPS GET plain request test failed"
fi
# Test using curl
curltest=$(curl --silent --doh-url https://$SERVER/dns-query http://$HTTPDOMAIN)
# Verify that the response is not empty and has text "Nathan.Woodburn/"
if [[ $curltest == *"Nathan.Woodburn/"* ]]; then
echo "DNS over HTTPS curl test passed"
else
echo "DNS over HTTPS curl test failed"
fi
# Test DoT
# Get the IP address of the server
IP=$(dig +short $SERVER)
# Test using kdig
kdigtest=$(kdig +tls-ca +tls-host=$SERVER $TXTDOMAIN @$IP TXT)
# Verify that the response is not empty and has text "DNS SUCCESS"
if [[ $kdigtest == *"DNS SUCCESS"* ]]; then
echo "DNS over TLS kdig test passed"
else
echo "DNS over TLS kdig test failed"
fi
# Plain DNS
# Test using dig
digtest=$(dig $TXTDOMAIN @$SERVER TXT)
# Verify that the response is not empty and has text "DNS SUCCESS"
if [[ $digtest == *"DNS SUCCESS"* ]]; then
echo "Plain DNS dig test passed"
else
echo "Plain DNS dig test failed"
fi