fix(audit): emit valid zero counts without nounset failures
This commit is contained in:
@@ -39,3 +39,34 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
echo "$output" | python3 -c 'import json,sys; assert json.load(sys.stdin)["running_mdm_processes"] == 1'
|
||||
}
|
||||
|
||||
@test "text audit completes with zero profiles under nounset" {
|
||||
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
|
||||
source "$1/lib/colors.sh"
|
||||
source "$1/lib/status.sh"
|
||||
pf_status() { :; }
|
||||
deep_status
|
||||
' bash "$BATS_TEST_DIRNAME/.."
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Risk:"* ]]
|
||||
[[ "$output" != *"integer expression expected"* ]]
|
||||
}
|
||||
|
||||
@test "audit and report JSON contain numeric zero counts under nounset" {
|
||||
local module function_name field
|
||||
for module in status report; do
|
||||
if [ "$module" = status ]; then function_name=deep_status_json; field=profile_count;
|
||||
else function_name=generate_report_json; field=installed_profiles; fi
|
||||
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
|
||||
source "$1/lib/colors.sh"
|
||||
source "$1/lib/$2.sh"
|
||||
grep() {
|
||||
if [ "${1:-}" = -c ] && [ "${3:-}" = /private/etc/hosts ]; then echo 0; return 1; fi
|
||||
command grep "$@"
|
||||
}
|
||||
"$3"
|
||||
' bash "$BATS_TEST_DIRNAME/.." "$module" "$function_name"
|
||||
[ "$status" -eq 0 ]
|
||||
echo "$output" | python3 -c 'import json,sys; data=json.load(sys.stdin); assert data[sys.argv[1]] == 0; assert data.get("hosts_blocked",0) == 0' "$field"
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user