Keep the IMAP password out of error messages
Test and publish / test (push) Successful in 1m11s
Test and publish / publish (push) Successful in 48s

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]>
This commit is contained in:
2026-10-14 17:14:18 +01:00
co-authored by Claude Opus 5.5
parent e6ed29d4a9
commit 0d31332033
2 changed files with 38 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
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)
}
}