A sign-in method's prompts could only be "text" or "select", so a token a plugin asks for (the Qoder plugin's PAT sign-in, magpie-community/plugins#103) showed on screen as it was typed, in the app and in `magpie plugin login`. What changed: - internal/gui/assets/app.js renderPluginAsk: a prompt of type "password" gets a password field (masked), the same field an "api" method's key gets. A "text" prompt is unchanged. - internal/cli/plugins_cli.go askPrompt: on a terminal a "password" prompt is read with term.ReadPassword (no echo); piped in it is read as a line, as a script answers it, and an empty answer still goes to the plugin's validate, as a text one does. - internal/plugin/providers.go: the Prompt type lists "password". host.js passes the type through untouched, so nothing there changes. The TUI has no plugin sign-in. - Docs: docs/reference.md and site/public/docs (en, zh, ja) plugins.html say what "password" does and that it is magpie's own (OpenCode has text and select). The answer is only sent to /api/plugin-signin/prompt and the sign-in, as a text answer is; nothing logs or shows it. What was run: - TestAskPromptPasswordIsUnseen (internal/cli): with the password branch disabled by hand it fails with `password on a terminal = "typed-in-the-open", <nil>, hidden reads 0; want pt-secret read unseen`; restored it passes. - plugin-password-prompt.test.cjs: Chromium and WebKit, en/zh/zh-TW/ja/de, 1100 and 420 wide, 11/11 each. With app.js put back it fails with expected 'password', actual 'text'. plugin-signin and plugin-signed-out-account 16/16 in both engines; i18n-keys passes in both. - gofmt -l clean; go vet for darwin, GOOS=linux -tags nogui and GOOS=windows on internal/cli, internal/plugin, internal/gui; go test -tags nogui of those three packages in a sandbox HOME: ok. Not tried: a real Qoder PAT through the community plugin (its PR isn't merged), and the CLI on a real Windows console (term.ReadPassword is the same call `magpie plugin login` already uses for an API key).
38 lines
1.5 KiB
Go
38 lines
1.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/plugin"
|
|
)
|
|
|
|
// TestAskPromptPasswordIsUnseen: a plugin question of type "password" (a
|
|
// Qoder PAT, #1982) is read from the terminal without echo, while a "text"
|
|
// question on the same terminal is still typed in the open; piped in, a
|
|
// password question is read as a line, as a script answers it.
|
|
func TestAskPromptPasswordIsUnseen(t *testing.T) {
|
|
hidden := 0
|
|
oldTerm, oldRead := promptTerminal, promptHidden
|
|
t.Cleanup(func() { promptTerminal, promptHidden = oldTerm, oldRead })
|
|
terminal := true
|
|
promptTerminal = func(int) bool { return terminal }
|
|
promptHidden = func(int) ([]byte, error) { hidden++; return []byte(" pt-secret \n"), nil }
|
|
|
|
piped(t, "typed-in-the-open")
|
|
v, err := askPrompt(&plugin.Prompt{Type: "password", Key: "pat", Message: "Your Qoder Personal Access Token", Placeholder: "pt-..."})
|
|
if err != nil || v != "pt-secret" || hidden != 1 {
|
|
t.Fatalf("password on a terminal = %q, %v, hidden reads %d; want pt-secret read unseen", v, err, hidden)
|
|
}
|
|
|
|
piped(t, "blue")
|
|
if v, err := askPrompt(&plugin.Prompt{Type: "text", Key: "team", Message: "Your team"}); err != nil || v != "blue" || hidden != 1 {
|
|
t.Fatalf("text on a terminal = %q, %v, hidden reads %d; want blue typed in the open", v, err, hidden)
|
|
}
|
|
|
|
terminal = false
|
|
piped(t, "pt-piped")
|
|
if v, err := askPrompt(&plugin.Prompt{Type: "password", Key: "pat", Message: "PAT"}); err != nil || v != "pt-piped" || hidden != 1 {
|
|
t.Fatalf("password piped = %q, %v, hidden reads %d; want the line", v, err, hidden)
|
|
}
|
|
}
|