From ec1da9c4d70359527be448a1a6bf06f79ea60443 Mon Sep 17 00:00:00 2001 From: ruihan Date: Fri, 30 Oct 2026 11:31:43 -0300 Subject: [PATCH] fix(cli): skip volume access during suppression previews --- tests/test_recovery_preview.bats | 37 ++++++++++++++++++++++++++++++++ unleash | 8 +++++++ unleash-standalone.sh | 8 +++++++ 3 files changed, 53 insertions(+) create mode 100644 tests/test_recovery_preview.bats diff --git a/tests/test_recovery_preview.bats b/tests/test_recovery_preview.bats new file mode 100644 index 0000000..6d75129 --- /dev/null +++ b/tests/test_recovery_preview.bats @@ -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 +} diff --git a/unleash b/unleash index b96683d..9c3e9d4 100755 --- a/unleash +++ b/unleash @@ -178,6 +178,10 @@ cmd_version() { cmd_bypass() { if is_recovery; then + if [ "$DRY_RUN" = true ]; then + full_bypass_mode "the selected Data volume" + return + fi header "Full MDM Bypass" local data_mount data_mount=$(resolve_data_volume) @@ -188,6 +192,10 @@ cmd_bypass() { } cmd_suppress() { + if [ "$DRY_RUN" = true ]; then + suppress_only_mode "the selected Data volume" + return + fi header "Suppress Enrollment" local data_mount data_mount=$(resolve_data_volume) diff --git a/unleash-standalone.sh b/unleash-standalone.sh index 544f562..15e82b0 100755 --- a/unleash-standalone.sh +++ b/unleash-standalone.sh @@ -2968,6 +2968,10 @@ cmd_version() { cmd_bypass() { if is_recovery; then + if [ "$DRY_RUN" = true ]; then + full_bypass_mode "the selected Data volume" + return + fi header "Full MDM Bypass" local data_mount data_mount=$(resolve_data_volume) @@ -2978,6 +2982,10 @@ cmd_bypass() { } cmd_suppress() { + if [ "$DRY_RUN" = true ]; then + suppress_only_mode "the selected Data volume" + return + fi header "Suppress Enrollment" local data_mount data_mount=$(resolve_data_volume)