mirror of
https://github.com/xroche/httrack.git
synced 2026-07-26 10:39:10 +03:00
The test scripts mostly ran with no error flags, so a failing command in
the middle would be ignored and the script would limp on to a misleading
result. Turn on strict mode everywhere, guarding the spots that legitimately
expect a non-zero exit:
- the htssafe overflow probes (-#8) deliberately abort, and the strsafe/
cmdline crawls capture an exit code to assert on, so those are run with
`|| true` / `|| rc=$?` rather than letting set -e kill the script first;
- the parser fixture crawl ignores httrack's own exit (it checks the mirrored
files), so it keeps `|| true`;
- 02_update-cache replaced `find ... | grep -q .` with a `-print -quit`
command substitution: under pipefail grep -q can close the pipe early and
leave find killed by SIGPIPE, which would spuriously fail an existing file;
- 12_crawl_https guards $HTTPS_SUPPORT with `${...:-}` for set -u.
02_manpage-regen and 01_engine-cache stay on `set -eu` (no pipefail): both are
run via $(BASH), which can be a plain POSIX /bin/sh where `set -o pipefail`
does not exist.
shellcheck clean; make check: 15 PASS, 7 SKIP (offline).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
94 lines
3.3 KiB
Bash
Executable File
94 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
|
|
# Offline command-line option tests (no network). The -F user-agent and -%X
|
|
# raw-header values used to be rejected past 126 / 256 bytes (#152); they are
|
|
# now bounded only by the general per-argument cap (HTS_CDLMAXSIZE). A value up
|
|
# to that cap is accepted on both the short (-F, -%X) and long (--user-agent,
|
|
# --headers) forms, and an over-cap value is refused cleanly rather than
|
|
# overrunning a fixed scratch buffer.
|
|
|
|
set -euo pipefail
|
|
|
|
tmp=$(mktemp -d "${TMPDIR:-/tmp}/httrack_cmdline.XXXXXX") || exit 1
|
|
trap 'rm -rf "$tmp"' EXIT HUP INT QUIT PIPE TERM
|
|
|
|
echo '<html><body>hello</body></html>' >"$tmp/index.html"
|
|
|
|
# a string of N repeated 'A' characters
|
|
nchars() {
|
|
printf 'A%.0s' $(seq 1 "$1")
|
|
}
|
|
|
|
# crawl the local fixture with the given extra args; leaves the exit status in RC
|
|
run() {
|
|
local out="$1"
|
|
shift
|
|
rm -rf "$out"
|
|
mkdir -p "$out"
|
|
RC=0
|
|
httrack "file://$tmp/index.html" -O "$out" --quiet -n "$@" >"$out/.log" 2>&1 || RC=$?
|
|
}
|
|
|
|
# crawl using exactly the given args as the only URL(s), no implicit primary URL;
|
|
# leaves the exit status in RC
|
|
run_only() {
|
|
local out="$1"
|
|
shift
|
|
rm -rf "$out"
|
|
mkdir -p "$out"
|
|
RC=0
|
|
httrack -O "$out" --quiet -n "$@" >"$out/.log" 2>&1 || RC=$?
|
|
}
|
|
|
|
# assert the value was accepted: clean exit and the fixture was mirrored
|
|
accepted() {
|
|
{ test "$RC" -eq 0 && test -n "$(find "$1" -type f -path '*/index.html' -print -quit)"; } ||
|
|
! echo "FAIL: $2 (exit $RC)" || exit 1
|
|
}
|
|
|
|
# assert the value was refused cleanly: a normal error exit, never a crash
|
|
# (a SIGABRT from an overflowed scratch buffer would surface as exit 134)
|
|
refused() {
|
|
{ test "$RC" -ne 0 && test "$RC" -ne 134; } ||
|
|
! echo "FAIL: $1 (exit $RC)" || exit 1
|
|
}
|
|
|
|
# a value past the old 126/256 caps but within the cap is accepted, on both the
|
|
# short and long form of each option
|
|
long=$(nchars 900)
|
|
run "$tmp/ua-s" -F "$long"
|
|
accepted "$tmp/ua-s" "#152: long -F user-agent rejected or crashed"
|
|
run "$tmp/ua-l" --user-agent "$long"
|
|
accepted "$tmp/ua-l" "#152: long --user-agent rejected or crashed"
|
|
run "$tmp/hd-s" "-%X" "X-A: $long"
|
|
accepted "$tmp/hd-s" "#152: long -%X header rejected or crashed"
|
|
run "$tmp/hd-l" --headers "X-B: $long"
|
|
accepted "$tmp/hd-l" "#152: long --headers rejected or crashed"
|
|
|
|
# a value just under the cap (>1000) must not overflow the long-form alias
|
|
# scratch buffer (the param[] copy in optalias_check)
|
|
run "$tmp/ua-n" --user-agent "$(nchars 1010)"
|
|
accepted "$tmp/ua-n" "#152: near-cap --user-agent overflowed the param[] buffer"
|
|
|
|
# a value over the cap is refused cleanly (graceful error, not a SIGABRT), on
|
|
# both forms
|
|
over=$(nchars 1100)
|
|
run "$tmp/ov-s" -F "$over"
|
|
refused "#152: over-cap -F not refused cleanly"
|
|
run "$tmp/ov-l" --user-agent "$over"
|
|
refused "#152: over-cap --user-agent not refused cleanly"
|
|
|
|
# Quote handling on the sole URL (run_only, so the quoted arg is the only URL and
|
|
# can't be masked by an implicit one). A fully "-quoted URL has its surrounding
|
|
# quotes stripped in place and is mirrored; a dangling opening quote, and a lone
|
|
# quote (empty after the opening "), are refused cleanly and never crash.
|
|
run_only "$tmp/q-ok" "\"file://$tmp/index.html\""
|
|
accepted "$tmp/q-ok" "quoted URL not stripped/mirrored"
|
|
run_only "$tmp/q-bad" '"foo'
|
|
refused "dangling-quote argument not refused cleanly"
|
|
run_only "$tmp/q-lone" '"'
|
|
refused "lone-quote argument not refused cleanly"
|
|
|
|
exit 0
|