fix(validate): scan the checkout that holds the sensitive-source scanner
scan-platform-sensitive-source.sh always scanned the fixed path
/home/donghyeon/workspace/platform, and its list of shell files with
embedded Python held the same fixed paths. Run from a temporary copy
or a CI runner, it scanned the desktop checkout instead of itself, or
nothing at all. Its own test failed at the first assertion in any
other checkout: the test file lost its embedded-Python context there
and was reported as a credential literal.
The platform root is now the checkout that contains the scanner
(dirname of BASH_SOURCE, physical path), and the embedded-Python list
is resolved under that root. The central documentation root stays the
desktop default. --docs-root DIR replaces it and --platform-only skips
it, for a copy or runner that has no central docs. A missing docs root
stops with exit 2 and names both options instead of scanning less.
Rejected: a --platform-root option. Scanning a tree with a scanner
from another tree would let a scanned tree differ from the rules that
scan it.
Risk: on the desktop host the default run is unchanged. A caller that
passed arguments before got usage and exit 2. It now gets the new
options.
Verification: on desktop, a non-canonical clone of main 205927f with
this change: test-scan-platform-sensitive-source.sh passes. Before the
change the same test in a worktree copy failed with "canonical scanner
test content leaf found a credential literal".
This commit is contained in:
@@ -1468,6 +1468,39 @@ output="$(run_scanner 2>&1)" || scanner_error_rc=$?
|
||||
fail 'scanner error did not fail closed'
|
||||
}
|
||||
pass 'rg errors fail closed'
|
||||
PLATFORM_SENSITIVE_SOURCE_TEST_PATH=''
|
||||
|
||||
[[ "$PLATFORM_SENSITIVE_SOURCE_SELF_ROOT" == "$ROOT" ]] || \
|
||||
fail 'the scanner does not scan the checkout it lives in'
|
||||
pass 'the scanner scans the checkout it lives in, not a fixed path'
|
||||
main_rc=0
|
||||
main_output="$(scan_platform_sensitive_source_main --unknown 2>&1)" || main_rc=$?
|
||||
(( main_rc == 2 )) || fail 'an unknown entrypoint argument was accepted'
|
||||
main_rc=0
|
||||
main_output="$(scan_platform_sensitive_source_main --docs-root relative/docs 2>&1)" || main_rc=$?
|
||||
(( main_rc == 2 )) || fail 'a relative docs root was accepted'
|
||||
new_fixture
|
||||
main_rc=0
|
||||
main_output="$(scan_platform_sensitive_source_main --docs-root "$WORK/missing-docs" 2>&1)" || main_rc=$?
|
||||
(( main_rc == 2 )) || fail 'a missing docs root was accepted'
|
||||
[[ "$main_output" == *'--platform-only'* ]] || \
|
||||
fail 'a missing docs root did not name --platform-only'
|
||||
pass 'the entrypoint rejects unknown, relative and missing docs roots before scanning'
|
||||
printf 'ordinary input\n' >"$WORK/platform/bootstrap/ordinary.md"
|
||||
platform_only_output="$(scan_platform_sensitive_roots "$WORK/platform" '' 2>&1)" || {
|
||||
printf '%s\n' "$platform_only_output" >&2
|
||||
fail 'a platform-only root scan failed'
|
||||
}
|
||||
[[ "$platform_only_output" == *'PLATFORM SENSITIVE SOURCE SCAN PASS'* ]] || \
|
||||
fail 'a platform-only root scan did not emit the PASS marker'
|
||||
printf 'Slack: https://hooks.%s/services/T1/B2/C3\n' 'slack.com' \
|
||||
>"$WORK/platform/bootstrap/live.env"
|
||||
platform_only_rc=0
|
||||
platform_only_output="$(scan_platform_sensitive_roots "$WORK/platform" '' 2>&1)" || platform_only_rc=$?
|
||||
(( platform_only_rc != 0 )) || fail 'a platform-only root scan accepted a Slack webhook'
|
||||
[[ "$platform_only_output" == *'platform/bootstrap/live.env'* ]] || \
|
||||
fail 'a platform-only root scan did not report the filename'
|
||||
pass 'a platform-only root scan still scans the platform root'
|
||||
|
||||
cleanup_before="$(
|
||||
find /tmp -maxdepth 1 -type d -name 'platform-sensitive-source-test.??????' \
|
||||
|
||||
Reference in New Issue
Block a user