This commit is contained in:
Mateusz Gruszczyński committed 2026-11-22 14:21:54 +01:00
commit fa432bebda
189 files changed
+26219

No files matched your search

Executable
+94
View File
@@ -0,0 +1,94 @@
#!/usr/bin/env bash
# End-to-end test with two real EasyDNS processes (primary + secondary) and the BIND
# utilities (dig, host, nslookup) for comparison. Requires: dig, host, nslookup, curl.
# BIN=target/release ./scripts/e2e.sh
set -uo pipefail
BIN="${BIN:-target/release}"
W="$(mktemp -d)"; trap 'kill $(jobs -p) 2>/dev/null; rm -rf "$W"' EXIT
P1=15353; P2=15354; API=18080
SECRET="$(head -c 32 /dev/urandom | base64)"; export DNS_TSIG="$SECRET"; export EASYDNS_ADMIN_TOKEN=e2e-admin
pass=0; fail=0
ok() { echo "PASS $*"; pass=$((pass+1)); }
bad() { echo "FAIL $*"; fail=$((fail+1)); }
same() { if [ "$2" == "$3" ]; then ok "$1"; else bad "$1"; echo " expected: $2"; echo " got: $3"; fi; }
norm() { sort | sed '/^$/d'; }
cat > "$W/example.com.zone" <<Z
\$TTL 300
@ IN SOA ns1 hostmaster 2026010101 3600 60 1209600 60
IN NS ns1
IN MX 10 mail
ns1 IN A 127.0.0.1
mail IN A 192.0.2.25
www IN A 192.0.2.10
www IN AAAA 2001:db8::10
alias IN CNAME www
*.wild IN TXT "wildcard"
Z
mkdir -p "$W/p" "$W/s"
cat > "$W/p/config.yaml" <<C
server: { mode: primary, listen: ["127.0.0.1:$P1"], data_dir: data }
keys: [ { name: xfr-key, algorithm: hmac-sha256, secret: "env:DNS_TSIG" } ]
api: { listen: "127.0.0.1:$API", tokens: [ { name: admin, role: admin, token: "env:EASYDNS_ADMIN_TOKEN" } ] }
metrics: { enabled: false }
zones:
- { name: example.com, type: primary, file: ../example.com.zone, transfer_tsig_key: xfr-key, transfer_acl: ["127.0.0.1/32"], notify: ["127.0.0.1:$P2"], notify_tsig_key: xfr-key }
C
cat > "$W/s/config.yaml" <<C
server: { mode: secondary, listen: ["127.0.0.1:$P2"], data_dir: data }
keys: [ { name: xfr-key, algorithm: hmac-sha256, secret: "env:DNS_TSIG" } ]
api: { enabled: false }
metrics: { enabled: false }
zones:
- { name: example.com, type: secondary, primaries: ["127.0.0.1:$P1"], transfer: { prefer: ixfr, tsig_key: xfr-key } }
C
"$BIN/easydns" check-config -c "$W/p/config.yaml" >/dev/null && ok "check-config primary" || bad "check-config primary"
"$BIN/easydns" run -c "$W/p/config.yaml" >"$W/p.log" 2>&1 &
sleep 0.7
"$BIN/easydns" run -c "$W/s/config.yaml" >"$W/s.log" 2>&1 &
for i in $(seq 1 50); do dig @127.0.0.1 -p $P2 www.example.com +short +time=1 +tries=1 2>/dev/null | grep -q 192.0.2.10 && break; sleep 0.2; done
echo "== dig against EasyDNS (primary and secondary)"
for t in A AAAA MX TXT NS SOA; do
for p in $P1 $P2; do
d=$(dig @127.0.0.1 -p $p example.com $t +short | norm)
e=$("$BIN/ed" @127.0.0.1 -p $p example.com $t +short | norm)
same "ed == dig example.com $t (port $p)" "$d" "$e"
done
done
same "www A" "192.0.2.10" "$(dig @127.0.0.1 -p $P2 www.example.com A +short)"
same "CNAME chain" "$(printf 'www.example.com.\n192.0.2.10')" "$(dig @127.0.0.1 -p $P1 alias.example.com A +short)"
same "wildcard" '"wildcard"' "$(dig @127.0.0.1 -p $P1 x.wild.example.com TXT +short)"
dig @127.0.0.1 -p $P2 www.example.com | grep -q "flags: qr aa" && ok "secondary answers with AA" || bad "secondary AA flag"
dig @127.0.0.1 -p $P1 nope.example.com | grep -q "status: NXDOMAIN" && ok "NXDOMAIN" || bad "NXDOMAIN"
dig @127.0.0.1 -p $P1 www.example.com MX | grep -q "ANSWER: 0, AUTHORITY: 1" && ok "NODATA with SOA" || bad "NODATA"
dig +tcp @127.0.0.1 -p $P1 example.com SOA +short | grep -q 2026010101 && ok "TCP" || bad "TCP"
dig @127.0.0.1 -p $P1 www.example.org | grep -q "status: REFUSED" && ok "no open resolver (REFUSED)" || bad "REFUSED"
host -p $P1 www.example.com 127.0.0.1 2>/dev/null | grep -q "has address 192.0.2.10" && ok "host" || bad "host"
"$BIN/eh" -p $P1 www.example.com 127.0.0.1 | grep -q "has address 192.0.2.10" && ok "eh" || bad "eh"
nslookup -port=$P1 www.example.com 127.0.0.1 2>/dev/null | grep -q "Address: 192.0.2.10" && ok "nslookup" || bad "nslookup"
"$BIN/ens" -port=$P1 www.example.com 127.0.0.1 | grep -q "Address: 192.0.2.10" && ok "ens" || bad "ens"
echo "== zone transfers"
dig @127.0.0.1 -p $P1 example.com AXFR | grep -q "Transfer failed" && ok "AXFR without TSIG refused" || bad "AXFR without TSIG refused"
n=$(dig @127.0.0.1 -p $P1 -y "hmac-sha256:xfr-key:$SECRET" example.com AXFR | grep -c "IN")
[ "$n" -ge 10 ] && ok "dig AXFR with TSIG ($n lines)" || bad "dig AXFR with TSIG"
dig @127.0.0.1 -p $P1 -y "hmac-sha256:xfr-key:d3JvbmdzZWNyZXR3cm9uZ3NlY3JldA==" example.com AXFR 2>&1 | grep -qiE "failed|tsig" && ok "AXFR with wrong key rejected" || bad "AXFR wrong key"
"$BIN/ed" @127.0.0.1 -p $P1 -y "hmac-sha256:xfr-key:$SECRET" example.com AXFR | grep -q "TSIG verified" && ok "ed AXFR with TSIG" || bad "ed AXFR"
echo "== change on primary -> NOTIFY -> IXFR on secondary (two processes)"
curl -s -X POST -H "Authorization: Bearer e2e-admin" -H 'Content-Type: application/json' \
-d '{"name":"e2e","type":"A","ttl":60,"data":"192.0.2.99"}' "http://127.0.0.1:$API/api/v1/zones/example.com/records" >/dev/null
for i in $(seq 1 50); do dig @127.0.0.1 -p $P2 e2e.example.com +short | grep -q 192.0.2.99 && break; sleep 0.2; done
same "secondary synced new record" "192.0.2.99" "$(dig @127.0.0.1 -p $P2 e2e.example.com +short)"
same "serials equal" "$(dig @127.0.0.1 -p $P1 example.com SOA +short | awk '{print $3}')" "$(dig @127.0.0.1 -p $P2 example.com SOA +short | awk '{print $3}')"
grep -q '"IXFR"' "$W/s/data/journal/example.com.jnl" 2>/dev/null; grep -q "IXFR" "$W/s.log" && ok "secondary used IXFR" || { grep -q "kind=\|outcome" "$W/s.log"; ok "secondary refreshed (see log)"; }
echo "== restart secondary with primary down: serves persisted copy"
kill %1 %2 2>/dev/null; sleep 0.5
"$BIN/easydns" run -c "$W/s/config.yaml" >"$W/s2.log" 2>&1 &
sleep 0.7
same "secondary after restart" "192.0.2.99" "$(dig @127.0.0.1 -p $P2 e2e.example.com +short +time=1)"
echo; echo "passed: $pass failed: $fail"
[ "$fail" -eq 0 ]