🎉 Sync 2026-09-27 21:03:26

This commit is contained in:
github-actions[bot] committed 2026-09-27 21:03:26 +08:00
1 parent f4559bbed1
commit 065763f7fd
673 files changed
+261285 -34160

No files matched your search

@@ -0,0 +1,51 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only
#
# Direct unit tests for the firewall field validators
# (root/etc/homeproxy/scripts/firewall_utils.uc).
#
# Why a separate file rather than extending test_firewall_template.sh:
# the rendering test needs the device-only `fw4` ucode module, so on a
# development host it only runs the source-level glue precondition; it
# cannot exercise the validators themselves. The validators are pure
# functions, so a self-contained ucode test runs anywhere ucode runs.
# Together they are the report's H1: the renderer cannot regress
# silently because the validators are independently pinned here.
#
# Usage: sh tests/ucode/test_firewall_validators.sh <repo-root> [work-dir]
ROOT="${1:-.}"
WORK="${2:-/tmp/hp-firewall-validators-test}"
ROOT="$(cd "$ROOT" && pwd)"
if ! command -v ucode > "/dev/null" 2>&1; then
echo "NOT RUN: ucode is not on PATH."
echo " Build the testbed toolchain first (tests/toolchain/build-ucode-linux.sh)."
exit 2
fi
rm -rf "$WORK"
mkdir -p "$WORK"
# The validators import `isEmpty` from homeproxy.uc. Stage a copy that
# just exports it - the validators under test are the only thing this
# process exercises, so pulling in the full homeproxy.uc (with its
# validate_data / popen / luci.* imports) would break the unit test on
# a host that lacks /sbin/validate_data.
cat > "$WORK/homeproxy.uc" <<'HPEOF'
export function isEmpty(res) {
return !res || res === 'nil' || (type(res) in ['array', 'object'] && length(res) === 0);
};
HPEOF
cp "$ROOT/root/etc/homeproxy/scripts/firewall_utils.uc" "$WORK/firewall_utils.uc"
cp "$ROOT/tests/ucode/test_firewall_validators.uc" "$WORK/test_firewall_validators.uc"
if ( cd "$WORK" && ucode test_firewall_validators.uc ); then
echo "PASS: firewall field validators drop invalid entries"
exit 0
else
echo "FAIL: firewall field validators"
exit 1
fi