mirror of
https://github.com/golang/term.git
synced 2026-01-29 07:02:06 +03:00
go.crypto/ssh/terminal: don't save passwords in history.
The history buffer would recall previously entered lines: including passwords. With this change, lines entered while echo is disabled are no longer put into the history. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/10853043
This commit is contained in:
@@ -546,8 +546,10 @@ func (t *Terminal) readLine() (line string, err error) {
|
||||
t.c.Write(t.outBuf)
|
||||
t.outBuf = t.outBuf[:0]
|
||||
if lineOk {
|
||||
t.historyIndex = -1
|
||||
t.history.Add(line)
|
||||
if t.echo {
|
||||
t.historyIndex = -1
|
||||
t.history.Add(line)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -129,3 +129,19 @@ func TestKeyPresses(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPasswordNotSaved(t *testing.T) {
|
||||
c := &MockTerminal{
|
||||
toSend: []byte("password\r\x1b[A\r"),
|
||||
bytesPerRead: 1,
|
||||
}
|
||||
ss := NewTerminal(c, "> ")
|
||||
pw, _ := ss.ReadPassword("> ")
|
||||
if pw != "password" {
|
||||
t.Fatalf("failed to read password, got %s", pw)
|
||||
}
|
||||
line, _ := ss.ReadLine()
|
||||
if len(line) > 0 {
|
||||
t.Fatalf("password was saved in history")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user