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 someone@example.com "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(), "someone@example.com") { 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) } }