fix(volumes): keep mount diagnostics out of paths
Keep disk mount output out of captured volume paths
This commit is contained in:
+3
-3
@@ -31,7 +31,7 @@ resolve_data_volume() {
|
|||||||
if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then
|
if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then
|
||||||
warn "Auto-detection failed. Available disks:"
|
warn "Auto-detection failed. Available disks:"
|
||||||
diskutil list >&2
|
diskutil list >&2
|
||||||
echo ""
|
echo "" >&2
|
||||||
[ -t 0 ] || error_exit "Cannot select a Data volume without a terminal."
|
[ -t 0 ] || error_exit "Cannot select a Data volume without a terminal."
|
||||||
read -r -p "Enter Data volume identifier (e.g. disk3s1): " id </dev/tty
|
read -r -p "Enter Data volume identifier (e.g. disk3s1): " id </dev/tty
|
||||||
id="${id#/dev/}"
|
id="${id#/dev/}"
|
||||||
@@ -51,14 +51,14 @@ resolve_data_volume() {
|
|||||||
|
|
||||||
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
||||||
info "Not mounted — mounting..."
|
info "Not mounted — mounting..."
|
||||||
diskutil mount "$data_dev" 2>/dev/null || true
|
diskutil mount "$data_dev" >&2 || true
|
||||||
mount_pt=$(_mount_point)
|
mount_pt=$(_mount_point)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
||||||
warn "FileVault-locked — need to unlock."
|
warn "FileVault-locked — need to unlock."
|
||||||
echo -e "${YEL}Enter password of a user on this Mac (or FileVault recovery key):${NC}" >&2
|
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."
|
|| error_exit "Failed to unlock. Re-run with valid credentials."
|
||||||
mount_pt=$(_mount_point)
|
mount_pt=$(_mount_point)
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -234,7 +234,7 @@ resolve_data_volume() {
|
|||||||
if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then
|
if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then
|
||||||
warn "Auto-detection failed. Available disks:"
|
warn "Auto-detection failed. Available disks:"
|
||||||
diskutil list >&2
|
diskutil list >&2
|
||||||
echo ""
|
echo "" >&2
|
||||||
[ -t 0 ] || error_exit "Cannot select a Data volume without a terminal."
|
[ -t 0 ] || error_exit "Cannot select a Data volume without a terminal."
|
||||||
read -r -p "Enter Data volume identifier (e.g. disk3s1): " id </dev/tty
|
read -r -p "Enter Data volume identifier (e.g. disk3s1): " id </dev/tty
|
||||||
id="${id#/dev/}"
|
id="${id#/dev/}"
|
||||||
@@ -254,14 +254,14 @@ resolve_data_volume() {
|
|||||||
|
|
||||||
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
||||||
info "Not mounted — mounting..."
|
info "Not mounted — mounting..."
|
||||||
diskutil mount "$data_dev" 2>/dev/null || true
|
diskutil mount "$data_dev" >&2 || true
|
||||||
mount_pt=$(_mount_point)
|
mount_pt=$(_mount_point)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
||||||
warn "FileVault-locked — need to unlock."
|
warn "FileVault-locked — need to unlock."
|
||||||
echo -e "${YEL}Enter password of a user on this Mac (or FileVault recovery key):${NC}" >&2
|
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."
|
|| error_exit "Failed to unlock. Re-run with valid credentials."
|
||||||
mount_pt=$(_mount_point)
|
mount_pt=$(_mount_point)
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user