Forráskód Böngészése

test: add A/B drop-in verification (v0.1.0 vs v0.2.0), document drop-in guarantee

ric 1 hónapja
szülő
commit
c536347f38
2 módosított fájl, 104 hozzáadás és 0 törlés
  1. 9 0
      CHANGELOG.md
  2. 95 0
      test/ab-dropin.sh

+ 9 - 0
CHANGELOG.md

@@ -20,6 +20,15 @@ All notable changes to this project are documented here.
   adopted vs. deliberately skipped improvements (DNSCrypt/libsodium, DoH/
   nghttp2, DNSTAP/protobuf-c, distroless final stage).
 
+### Verified
+- A/B drop-in test (`test/ab-dropin.sh`): v0.1.0 vs. v0.2.0 side by side
+  with identical config — 7/7: identical resolution, identical DNSSEC
+  AD-bit behavior, identical CHAOS/hide-identity behavior, identical
+  contract (uid 1500, port 5053, healthcheck, /config volume).
+  v0.2.0 is a pure drop-in for v0.1.0: only Dockerfile (build-time
+  integrity, hardening, feature flags) and tests/docs changed;
+  `config/`, `entrypoint.sh`, `docker-compose.yml` are untouched.
+
 ## [0.1.0] - 2026-10-23
 
 ### Added

+ 95 - 0
test/ab-dropin.sh

@@ -0,0 +1,95 @@
+#!/bin/sh
+# A/B drop-in test: unbound-sec:v0.1.0 vs. unbound-sec:test (v0.2.0)
+# Same config, same network, identical queries -> responses must match.
+set -u
+N=ubsec-ab
+C1=ab-v010
+C2=ab-v020
+CFG=$(pwd)/test/fixture-ab
+PASS=0
+FAIL=0
+ok()  { PASS=$((PASS+1)); printf '  [PASS] %s\n' "$1"; }
+bad() { FAIL=$((FAIL+1)); printf '  [FAIL] %s\n' "$1"; }
+
+cleanup() {
+  docker rm -f "$C1" "$C2" >/dev/null 2>&1
+  docker network rm "$N" >/dev/null 2>&1
+  rm -rf "$CFG"
+}
+trap cleanup EXIT
+
+cleanup
+docker network create "$N" >/dev/null
+mkdir -p "$CFG"
+printf 'server:\n  statistics-interval: 0\n' > "$CFG/99-ab.conf"
+
+docker run -d --name "$C1" --network "$N" \
+  --tmpfs "/run/unbound:uid=1500,gid=1500" -v "$CFG:/config:ro" \
+  unbound-sec:v0.1.0 >/dev/null
+docker run -d --name "$C2" --network "$N" \
+  --tmpfs "/run/unbound:uid=1500,gid=1500" -v "$CFG:/config:ro" \
+  unbound-sec:test >/dev/null
+sleep 4
+
+for c in "$C1" "$C2"; do
+  [ "$(docker inspect -f '{{.State.Running}}' "$c")" = "true" ] \
+    && ok "$c running" || { bad "$c running"; exit 1; }
+done
+
+# Extract the ANSWER section of a drill response (empty = no answers).
+ans() {
+  docker exec "$1" drill -p 5053 "$2" @127.0.0.1 2>/dev/null \
+    | awk '/;; ANSWER SECTION:/{f=1;next} /;; AUTHORITY SECTION:/{f=0} f && NF'
+}
+
+# 1. identical plain resolution
+a1="$(ans "$C1" example.com)"; a2="$(ans "$C2" example.com)"
+if [ -n "$a1" ] && [ "$a1" = "$a2" ]; then
+  ok "identical non-empty answer for example.com"
+else
+  bad "identical non-empty answer for example.com"
+  printf '    v0.1.0: %s\n    v0.2.0: %s\n' "$a1" "$a2"
+fi
+
+# 2. DNSSEC: AD bit must be set on both (raw DO-bit query via python probe)
+P() {
+  docker run --rm --network "$N" -v "$(pwd)/test/dns-check.py:/probe.py:ro" \
+    python:alpine python /probe.py "$1" 5053 2>&1
+}
+p1="$(P "$C1")"; p2="$(P "$C2")"
+if printf '%s' "$p1" | grep -q "PASS" && printf '%s' "$p2" | grep -q "PASS" \
+   && [ "$(printf '%s' "$p1" | grep -c PASS)" = "$(printf '%s' "$p2" | grep -c PASS)" ]; then
+  ok "DNSSEC AD-bit on both versions (identical probe results)"
+else
+  bad "DNSSEC AD-bit on both versions"
+  printf '    v0.1.0: %s\n    v0.2.0: %s\n' "$p1" "$p2"
+fi
+
+# 3. identity behavior identical (hide-identity: yes in base config)
+chaos() {
+  docker exec "$1" drill -p 5053 -C CHAOS id.server. @127.0.0.1 2>/dev/null \
+    | awk '/;; ANSWER SECTION:/{f=1;next} /;; AUTHORITY SECTION:/{f=0} f && NF'
+}
+c1="$(chaos "$C1")"; c2="$(chaos "$C2")"
+if [ -z "$c1" ] && [ -z "$c2" ]; then
+  ok "identical CHAOS id.server behavior (empty answer section, hide-identity)"
+else
+  bad "identical CHAOS id.server behavior (v0.1.0: '$c1' / v0.2.0: '$c2')"
+fi
+
+# 4. same user/port/healthcheck contract (from image metadata + runtime uid)
+for c in "$C1" "$C2"; do
+  uid="$(docker exec "$c" sh -c 'id -u')"
+  ports="$(docker inspect -f '{{json .Config.ExposedPorts}}' "$c")"
+  hc="$(docker inspect -f '{{json .Config.Healthcheck.Test}}' "$c")"
+  vol="$(docker inspect -f '{{json .Config.Volumes}}' "$c")"
+  if [ "$uid" = "1500" ] && printf '%s' "$ports" | grep -q '5053' \
+     && printf '%s' "$hc" | grep -q "5053" && printf '%s' "$vol" | grep -q '/config'; then
+    ok "$c contract: uid 1500, expose 5053, healthcheck 5053, volume /config"
+  else
+    bad "$c contract (uid=$uid ports=$ports hc=$hc vol=$vol)"
+  fi
+done
+
+printf '\nAB RESULT: %s passed, %s failed\n' "$PASS" "$FAIL"
+[ "$FAIL" -eq 0 ]