mirror of
https://github.com/golang/go
synced 2024-11-05 18:46:11 -07:00
net/smtp: preserve Auth errors
If authentication failed, the initial error was being thrown away. Fixes #5700. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/10744043
This commit is contained in:
parent
e88478f1e0
commit
64441d6d66
@ -196,7 +196,9 @@ func (c *Client) Auth(a Auth) error {
|
|||||||
default:
|
default:
|
||||||
err = &textproto.Error{Code: code, Msg: msg64}
|
err = &textproto.Error{Code: code, Msg: msg64}
|
||||||
}
|
}
|
||||||
|
if err == nil {
|
||||||
resp, err = a.Next(msg, code == 334)
|
resp, err = a.Next(msg, code == 334)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// abort the AUTH
|
// abort the AUTH
|
||||||
c.cmd(501, "*")
|
c.cmd(501, "*")
|
||||||
|
@ -504,3 +504,47 @@ SendMail is working for me.
|
|||||||
.
|
.
|
||||||
QUIT
|
QUIT
|
||||||
`
|
`
|
||||||
|
|
||||||
|
func TestAuthFailed(t *testing.T) {
|
||||||
|
server := strings.Join(strings.Split(authFailedServer, "\n"), "\r\n")
|
||||||
|
client := strings.Join(strings.Split(authFailedClient, "\n"), "\r\n")
|
||||||
|
var cmdbuf bytes.Buffer
|
||||||
|
bcmdbuf := bufio.NewWriter(&cmdbuf)
|
||||||
|
var fake faker
|
||||||
|
fake.ReadWriter = bufio.NewReadWriter(bufio.NewReader(strings.NewReader(server)), bcmdbuf)
|
||||||
|
c, err := NewClient(fake, "fake.host")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("NewClient: %v", err)
|
||||||
|
}
|
||||||
|
defer c.Close()
|
||||||
|
|
||||||
|
c.tls = true
|
||||||
|
c.serverName = "smtp.google.com"
|
||||||
|
err = c.Auth(PlainAuth("", "user", "pass", "smtp.google.com"))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Auth: expected error; got none")
|
||||||
|
} else if err.Error() != "535 Invalid credentials\nplease see www.example.com" {
|
||||||
|
t.Errorf("Auth: got error: %v, want: %s", err, "535 Invalid credentials\nplease see www.example.com")
|
||||||
|
}
|
||||||
|
|
||||||
|
bcmdbuf.Flush()
|
||||||
|
actualcmds := cmdbuf.String()
|
||||||
|
if client != actualcmds {
|
||||||
|
t.Errorf("Got:\n%s\nExpected:\n%s", actualcmds, client)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var authFailedServer = `220 hello world
|
||||||
|
250-mx.google.com at your service
|
||||||
|
250 AUTH LOGIN PLAIN
|
||||||
|
535-Invalid credentials
|
||||||
|
535 please see www.example.com
|
||||||
|
221 Goodbye
|
||||||
|
`
|
||||||
|
|
||||||
|
var authFailedClient = `EHLO localhost
|
||||||
|
AUTH PLAIN AHVzZXIAcGFzcw==
|
||||||
|
*
|
||||||
|
QUIT
|
||||||
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user