mirror of
https://github.com/golang/go.git
synced 2025-05-07 08:32:59 +00:00
net/smtp: ignore HELO error in QUIT
Fixes #70011 Change-Id: I9d8b3ffbd66561eee0efffd54038960acd5fcf64 Reviewed-on: https://go-review.googlesource.com/c/go/+/622476 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Commit-Queue: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
4226fc597b
commit
2ef8e41f95
@ -413,9 +413,7 @@ func (c *Client) Noop() error {
|
|||||||
|
|
||||||
// Quit sends the QUIT command and closes the connection to the server.
|
// Quit sends the QUIT command and closes the connection to the server.
|
||||||
func (c *Client) Quit() error {
|
func (c *Client) Quit() error {
|
||||||
if err := c.hello(); err != nil {
|
c.hello() // ignore error; we're quitting anyhow
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, _, err := c.cmd(221, "QUIT")
|
_, _, err := c.cmd(221, "QUIT")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -288,6 +288,37 @@ Goodbye.
|
|||||||
QUIT
|
QUIT
|
||||||
`
|
`
|
||||||
|
|
||||||
|
func TestHELOFailed(t *testing.T) {
|
||||||
|
serverLines := `502 EH?
|
||||||
|
502 EH?
|
||||||
|
221 OK
|
||||||
|
`
|
||||||
|
clientLines := `EHLO localhost
|
||||||
|
HELO localhost
|
||||||
|
QUIT
|
||||||
|
`
|
||||||
|
|
||||||
|
server := strings.Join(strings.Split(serverLines, "\n"), "\r\n")
|
||||||
|
client := strings.Join(strings.Split(clientLines, "\n"), "\r\n")
|
||||||
|
var cmdbuf strings.Builder
|
||||||
|
bcmdbuf := bufio.NewWriter(&cmdbuf)
|
||||||
|
var fake faker
|
||||||
|
fake.ReadWriter = bufio.NewReadWriter(bufio.NewReader(strings.NewReader(server)), bcmdbuf)
|
||||||
|
c := &Client{Text: textproto.NewConn(fake), localName: "localhost"}
|
||||||
|
|
||||||
|
if err := c.Hello("localhost"); err == nil {
|
||||||
|
t.Fatal("expected EHLO to fail")
|
||||||
|
}
|
||||||
|
if err := c.Quit(); err != nil {
|
||||||
|
t.Errorf("QUIT failed: %s", err)
|
||||||
|
}
|
||||||
|
bcmdbuf.Flush()
|
||||||
|
actual := cmdbuf.String()
|
||||||
|
if client != actual {
|
||||||
|
t.Errorf("Got:\n%s\nWant:\n%s", actual, client)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestExtensions(t *testing.T) {
|
func TestExtensions(t *testing.T) {
|
||||||
fake := func(server string) (c *Client, bcmdbuf *bufio.Writer, cmdbuf *strings.Builder) {
|
fake := func(server string) (c *Client, bcmdbuf *bufio.Writer, cmdbuf *strings.Builder) {
|
||||||
server = strings.Join(strings.Split(server, "\n"), "\r\n")
|
server = strings.Join(strings.Split(server, "\n"), "\r\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user