Returns []byte so callers can zeroize the buffer after use. Refactors internals to share readRaw between both variants. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
22 lines
497 B
Go
22 lines
497 B
Go
package terminal
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestReadPasswordNotATTY(t *testing.T) {
|
|
// When stdin is not a terminal (e.g. in CI), ReadPassword should
|
|
// return an error rather than hanging or panicking.
|
|
_, err := ReadPassword("Password: ")
|
|
if err == nil {
|
|
t.Fatal("expected error when stdin is not a terminal")
|
|
}
|
|
}
|
|
|
|
func TestReadPasswordBytesNotATTY(t *testing.T) {
|
|
_, err := ReadPasswordBytes("Password: ")
|
|
if err == nil {
|
|
t.Fatal("expected error when stdin is not a terminal")
|
|
}
|
|
}
|