Skip to content

Commit

Permalink
server: Add a test to verify that <LF>.<LF> is not recognized as a me…
Browse files Browse the repository at this point in the history
…ssage end
  • Loading branch information
foxcpp committed Jul 24, 2020
1 parent 79274b8 commit 09421d1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,50 @@ func TestServer(t *testing.T) {
}
}

func TestServer_LFDotLF(t *testing.T) {
be, s, c, scanner := testServerAuthenticated(t)
defer s.Close()
defer c.Close()

io.WriteString(c, "MAIL FROM:<[email protected]>\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "250 ") {
t.Fatal("Invalid MAIL response:", scanner.Text())
}

io.WriteString(c, "RCPT TO:<[email protected]>\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "250 ") {
t.Fatal("Invalid RCPT response:", scanner.Text())
}

io.WriteString(c, "DATA\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "354 ") {
t.Fatal("Invalid DATA response:", scanner.Text())
}

io.WriteString(c, "From: [email protected]\r\n")
io.WriteString(c, "\r\n")
io.WriteString(c, "hey\r\n")
io.WriteString(c, "\n.\n")
io.WriteString(c, "this is going to break your server\r\n")
io.WriteString(c, ".\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "250 ") {
t.Fatal("Invalid DATA response:", scanner.Text())
}

if len(be.messages) != 1 || len(be.anonmsgs) != 0 {
t.Fatal("Invalid number of sent messages:", be.messages, be.anonmsgs)
}

msg := be.messages[0]
if string(msg.Data) != "From: [email protected]\r\n\r\nhey\r\n\n.\nthis is going to break your server\r\n" {
t.Fatal("Invalid mail data:", string(msg.Data))
}
}

func TestServer_authDisabled(t *testing.T) {
_, s, c, scanner, caps := testServerEhlo(t, authDisabled)
defer s.Close()
Expand Down

0 comments on commit 09421d1

Please sign in to comment.