Files
connector-macos/smoketest/scenarios/85-sftp.sh
T
David YoungandClaude Opus 5.5 eab26c0888 Stop SSHFS hanging, and name the real reason Gatekeeper refuses an app
With macFUSE's FSKit extension off, sshfs waits forever and ignores TERM;
sftp_mount gives it 30 seconds, then stops it and says to turn macFUSE on.

On a Mac that allows only App Store apps, app_install said the download
"isn't notarized"; it now says the Mac only allows App Store apps, and where
to change that.

The vanilla image is like that and since macOS 15 only System Settings or
MDM can change it, so 70-apps checks the message and skips the installs
there. 85-sftp checks that add_sftp gives up while the extension is off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:01:03 -07:00

97 lines
3.5 KiB
Bash

# shellcheck shell=bash
DESCRIPTION="SFTP folders: macFUSE and SSHFS install, and the VM mounts a folder from itself over SSH"
TIER=quick
source "$CONNECTOR/configure.d/60-storage.sh"
SOURCE_DIR="$HOME/sftp-source"
URL="sftp://$USER@localhost$SOURCE_DIR"
job_loaded() {
launchctl print "gui/$(id -u)/$LABEL" > /dev/null 2>&1
}
# The id of macFUSE's file system extension, as pluginkit lists it
fsmodule_id() {
pluginkit -m -A -D -p com.apple.fskit.fsmodule 2> /dev/null | grep -i macfuse | head -n 1 \
| sed -E 's/^[-+=!? ]*//; s/[[:space:]]*\(.*$//; s/[[:space:]].*$//'
}
point_of() {
awk -F'|' -v url="$URL" '$1 == url { print $2 }' "$STORAGE_CONF"
}
reads_through_mount() {
[ "$(cat "$(point_of)/hello.txt")" = "hello over sftp" ]
}
writes_through_mount() {
echo written > "$(point_of)/from-mount.txt" && [ "$(cat "$SOURCE_DIR/from-mount.txt")" = written ]
}
remounts() {
local point
point="$(point_of)"
sftp_unmount "$point" || return 1
sftp_mounted "$point" && return 1
bash "$STORAGE_MOUNT"
sleep 3
sftp_mounted "$point"
}
# add_sftp fails, within sftp_mount's 30 seconds and not by asking to turn
# the extension on (which waits 5 minutes), and leaves nothing mounted
gives_up() {
local start=$SECONDS
add_sftp "$URL" < /dev/null && return 1
[ $((SECONDS - start)) -le 60 ] || return 1
! sftp_mounted "/Volumes/localhost-sftp-source"
}
scenario() {
local backend id
check "fuse_backend picks one" fuse_backend
backend="$(fuse_backend)"
[ -n "$backend" ] || { skip "This macOS can't mount over SFTP without macFUSE's kernel extension"; return; }
check_eq "it's FSKit on macOS 26 and later" fskit "$backend"
step "Installing macFUSE and SSHFS (Team IDs checked)"
check "app_install macfuse" app_install macfuse
check "app_install sshfs" app_install sshfs
check "sshfs runs" "$SSHFS" --version
step "macFUSE's file system extension"
id="$(fsmodule_id)"
if [ -z "$id" ]; then
skip "pluginkit doesn't list macFUSE's extension, so fskit_enabled can't tell whether it's on"
else
check "pluginkit lists it ($id)" true
fskit_enabled || pluginkit -e use -i "$id" 2> /dev/null
sleep 2
fi
step "A folder from this Mac, over SSH"
mkdir -p "$HOME/.ssh" "$SOURCE_DIR"
echo "hello over sftp" > "$SOURCE_DIR/hello.txt"
[ -f "$HOME/.ssh/id_ed25519" ] || ssh-keygen -q -t ed25519 -N '' -f "$HOME/.ssh/id_ed25519"
cat "$HOME/.ssh/id_ed25519.pub" >> "$HOME/.ssh/authorized_keys"
ssh-keyscan -H localhost >> "$HOME/.ssh/known_hosts" 2> /dev/null
mkdir -p "$CONF_DIR"
: > "$STORAGE_CONF"
check "sftp_key_works" sftp_key_works "$URL"
# The extension needs a click in System Settings, so it's usually off here
fskit_enabled
case $? in
1) skip "Turning macFUSE's extension on needs a click in System Settings: check mounting by hand"
return ;;
2) check "add_sftp gives up, rather than hanging, while macFUSE's extension isn't on" gives_up
skip "Turning macFUSE's extension on needs a click in System Settings: check mounting by hand"
return ;;
esac
check "add_sftp mounts it and adds it to the list" add_sftp "$URL"
check "launchd has the job" job_loaded
check "a file reads through the mount" reads_through_mount
check "a file written through the mount lands on the server" writes_through_mount
check "storage-mount mounts it again after it's unmounted" remounts
check "remove_share" remove_share "$URL" "$(point_of)"
check_not "it's no longer in the list" grep -qF "$URL" "$STORAGE_CONF"
}