From 5bc58ff3719bbecdac6c98e99acecccb5d5f311a Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Fri, 20 Nov 2026 00:53:53 -0800 Subject: [PATCH 1/3] test: require the permission refusal in the restricted-admin apply check Follow-up to #115. The apply check for the existing `restricted` user only asserted that nothing was written. The placeholder plan id is rejected by the page whether or not the permission check runs, so the check passed without exercising it. #115 fixed the same weakness for `nodisabled` by also requiring the refusal text. Now the apply response must contain "do not cover every device" for `restricted` too, and the no-write assertion is a separate check. Signed-off-by: Thomas Vincent --- tests/permissions-e2e.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/permissions-e2e.sh b/tests/permissions-e2e.sh index cce4272..932e612 100644 --- a/tests/permissions-e2e.sh +++ b/tests/permissions-e2e.sh @@ -281,8 +281,9 @@ token=$(csrf restricted $INV) page_r=$(curl -s -b $WORK/restricted.jar -c $WORK/restricted.jar -F "__csrf_magic=$token" -F action=check -F format=yaml -F "config_file=@$WORK/conf-r.yaml" "$BASE/$CONF") check config-plan-refused-restricted-admin "an upload to check returns no plan" sh -c '! echo "$1" | grep -q "add target\|Apply Import\|Plan " && echo "$1" | grep -q "do not cover every device"' x "$page_r" token=$(csrf restricted $INV) -curl -s -b $WORK/restricted.jar -c $WORK/restricted.jar -o /dev/null --data-urlencode "__csrf_magic=$token" --data "action=apply&plan=0000000000000000" "$BASE/$CONF" -[ "$(q "SELECT COUNT(*) FROM plugin_smokeping_target WHERE path = 'Conf/restricted'" | jcell)" = 0 ] && result PASS config-apply-refused-restricted-admin "an apply post changes nothing" || result FAIL config-apply-refused-restricted-admin "a target was added" +apply_r=$(curl -s -b $WORK/restricted.jar -c $WORK/restricted.jar --data-urlencode "__csrf_magic=$token" --data "action=apply&plan=0000000000000000" "$BASE/$CONF") +check config-apply-refused-restricted-admin "an apply post is refused for device coverage, not as a bad plan" sh -c 'echo "$1" | grep -q "do not cover every device"' x "$apply_r" +[ "$(q "SELECT COUNT(*) FROM plugin_smokeping_target WHERE path = 'Conf/restricted'" | jcell)" = 0 ] && result PASS config-apply-writes-nothing-restricted-admin "an apply post changes nothing" || result FAIL config-apply-writes-nothing-restricted-admin "a target was added" printf 'schema_version: 1\ntargets:\n - path: Conf/new\n host: conf.example\n' > $WORK/conf-new.yaml n0=$(q "SELECT COUNT(*) FROM plugin_smokeping_target" | jcell) From 87aa81d970d8e783a8d72d4cd757a5b164e20fb9 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Fri, 20 Nov 2026 01:09:49 -0800 Subject: [PATCH 2/3] test: require the permission refusal in the restricted-admin import apply check imp_apply discarded the response, so the restricted import apply was only checked for writing nothing, which a stale plan id also satisfies. It now keeps the body in $WORK/imp-apply.out (callers are unchanged) and the restricted apply must contain "do not cover every device"; the no-write check stays separate. Signed-off-by: Thomas Vincent --- tests/permissions-e2e.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/permissions-e2e.sh b/tests/permissions-e2e.sh index 932e612..b39d85f 100644 --- a/tests/permissions-e2e.sh +++ b/tests/permissions-e2e.sh @@ -334,10 +334,10 @@ imp_preview() { # imp_preview -> the preview page token=$(csrf "$1" $IMP) curl -s -b "$WORK/$1.jar" -c "$WORK/$1.jar" -F "__csrf_magic=$token" -F action=preview -F source=upload -F device_per=host -F poller=1 -F site=0 -F tree=-1 -F "tree_name=SmokePing Web" -F "smokeping_file=@$2" "$BASE/$IMP" } -imp_apply() { # imp_apply [no-token] +imp_apply() { # imp_apply [no-token]; the response body is kept in $WORK/imp-apply.out token=$(csrf "$1" $IMP) [ "${3:-}" = no-token ] && token= - curl -s -b "$WORK/$1.jar" -c "$WORK/$1.jar" -o /dev/null --data-urlencode "__csrf_magic=$token" --data "action=apply&plan=$2&source=upload&device_per=host&poller=1&site=0&tree=-1" --data-urlencode "tree_name=SmokePing Web" "$BASE/$IMP" + curl -s -b "$WORK/$1.jar" -c "$WORK/$1.jar" -o "$WORK/imp-apply.out" --data-urlencode "__csrf_magic=$token" --data "action=apply&plan=$2&source=upload&device_per=host&poller=1&site=0&tree=-1" --data-urlencode "tree_name=SmokePing Web" "$BASE/$IMP" } page=$(imp_preview admin $WORK/imp.conf) @@ -354,6 +354,7 @@ imp_apply admin "$plan" no-token imp_apply admin 0000000000000000 imp_apply scoped "$plan" imp_apply restricted "$plan" +check import-apply-refused-restricted-admin "an apply post is refused for device coverage, not as a stale plan" sh -c 'grep -q "do not cover every device" "$1"' x "$WORK/imp-apply.out" [ "$(imp_rows)" = "0 0 0 0" ] && result PASS import-apply-refusals "no token, a plan never shown, no realm, and limited devices all write nothing" || result FAIL import-apply-refusals "$(imp_rows)" page=$(imp_preview admin $WORK/imp.conf) plan=$(echo "$page" | sed -n 's/.*name=.plan. value=.\([0-9a-f]\{16\}\).*/\1/p' | head -1) From b9d896c362b34fc2603617973dfde430ba80fdcb Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Fri, 20 Nov 2026 01:19:06 -0800 Subject: [PATCH 3/3] test: assign imp_apply parameters to named variables Signed-off-by: Thomas Vincent --- tests/permissions-e2e.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/permissions-e2e.sh b/tests/permissions-e2e.sh index b39d85f..7ac94b5 100644 --- a/tests/permissions-e2e.sh +++ b/tests/permissions-e2e.sh @@ -335,9 +335,10 @@ imp_preview() { # imp_preview -> the preview page curl -s -b "$WORK/$1.jar" -c "$WORK/$1.jar" -F "__csrf_magic=$token" -F action=preview -F source=upload -F device_per=host -F poller=1 -F site=0 -F tree=-1 -F "tree_name=SmokePing Web" -F "smokeping_file=@$2" "$BASE/$IMP" } imp_apply() { # imp_apply [no-token]; the response body is kept in $WORK/imp-apply.out - token=$(csrf "$1" $IMP) - [ "${3:-}" = no-token ] && token= - curl -s -b "$WORK/$1.jar" -c "$WORK/$1.jar" -o "$WORK/imp-apply.out" --data-urlencode "__csrf_magic=$token" --data "action=apply&plan=$2&source=upload&device_per=host&poller=1&site=0&tree=-1" --data-urlencode "tree_name=SmokePing Web" "$BASE/$IMP" + apply_user=$1; apply_plan=$2; apply_flag=${3:-} + token=$(csrf "$apply_user" $IMP) + [ "$apply_flag" = no-token ] && token= + curl -s -b "$WORK/$apply_user.jar" -c "$WORK/$apply_user.jar" -o "$WORK/imp-apply.out" --data-urlencode "__csrf_magic=$token" --data "action=apply&plan=$apply_plan&source=upload&device_per=host&poller=1&site=0&tree=-1" --data-urlencode "tree_name=SmokePing Web" "$BASE/$IMP" } page=$(imp_preview admin $WORK/imp.conf)