Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions bin/varlatch-menu
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,17 @@ case "${1:-}" in

verify)
# The one explicitly network-touching read: --probe checks each stored
# credential against its server.
out=$(eval "$CMD status --probe --json" 2>&1) \
|| { notify "verify failed: $out"; exit 1; }
# credential against its server. Only stdout is the document: the CLI
# can warn on stderr, as on a Node.js release without its security fixes.
err=$(mktemp)
# Removed however the action ends. bash skips the EXIT trap when a
# signal kills it, so those become exits.
trap 'rm -f "$err"' EXIT
trap 'exit 129' HUP; trap 'exit 130' INT; trap 'exit 143' TERM
if ! out=$(eval "$CMD status --probe --json" 2>"$err"); then
msg=$(cat "$err")
notify "verify failed: ${msg:-$out}"; exit 1
fi
summary=$(echo "$out" | jq -r '.servers[] | "\(.server): \(.probe.state // "unknown")\(if .probe.detail then " (\(.probe.detail))" else "" end)"')
notify "${summary:-no stored credentials}"
refresh_widget
Expand Down
13 changes: 12 additions & 1 deletion tests/fake-varlatch
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
# A stand-in for the varlatch CLI, for tests/run.sh. Every call is recorded
# in $HOME/calls.log. `status` prints $HOME/status.json (no sessions when it
# is missing), and the FAKE_* variables choose how sign-ins end.
# FAKE_STDERR is a line every call writes to stderr first, as the CLI warns
# on a Node.js release without its security fixes; FAKE_STATUS_FAIL makes
# `status` fail as an unreachable server does, and FAKE_STATUS_SLEEP makes it
# take that many seconds.
echo "cli $*" >> "$HOME/calls.log"
[ -n "${FAKE_STDERR:-}" ] && echo "$FAKE_STDERR" >&2
case "${1:-}" in
--version) echo "varlatch ${FAKE_VERSION:-0.15.0} (migration 26)"; exit 0 ;;
--help) echo "Usage: varlatch <command>"; exit 0 ;;
status) cat "$HOME/status.json" 2>/dev/null || echo '{"version":1,"servers":[],"repo":null}'; exit 0 ;;
status)
sleep "${FAKE_STATUS_SLEEP:-0}"
if [ -n "${FAKE_STATUS_FAIL:-}" ]; then
echo "varlatch status: cannot reach https://vl.example.com" >&2
exit 69
fi
cat "$HOME/status.json" 2>/dev/null || echo '{"version":1,"servers":[],"repo":null}'; exit 0 ;;
logout) echo "Logged out."; exit 0 ;;
login) ;;
*) exit 64 ;;
Expand Down
26 changes: 25 additions & 1 deletion tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ EOF
MENU="$T/.config/omarchy/extensions/omarchy-menu.jsonc"
widget '{}'
unset FAKE_VERSION FAKE_WAIT FAKE_CHOICE FAKE_LOGIN_RC FAKE_LOGIN_SLEEP FAKE_START_FAIL \
FAKE_LATEST FAKE_CURL_FAIL FAKE_SERVER_VERSION VARLATCH_SERVER
FAKE_LATEST FAKE_CURL_FAIL FAKE_SERVER_VERSION FAKE_STDERR FAKE_STATUS_FAIL FAKE_STATUS_SLEEP VARLATCH_SERVER
}

# The widget's entry in shell.json: the fake CLI plus the given settings.
Expand Down Expand Up @@ -208,6 +208,30 @@ check "no device sign-in row before 0.14.0" "menu_has 'has(\"varlatch.device\")
echo '{"current": "0.14.0", "latest": "0.15.0", "updateAvailable": true, "install": "release"}' > "$U"; "$H" sync-menu
check "Update CLI row for a release install" "menu_has '.[\"varlatch.update\"].description == \"0.14.0 → 0.15.0\"'"

# --------------------------------------------------------------------------
section "verify (status --probe)"
new_home
jq -n '{version: 1, repo: null, servers: [{server: "https://vl.example.com", name: null,
issuedAt: "2026-10-07T06:00:00Z", expiresAt: "2099-01-01T00:00:00Z", expired: false, expiring: false,
probe: {state: "valid"}}]}' > "$T/status.json"
"$H" verify
check "each server's probe state in the notification" \
"calls | grep -F 'notify-send -a Varlatch Varlatch https://vl.example.com: valid'" "$(calls)"
NODE_WARNING="varlatch: Node.js 26.12.0 is missing security fixes; update it to 26.12.1 or later. VARLATCH_NODE_CHECK=off hides this warning."
: > "$T/calls.log"; FAKE_STDERR="$NODE_WARNING" "$H" verify
check "a CLI warning on stderr leaves the document readable" \
"calls | grep -F 'notify-send -a Varlatch Varlatch https://vl.example.com: valid'" "$(calls)"
: > "$T/calls.log"; FAKE_STDERR="$NODE_WARNING" FAKE_STATUS_FAIL=1 "$H" verify && rc=0 || rc=$?
check "a failure notifies what the CLI said on stderr" \
"[ $rc -eq 1 ] && calls | grep -F 'notify-send -a Varlatch Varlatch verify failed:' && calls | grep -qF 'cannot reach https://vl.example.com'" "$(calls)"
# Its stderr file goes, whether verify succeeds, fails, or is stopped.
mkdir "$T/tmp"
TMPDIR="$T/tmp" "$H" verify
TMPDIR="$T/tmp" FAKE_STATUS_FAIL=1 "$H" verify || true
TMPDIR="$T/tmp" FAKE_STATUS_SLEEP=2 "$H" verify & helper=$!
sleep 0.5; kill -TERM "$helper"; wait "$helper" && rc=0 || rc=$?
check "no temporary file is left, even after SIGTERM" "[ $rc -eq 143 ] && [ -z \"\$(ls -A '$T/tmp')\" ]" "rc=$rc; $(ls -A "$T/tmp")"

# --------------------------------------------------------------------------
section "sign-in state (login, login-check, login-cancel)"
new_home
Expand Down
Loading