new_version

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-19 11:09:13 +02:00
1 parent 910bb563f0
commit a946c38194
32 files changed
+809 -65

No files matched your search

+28 -2
View File
@@ -39,7 +39,9 @@ PY
# Isolate the rc.d argument composition without running FreeBSD-only commands.
cat > "$WORK/rc.subr" <<'EOF'
load_rc_config() { :; }
run_rc_command() { printf '%s\n' "$command_args"; }
run_rc_command() {
if [ "$1" = reload ]; then "$reload_cmd"; else printf '%s\n' "$command_args"; fi
}
EOF
python3 - "$RC" "$WORK/rc-test" "$WORK" <<'PY'
from pathlib import Path
@@ -67,6 +69,26 @@ assert_interval 604800
printf 'enabled="1"\n' > "$WORK/opnsense.conf"
args=$(sh "$WORK/rc-test" start)
[[ "$args" == *'--update-check-interval-secs 3600 serve'* ]] || exit 1
# Exercise the rc.d soft reload itself with a live mock child and CLI.
mkdir -p "$WORK/bin"
cat > "$WORK/bin/mock-cli" <<'EOF'
#!/bin/sh
printf '%s\n' "$*" > "$TEST_CLI_ARGS"
EOF
chmod +x "$WORK/bin/mock-cli"
printf 'enabled="1"\nrustproxy_config_path="/usr/local/etc/rustproxy/config.json"\n' > "$WORK/opnsense.conf"
echo "$$" > "$WORK/rustproxy.pid"
export TEST_CLI_ARGS="$WORK/cli-args"
rustproxy_run_dir="$WORK" rustproxy_command="$WORK/bin/mock-cli" sh "$WORK/rc-test" reload
args=$(cat "$TEST_CLI_ARGS")
[[ "$args" == *'--data-dir /var/db/rustproxy'* ]]
[[ "$args" == *'--config /usr/local/etc/rustproxy/config.json'* ]]
[[ "$args" == *'--admin-listen 127.0.0.1:9090 reload'* ]]
printf 'enabled="1"\nrustproxy_config_path="/usr/local/etc/rustproxy/config.json;touch /tmp/bad"\n' > "$WORK/opnsense.conf"
if rustproxy_run_dir="$WORK" rustproxy_command="$WORK/bin/mock-cli" sh "$WORK/rc-test" reload >/dev/null 2>&1; then
echo 'Unsafe OPNsense config path was accepted' >&2; exit 1
fi
for invalid in 0 59 604801 nope '1;touch /tmp/pwn'; do
printf 'enabled="1"\nrustproxy_update_check_interval_secs="%s"\n' "$invalid" > "$WORK/opnsense.conf"
if sh "$WORK/rc-test" start >/dev/null 2>&1; then
@@ -90,6 +112,7 @@ case "$1" in
status) [ -f "$TEST_PID" ] ;;
onestart) printf 'start\n' >> "$TEST_LOG"; touch "$TEST_PID" ;;
onestop) printf 'stop\n' >> "$TEST_LOG"; rm -f "$TEST_PID" ;;
reload) printf 'reload\n' >> "$TEST_LOG" ;;
*) exit 1 ;;
esac
EOF
@@ -114,6 +137,9 @@ ENABLED=1 "$WORK/hook-test"
[[ $(grep -cx start "$TEST_LOG") == 1 ]] || { echo 'Boot did not start service' >&2; exit 1; }
ENABLED=1 "$WORK/hook-test"
[[ $(grep -cx start "$TEST_LOG") == 1 ]] || { echo 'Duplicate supervisor start' >&2; exit 1; }
ENABLED=1 "$WORK/service-test" reload
[[ $(grep -cx reload "$TEST_LOG") == 1 ]] || { echo 'Soft reload not passed through' >&2; exit 1; }
[[ $(grep -cx stop "$TEST_LOG" || true) == 0 ]] || { echo 'Soft reload restarted service' >&2; exit 1; }
rm -f "$TEST_PID"
ENABLED=0 "$WORK/hook-test"
[[ $(grep -cx start "$TEST_LOG") == 1 ]] || { echo 'Disabled service started' >&2; exit 1; }
@@ -122,4 +148,4 @@ if FAIL_RENDER=1 ENABLED=1 "$WORK/hook-test" >/dev/null 2>&1; then
fi
[[ $(grep -cx start "$TEST_LOG") == 1 ]] || { echo 'Started despite failed template rendering' >&2; exit 1; }
echo 'OPNsense boot / update interval checks: OK'
echo 'OPNsense boot / update interval / soft reload checks: OK'