A refused IMAP command's error quoted the whole command, so a failed
LOGIN put the password into the log on every sync. The error now names
only the verb ("IMAP LOGIN failed: ..."). Carried over from web_server's
backend, which logged it the same way.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package services
|
|
|
|
import (
|
|
"bufio"
|
|
"net"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A refused command's error is logged by the sync, so it must not quote the
|
|
// command's arguments: for LOGIN those include the password.
|
|
func TestIMAPCommandErrorOmitsArguments(t *testing.T) {
|
|
client, server := net.Pipe()
|
|
defer client.Close()
|
|
go func() {
|
|
defer server.Close()
|
|
r := bufio.NewReader(server)
|
|
line, _ := r.ReadString('\n')
|
|
tag, _, _ := strings.Cut(line, " ")
|
|
server.Write([]byte(tag + " NO Basic authentication is disabled.\r\n"))
|
|
}()
|
|
|
|
c := &imapClient{conn: client, reader: bufio.NewReader(client)}
|
|
_, err := c.sendCommandOK(`LOGIN [email protected] "hunter2-secret"`)
|
|
if err == nil {
|
|
t.Fatal("expected the refused LOGIN to be an error")
|
|
}
|
|
if strings.Contains(err.Error(), "hunter2-secret") || strings.Contains(err.Error(), "[email protected]") {
|
|
t.Fatalf("error quotes the command's arguments: %v", err)
|
|
}
|
|
if want := "IMAP LOGIN failed: A0001 NO Basic authentication is disabled."; err.Error() != want {
|
|
t.Fatalf("error = %q, want %q", err, want)
|
|
}
|
|
}
|