Skip to content

Commit

Permalink
Tests (flashmob#62)
Browse files Browse the repository at this point in the history
* Additional test for HELO/EHLO, see issue flashmob#44.
Also raises code coverage, see issue flashmob#45
  • Loading branch information
phires authored and flashmob committed Jan 28, 2017
1 parent 78a7ce8 commit 0b01b75
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/guerrilla_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,83 @@ func TestMailFromCmd(t *testing.T) {
logIn.Reset(&logBuffer)
}

// Test several different inputs to MAIL FROM command
func TestHeloEhlo(t *testing.T) {
if initErr != nil {
t.Error(initErr)
t.FailNow()
}
if startErrors := app.Start(); startErrors == nil {
conn, bufin, err := Connect(config.Servers[0], 20)
hostname := config.Servers[0].Hostname
if err != nil {
// handle error
t.Error(err.Error(), config.Servers[0].ListenInterface)
t.FailNow()
} else {
// Test HELO
response, err := Command(conn, bufin, "HELO localtester")
if err != nil {
t.Error("command failed", err.Error())
}
expected := fmt.Sprintf("250 %s Hello", hostname)
if strings.Index(response, expected) != 0 {
t.Error("Server did not respond with", expected, ", it said:"+response)
}
// Reset
response, err = Command(conn, bufin, "RSET")
if err != nil {
t.Error("command failed", err.Error())
}
expected = "250 2.1.0 OK"
if strings.Index(response, expected) != 0 {
t.Error("Server did not respond with", expected, ", it said:"+response)
}
// Test EHLO
// This is tricky as it is a multiline response
var fullresp string
response, err = Command(conn, bufin, "EHLO localtester")
fullresp = fullresp + response
if err != nil {
t.Error("command failed", err.Error())
}
for err == nil {
response, err = bufin.ReadString('\n')
fullresp = fullresp + response
if strings.HasPrefix(response, "250 ") { // Last response has a whitespace and no "-"
break // bail
}
}

expected = fmt.Sprintf("250-%s Hello\r\n250-SIZE 100017\r\n250-PIPELINING\r\n250-STARTTLS\r\n250-ENHANCEDSTATUSCODES\r\n250 HELP\r\n", hostname)
if fullresp != expected {
t.Error("Server did not respond with [" + expected + "], it said [" + fullresp + "]")
}
// be kind, QUIT. And we are sure that bufin does not contain fragments from the EHLO command.
response, err = Command(conn, bufin, "QUIT")
if err != nil {
t.Error("command failed", err.Error())
}
expected = "221 2.0.0 Bye"
if strings.Index(response, expected) != 0 {
t.Error("Server did not respond with", expected, ", it said:"+response)
}
}
conn.Close()
app.Shutdown()
} else {
if startErrors := app.Start(); startErrors != nil {
t.Error(startErrors)
app.Shutdown()
t.FailNow()
}
}
logOut.Flush()
// don't forget to reset
logBuffer.Reset()
logIn.Reset(&logBuffer)
}

// It should error when MAIL FROM was given twice
func TestNestedMailCmd(t *testing.T) {
if initErr != nil {
Expand Down

0 comments on commit 0b01b75

Please sign in to comment.