Skip to content
Open
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
4 changes: 3 additions & 1 deletion internal/cli/pinentry/pinentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ const (
)

// dialogScript shows the message passed as the first argument (never interpolated into the script)
// and prints the entered PIN to stdout.
// and prints the entered PIN to stdout. `activate` brings osascript to the front first: when the CLI
// runs in the background (e.g. from an agent) the dialog otherwise opens without keyboard focus.
const dialogScript = `on run argv
activate
set reply to display dialog (item 1 of argv) with title "rack-gateway" default answer "" ¬
with hidden answer buttons {"Cancel", "Approve"} default button "Approve" cancel button "Cancel" ¬
with icon caution giving up after 170
Expand Down
9 changes: 9 additions & 0 deletions internal/cli/pinentry/pinentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ func TestDescribeCommandTruncatesLongCommands(t *testing.T) {
t.Fatalf("describeCommand length = %d, want %d ending in ...", len(got), maxCommandLength+3)
}
}

func TestDialogScriptActivatesBeforeShowingDialog(t *testing.T) {
activate := strings.Index(dialogScript, "\tactivate\n")
dialog := strings.Index(dialogScript, "display dialog")
if activate < 0 || activate > dialog {
t.Fatalf("dialog script must activate osascript before the dialog so the PIN field has focus:\n%s",
dialogScript)
}
}
Loading