Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/infra/test/reach-reject.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / infra / test / reach-reject.sh` 67 lines ยท 2865 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # Negative control for smoke.sh reach. A name or address that is not safe to paste into a 3 # remote shell is refused before dig, ssh or curl run. A real IPv4 address is not refused, 4 # and the certificate check passes the name as an argument instead of inside the script. 5 # bash infra/test/reach-reject.sh 6 set -u 7 INFRA=$(cd "$(dirname "$0")/.." && pwd) 8 T=$(mktemp -d) 9 trap 'rm -rf "$T"' EXIT 10 pass=0; fail=0 11 ok() { pass=$((pass+1)); echo "PASS $*"; } 12 bad() { fail=$((fail+1)); echo "FAIL $*"; } 13 MARKER=$T/called 14 mkdir -p "$T/bin" 15 cat > "$T/bin/stub" <> "$MARKER" 18 exit 0 19 EOF 20 chmod 755 "$T/bin/stub" 21 ln -s stub "$T/bin/dig" 22 ln -s stub "$T/bin/ssh" 23 ln -s stub "$T/bin/curl" 24 25 reject() { # reject LABEL EXPECT RC-CHECK... 26 local label=$1 expect=$2; shift 2 27 : > "$MARKER" 28 rm -f "$T/pwned" 29 out=$(PATH="$T/bin:$PATH" REACH_OUTSIDE=0 timeout 10 "$@" 2>&1); rc=$? 30 if [ "$rc" = 3 ] && printf '%s\n' "$out" | grep -q "$expect" && [ ! -s "$MARKER" ] && [ ! -e "$T/pwned" ]; then 31 ok "$label" 32 else 33 bad "$label rc $rc marker=$(wc -c < "$MARKER" 2>/dev/null || echo missing) out=$(printf '%s' "$out" | tail -n 1)" 34 fi 35 } 36 37 SMOKE=(bash "$INFRA/smoke.sh" reach) 38 reject "quote in name refused, nothing queried" "not a DNS name" "${SMOKE[@]}" "x';touch $T/pwned;echo '" 39 reject "space in name refused, nothing queried" "not a DNS name" "${SMOKE[@]}" "bad name" 40 reject "quote in REACH_ADDR refused, nothing queried" "not an IPv4 address" \ 41 env REACH_ADDR="1.2.3.4'" "${SMOKE[@]}" interplane.io 42 reject "short REACH_ADDR refused, nothing queried" "not an IPv4 address" \ 43 env REACH_ADDR=1.2.3 "${SMOKE[@]}" interplane.io 44 reject "dot-only REACH_ADDR refused, nothing queried" "not an IPv4 address" \ 45 env REACH_ADDR=.... "${SMOKE[@]}" interplane.io 46 reject "octet 999 refused, nothing queried" "not an IPv4 address" \ 47 env REACH_ADDR=999.1.1.1 "${SMOKE[@]}" interplane.io 48 reject "five-part REACH_ADDR refused, nothing queried" "not an IPv4 address" \ 49 env REACH_ADDR=192.0.2.1.9 "${SMOKE[@]}" interplane.io 50 51 : > "$MARKER" 52 out=$(PATH="$T/bin:$PATH" REACH_OUTSIDE=0 REACH_ADDR=192.0.2.1 timeout 15 bash "$INFRA/smoke.sh" reach interplane.io 2>&1); rc=$? 53 if grep -q '/ssh ' "$MARKER" && ! grep -q '/dig ' "$MARKER"; then 54 ok "valid IPv4 is queried (ssh called, dig not)" 55 else 56 bad "valid IPv4 query shape rc $rc marker=$(cat "$MARKER")" 57 fi 58 if grep -q 'servername' "$MARKER" && grep -q '\$2' "$MARKER" && ! grep -q "servername 'interplane.io'" "$MARKER" \ 59 && grep -q '192.0.2.1' "$MARKER"; then 60 ok "cert check passes address and name as arguments" 61 else 62 bad "cert command was interpolated: $(grep -m1 servername "$MARKER" || echo none)" 63 fi 64 [ "$rc" = 3 ] && ok "dead address still fails reach (rc 3)" || bad "dead address rc $rc (want 3)" 65 66 echo "reach-reject: $pass passed, $fail failed" 67 [ "$fail" = 0 ]