Repository navigation
fix: address the review findings left open when #98 merged #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
71a7118
4d97441
f72449c
9d8bb8d
bbffdce
49b3d00
e994160
d6f0295
35cbc00
8691de9
5b7a103
27b550e
4a10237
5915b4e
2aa1848
187e28f
ebe640f
e67a298
d8c51b8
5fa359c
918faf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # Test tools/environments/probe-reachability.sh with stub curl and ldd | ||
| # executables, so no network is used. The stub curl reproduces what curl 8.5 | ||
| # was measured to do (2026-11-04) against servers that ignore a byte range: | ||
| # with --max-filesize it stops and exits 63, still reporting the status code. | ||
| # Checks: a non-GNU ldd does not stop the probe; --get passes the size cap | ||
| # and reports a capped transfer as range-ignored; outcomes are classified; | ||
| # --json is valid; an unknown argument exits 2. Needs jq. | ||
| set -euo pipefail | ||
|
|
||
| repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
| probe="$repo_root/tools/environments/probe-reachability.sh" | ||
| work="$(mktemp -d)" | ||
| trap 'rm -rf "$work"' EXIT | ||
| fail() { echo "FAIL: $*" >&2; exit 1; } | ||
|
|
||
| mkdir -p "$work/bin" | ||
| cat > "$work/hosts.txt" <<'EOF' | ||
| # comment line | ||
| https://range-ignoring.test/big.bin | ||
| https://honours-range.test/file | ||
| https://refusing.test/api | ||
| https://bad-cert.test/ | ||
| EOF | ||
|
|
||
| # Stub curl: the URL is the last argument; -w '%{http_code}' output goes to | ||
| # stdout, as with the real curl. | ||
| cat > "$work/bin/curl" <<'SH' | ||
| #!/bin/sh | ||
| args="$*" | ||
| for url in "$@"; do :; done | ||
| case "$args" in *" -r 0-0 "*) mode=get ;; *" -I "*) mode=head ;; *) echo "stub curl: no method in: $args" >&2; exit 97 ;; esac | ||
| if [ "$mode" = get ]; then | ||
| case "$args" in *"--max-filesize 65536"*) ;; *) echo "stub curl: GET without size cap" >&2; exit 97 ;; esac | ||
| fi | ||
| case "$url" in | ||
| https://range-ignoring.test/*) printf 200; [ "$mode" = get ] && exit 63; exit 0 ;; | ||
| https://honours-range.test/*) [ "$mode" = get ] && printf 206 || printf 200; exit 0 ;; | ||
| https://refusing.test/*) printf 403; exit 0 ;; | ||
| https://bad-cert.test/*) printf 000; exit 60 ;; | ||
| esac | ||
| printf 000; exit 6 | ||
| SH | ||
| # A FreeBSD-style ldd: exists, rejects --version. | ||
| printf '#!/bin/sh\necho "ldd: illegal option -- -" >&2\nexit 1\n' > "$work/bin/ldd" | ||
| chmod +x "$work/bin/curl" "$work/bin/ldd" | ||
|
|
||
| run() { PATH="$work/bin:$PATH" HOSTS_FILE="$work/hosts.txt" bash "$probe" "$@"; } | ||
| row() { grep -Eq "^$1 +$2 +$3\$" <<<"$4" || fail "expected '$1 $2 $3' in: $4"; } | ||
|
Check warning on line 50 in tests/probe_reachability_test.sh
|
||
|
|
||
| head_out="$(run)" || fail "HEAD probe exited non-zero with a non-GNU ldd" | ||
| grep -q 'glibc' <<<"$head_out" && fail "non-GNU ldd reported as glibc" | ||
| row 200 reachable 'https://range-ignoring\.test/big\.bin' "$head_out" | ||
| row 403 refused 'https://refusing\.test/api' "$head_out" | ||
| row 000 tls-failed 'https://bad-cert\.test/' "$head_out" | ||
|
|
||
| get_out="$(run --get)" || fail "GET probe exited non-zero" | ||
| row 200 range-ignored 'https://range-ignoring\.test/big\.bin' "$get_out" | ||
| row 206 reachable 'https://honours-range\.test/file' "$get_out" | ||
|
|
||
| json="$(run --json --get)" || fail "JSON probe exited non-zero" | ||
| jq -e '.method == "get" and (.hosts | length) == 4 and | ||
| ([.hosts[].outcome] | sort) == ["range-ignored","reachable","refused","tls-failed"]' \ | ||
| <<<"$json" >/dev/null || fail "JSON output wrong: $json" | ||
|
|
||
| rc=0; run --bogus >/dev/null 2>&1 || rc=$? | ||
| [ "$rc" -eq 2 ] || fail "unknown argument exited $rc, expected 2" | ||
|
Check failure on line 68 in tests/probe_reachability_test.sh
|
||
|
|
||
| echo 'PASS: probe tolerates non-GNU ldd, caps range-ignoring GETs, classifies outcomes' | ||
Uh oh!
There was an error while loading. Please reload this page.