fix(cli): avoid target access during previews (#38)

Return before volume access in suppression previews
This commit is contained in:
2026-10-30 11:33:30 -03:00
3 changed files with 53 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bats
run_preview() {
local script="$1" command="$2" recovery="$3"
local definitions="$BATS_TEST_TMPDIR/preview.functions"
sed '/^main "\$@"$/d' "$script" > "$definitions"
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
source "$1"
action="$2" recovery="$3"
load_config() { :; }
is_recovery() { return "$recovery"; }
resolve_data_volume() { echo TARGET_WAS_ACCESSED; return 97; }
main --dry-run "$action"
' "$script" "$definitions" "$command" "$recovery"
}
@test "suppress and bypass dry runs return before target resolution" {
local entrypoint action
for entrypoint in unleash unleash-standalone.sh; do
for action in suppress bypass; do
run_preview "$BATS_TEST_DIRNAME/../$entrypoint" "$action" 0
[ "$status" -eq 0 ]
[[ "$output" == *"[DRY RUN]"* ]]
[[ "$output" != *"TARGET_WAS_ACCESSED"* ]]
done
done
}
@test "bypass dry run still rejects a booted OS" {
local entrypoint
for entrypoint in unleash unleash-standalone.sh; do
run_preview "$BATS_TEST_DIRNAME/../$entrypoint" bypass 1
[ "$status" -ne 0 ]
[[ "$output" == *"Full bypass must run from Recovery mode"* ]]
[[ "$output" != *"TARGET_WAS_ACCESSED"* ]]
done
}
+8
View File
@@ -178,6 +178,10 @@ cmd_version() {
cmd_bypass() { cmd_bypass() {
if is_recovery; then if is_recovery; then
if [ "$DRY_RUN" = true ]; then
full_bypass_mode "the selected Data volume"
return
fi
header "Full MDM Bypass" header "Full MDM Bypass"
local data_mount local data_mount
data_mount=$(resolve_data_volume) data_mount=$(resolve_data_volume)
@@ -188,6 +192,10 @@ cmd_bypass() {
} }
cmd_suppress() { cmd_suppress() {
if [ "$DRY_RUN" = true ]; then
suppress_only_mode "the selected Data volume"
return
fi
header "Suppress Enrollment" header "Suppress Enrollment"
local data_mount local data_mount
data_mount=$(resolve_data_volume) data_mount=$(resolve_data_volume)
+8
View File
@@ -2968,6 +2968,10 @@ cmd_version() {
cmd_bypass() { cmd_bypass() {
if is_recovery; then if is_recovery; then
if [ "$DRY_RUN" = true ]; then
full_bypass_mode "the selected Data volume"
return
fi
header "Full MDM Bypass" header "Full MDM Bypass"
local data_mount local data_mount
data_mount=$(resolve_data_volume) data_mount=$(resolve_data_volume)
@@ -2978,6 +2982,10 @@ cmd_bypass() {
} }
cmd_suppress() { cmd_suppress() {
if [ "$DRY_RUN" = true ]; then
suppress_only_mode "the selected Data volume"
return
fi
header "Suppress Enrollment" header "Suppress Enrollment"
local data_mount local data_mount
data_mount=$(resolve_data_volume) data_mount=$(resolve_data_volume)