mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-11 07:57:51 +08:00
✨ Sync 2026-09-19 17:06:32
This commit is contained in:
1 parent
cee0877435
commit
d1cbb03aed
8 files changed
+251
-7
No files matched your search
@@ -81,6 +81,68 @@ else
|
||||
FAILED=1
|
||||
fi
|
||||
|
||||
echo "== wget flavour selection =="
|
||||
# A stub /usr/bin/wget whose --version answer comes from the environment, so
|
||||
# both flavours can be exercised on a single host. The empty-answer/non-zero
|
||||
# case is uclient-fetch, whose getopt rejects --version just like it rejects
|
||||
# -nv before sending anything.
|
||||
rm -rf "$WORK/wget_flavor"
|
||||
mkdir -p "$WORK/wget_flavor"
|
||||
cat > "$WORK/wget_flavor/wget-stub" <<'STUB'
|
||||
#!/bin/sh
|
||||
if [ "$1" = "--version" ]; then
|
||||
printf '%s\n' "$HP_WGET_STUB_VERSION"
|
||||
exit "${HP_WGET_STUB_VERSION_RC:-0}"
|
||||
fi
|
||||
for arg in "$@"; do printf '%s\n' "$arg"; done >> "$HP_WGET_STUB_LOG"
|
||||
printf 'stub body\n'
|
||||
STUB
|
||||
chmod +x "$WORK/wget_flavor/wget-stub"
|
||||
sed "s|/usr/bin/wget|$WORK/wget_flavor/wget-stub|" \
|
||||
"$ROOT/root/etc/homeproxy/scripts/homeproxy.uc" > "$WORK/wget_flavor/homeproxy.uc"
|
||||
cp "$ROOT/tests/ucode/test_wget_flavor.uc" "$WORK/wget_flavor/"
|
||||
|
||||
for flavor in gnu compat; do
|
||||
if [ "$flavor" = "gnu" ]; then
|
||||
version="GNU Wget 1.25.0 built on linux-gnu."
|
||||
rc=0
|
||||
else
|
||||
version=""
|
||||
rc=1
|
||||
fi
|
||||
rm -f "$WORK/wget_flavor/args.log"
|
||||
if ( cd "$WORK/wget_flavor" &&
|
||||
HP_WGET_EXPECT_FLAVOR="$flavor" \
|
||||
HP_WGET_STUB_VERSION="$version" \
|
||||
HP_WGET_STUB_VERSION_RC="$rc" \
|
||||
HP_WGET_STUB_LOG="$WORK/wget_flavor/args.log" \
|
||||
ucode test_wget_flavor.uc ); then
|
||||
echo "PASS: wget flavour selection ($flavor)"
|
||||
else
|
||||
echo "FAIL: wget flavour selection ($flavor)"
|
||||
FAILED=1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "== real uclient-fetch compatibility =="
|
||||
# uclient-fetch is the default /usr/bin/wget on OpenWrt/ImmortalWrt, so a
|
||||
# GNU-only option anywhere in the generated command line has to fail here.
|
||||
if [ -x /bin/uclient-fetch ]; then
|
||||
rm -rf "$WORK/uclient"
|
||||
mkdir -p "$WORK/uclient"
|
||||
sed "s|/usr/bin/wget|/bin/uclient-fetch|" \
|
||||
"$ROOT/root/etc/homeproxy/scripts/homeproxy.uc" > "$WORK/uclient/homeproxy.uc"
|
||||
cp "$ROOT/tests/ucode/test_wget_verbose_uclient.uc" "$WORK/uclient/"
|
||||
if ( cd "$WORK/uclient" && ucode test_wget_verbose_uclient.uc ); then
|
||||
echo "PASS: uclient-fetch accepts the generated command line"
|
||||
else
|
||||
echo "FAIL: uclient-fetch rejects the generated command line"
|
||||
FAILED=1
|
||||
fi
|
||||
else
|
||||
echo "SKIP: /bin/uclient-fetch not installed on this host"
|
||||
fi
|
||||
|
||||
echo "== generator regression tests =="
|
||||
sh "$ROOT/tests/ucode/test_generators.sh" "$ROOT" "$WORK/generators" || FAILED=1
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/ucode
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* Copyright (C) 2026 ImmortalWrt.org
|
||||
*
|
||||
* Regression tests for the wget flavour probe and for the command line
|
||||
* wGETVerbose() builds from it.
|
||||
*
|
||||
* OpenWrt/ImmortalWrt's default /usr/bin/wget is uclient-fetch, which rejects
|
||||
* GNU-only flags such as -nv with "unrecognized option: n" *before* it opens a
|
||||
* connection, so a single GNU-ism turns every subscription update into
|
||||
* "no valid node found". run.sh stages a copy of homeproxy.uc whose
|
||||
* /usr/bin/wget points at a stub; HP_WGET_STUB_VERSION steers the answer of
|
||||
* the `--version` probe (empty output plus a non-zero exit mimics
|
||||
* uclient-fetch, whose getopt rejects the option and returns 1).
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { readfile } from 'fs';
|
||||
import { classifyWgetFlavor, wGETVerbose, wgetFlavor } from 'homeproxy';
|
||||
|
||||
let failures = 0, checks = 0;
|
||||
|
||||
function expect(name, actual, want) {
|
||||
checks++;
|
||||
if (sprintf('%J', actual) !== sprintf('%J', want)) {
|
||||
printf('FAIL %s: expected %J, got %J\n', name, want, actual);
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
|
||||
function has(list, value) {
|
||||
for (let v in list)
|
||||
if (v === value)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* The value following the first occurrence of `key` */
|
||||
function after(list, key) {
|
||||
let prev = null;
|
||||
|
||||
for (let v in list) {
|
||||
if (prev === key)
|
||||
return v;
|
||||
|
||||
prev = v;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Classification of the `wget --version` probe. */
|
||||
expect('gnu.version', classifyWgetFlavor(0, 'GNU Wget 1.25.0 built on linux-gnu.\n'), 'gnu');
|
||||
expect('gnu.multiline', classifyWgetFlavor(0, "GNU Wget 1.21.4 built on linux-gnu.\n\nCopyright (C) 2015 Free Software Foundation.\n"), 'gnu');
|
||||
expect('uclient.rejects-version', classifyWgetFlavor(1, null), 'compat');
|
||||
expect('busybox.version', classifyWgetFlavor(0, 'BusyBox v1.36.1 (2024-01-01) multi-call binary.\n'), 'compat');
|
||||
expect('empty.stdout', classifyWgetFlavor(0, ''), 'compat');
|
||||
expect('missing.binary', classifyWgetFlavor(127, null), 'compat');
|
||||
|
||||
/* wgetFlavor() probes the stub and caches the answer. */
|
||||
const want_flavor = getenv('HP_WGET_EXPECT_FLAVOR');
|
||||
expect('flavor', wgetFlavor(), want_flavor);
|
||||
expect('flavor.cached', wgetFlavor(), want_flavor);
|
||||
|
||||
const res = wGETVerbose('https://example.invalid/subs?token=abc', 'HomeProxy test UA');
|
||||
expect('content', res.content, 'stub body');
|
||||
expect('error', res.error, null);
|
||||
|
||||
const log = readfile(getenv('HP_WGET_STUB_LOG'));
|
||||
const args = log ? split(trim(log), '\n') : [];
|
||||
|
||||
expect('agent flag', has(args, '-U'), true);
|
||||
expect('agent value', after(args, '-U'), 'HomeProxy test UA');
|
||||
expect('timeout flag', after(args, '-T'), '10');
|
||||
expect('output flag', has(args, '-O-'), true);
|
||||
expect('url', has(args, 'https://example.invalid/subs?token=abc'), true);
|
||||
|
||||
/* -nv is GNU wget's --no-verbose; every other wget on the target rejects it,
|
||||
* and -q is the meter switch they all share. */
|
||||
expect('meter flag', has(args, want_flavor === 'gnu' ? '-nv' : '-q'), true);
|
||||
expect('no gnu-only flag', has(args, '-nv'), want_flavor === 'gnu');
|
||||
expect('no long options', has(args, '--user-agent') || has(args, '--timeout=10'), false);
|
||||
|
||||
printf('%d checks, %d failures\n', checks, failures);
|
||||
exit(failures === 0 ? 0 : 1);
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/ucode
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* Copyright (C) 2026 ImmortalWrt.org
|
||||
*
|
||||
* Feeds the command line wGETVerbose() builds to the target's real
|
||||
* uclient-fetch - the default /usr/bin/wget on OpenWrt/ImmortalWrt. run.sh
|
||||
* rewrites the module's wget path to /bin/uclient-fetch and skips this file
|
||||
* where that binary does not exist.
|
||||
*
|
||||
* A closed loopback port is the entire request: what matters is that
|
||||
* uclient-fetch gets past getopt. Before the flavour probe existed it did not -
|
||||
* `-nv` made it print "unrecognized option: n" and exit before the request was
|
||||
* sent, so every subscription fetch came back empty. Any failure observed here
|
||||
* must therefore come from the network, never from the option parser.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { wGETVerbose, wgetFlavor } from 'homeproxy';
|
||||
|
||||
let failures = 0, checks = 0;
|
||||
|
||||
function expect(name, actual, want) {
|
||||
checks++;
|
||||
if (sprintf('%J', actual) !== sprintf('%J', want)) {
|
||||
printf('FAIL %s: expected %J, got %J\n', name, want, actual);
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
|
||||
/* uclient-fetch has no --version and rejects it, so it is classified compat. */
|
||||
expect('flavor', wgetFlavor(), 'compat');
|
||||
|
||||
const res = wGETVerbose('http://127.0.0.1:1/subs', 'HomeProxy test UA');
|
||||
expect('no content', res.content, null);
|
||||
expect('not an option error', match(res.error || '', /unrecognized option/) == null, true);
|
||||
expect('error carries the exit code', match(res.error || '', /^wget exited with status \d+: /) != null, true);
|
||||
|
||||
printf('%d checks, %d failures\n', checks, failures);
|
||||
exit(failures === 0 ? 0 : 1);
|
||||
Reference in new issue
Block a user