diff --git a/lib/detect.sh b/lib/detect.sh index 21fee6e..7eceb61 100644 --- a/lib/detect.sh +++ b/lib/detect.sh @@ -31,7 +31,7 @@ resolve_data_volume() { if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then warn "Auto-detection failed. Available disks:" diskutil list >&2 - echo "" + echo "" >&2 [ -t 0 ] || error_exit "Cannot select a Data volume without a terminal." read -r -p "Enter Data volume identifier (e.g. disk3s1): " id /dev/null || true + diskutil mount "$data_dev" >&2 || true mount_pt=$(_mount_point) fi if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then warn "FileVault-locked — need to unlock." echo -e "${YEL}Enter password of a user on this Mac (or FileVault recovery key):${NC}" >&2 - diskutil apfs unlockVolume "$data_dev" 2>/dev/null \ + diskutil apfs unlockVolume "$data_dev" >&2 \ || error_exit "Failed to unlock. Re-run with valid credentials." mount_pt=$(_mount_point) fi diff --git a/tests/test_volume_output.bats b/tests/test_volume_output.bats new file mode 100644 index 0000000..7bef25f --- /dev/null +++ b/tests/test_volume_output.bats @@ -0,0 +1,47 @@ +#!/usr/bin/env bats + +check_volume_output() { + local mode="$1" entrypoint + bats_require_minimum_version 1.5.0 + for entrypoint in unleash unleash-standalone.sh; do + local script="$BATS_TEST_DIRNAME/../$entrypoint" + local target="$BATS_TEST_TMPDIR/$entrypoint/Data volume" + mkdir -p "$target/private/var/db/dslocal/nodes/Default" + run --separate-stderr bash -u -c ' + source <(sed '\''/^main "\$@"$/d'\'' "$1") + target="$2"; mode="$3"; mounted="$4" + diskutil() { + case "$*" in + "apfs list") echo "+-- Volume disk5s1 (Data)" ;; + "info /dev/disk5s1") + if [ -f "$mounted" ]; then printf "Mount Point: %s\n" "$target"; + else echo "Mount Point: Not mounted"; fi ;; + "mount /dev/disk5s1") + echo "Mount attempt diagnostic" + [ "$mode" != locked ] || return 1 + touch "$mounted" ;; + "apfs unlockVolume /dev/disk5s1") + echo "Unlocking any cryptographic user" + echo "Unlocked and mounted APFS Volume" + touch "$mounted" ;; + *) return 1 ;; + esac + } + resolve_data_volume + ' "$script" "$script" "$target" "$mode" "$BATS_TEST_TMPDIR/$entrypoint.mounted" + [ "$status" -eq 0 ] + [ "$output" = "$target" ] + [[ "$stderr" == *"Mount attempt diagnostic"* ]] + if [ "$mode" = locked ]; then + [[ "$stderr" == *"Unlocked and mounted APFS Volume"* ]] + fi + done +} + +@test "mount diagnostics stay out of the selected Data volume path" { + check_volume_output unmounted +} + +@test "FileVault unlock diagnostics stay out of the selected Data volume path" { + check_volume_output locked +} diff --git a/unleash-standalone.sh b/unleash-standalone.sh index dc2bf9f..04ce5f6 100755 --- a/unleash-standalone.sh +++ b/unleash-standalone.sh @@ -234,7 +234,7 @@ resolve_data_volume() { if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then warn "Auto-detection failed. Available disks:" diskutil list >&2 - echo "" + echo "" >&2 [ -t 0 ] || error_exit "Cannot select a Data volume without a terminal." read -r -p "Enter Data volume identifier (e.g. disk3s1): " id /dev/null || true + diskutil mount "$data_dev" >&2 || true mount_pt=$(_mount_point) fi if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then warn "FileVault-locked — need to unlock." echo -e "${YEL}Enter password of a user on this Mac (or FileVault recovery key):${NC}" >&2 - diskutil apfs unlockVolume "$data_dev" 2>/dev/null \ + diskutil apfs unlockVolume "$data_dev" >&2 \ || error_exit "Failed to unlock. Re-run with valid credentials." mount_pt=$(_mount_point) fi