mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2025-02-21 10:15:56 +00:00
More auth tests, fix bug
This commit is contained in:
parent
a4c1f6a4d0
commit
54b4c4c681
2 changed files with 66 additions and 5 deletions
61
auth_test.go
61
auth_test.go
|
@ -87,4 +87,65 @@ func TestBasicSMTPAuth(t *testing.T) {
|
||||||
n, err = conn.Read(buf)
|
n, err = conn.Read(buf)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, string(buf[0:n]), "235 Authentication successful\n")
|
assert.Equal(t, string(buf[0:n]), "235 Authentication successful\n")
|
||||||
|
|
||||||
|
// Send RSET and EHLO
|
||||||
|
_, err = conn.Write([]byte("RSET\r\n"))
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
_, err = conn.Write([]byte("EHLO localhost\r\n"))
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
|
||||||
|
// Send AUTH
|
||||||
|
_, err = conn.Write([]byte("AUTH LOGIN\r\n"))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
// Read the response
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, string(buf[0:n]), "334 VXNlcm5hbWU6\n")
|
||||||
|
|
||||||
|
// Send AUTH
|
||||||
|
_, err = conn.Write([]byte("foobar\r\n"))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
// Read the response
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, string(buf[0:n]), "334 UGFzc3dvcmQ6\n")
|
||||||
|
|
||||||
|
// Send AUTH
|
||||||
|
_, err = conn.Write([]byte("foobar\r\n"))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
// Read the response
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, string(buf[0:n]), "235 Authentication successful\n")
|
||||||
|
|
||||||
|
// Send RSET and EHLO
|
||||||
|
_, err = conn.Write([]byte("RSET\r\n"))
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
_, err = conn.Write([]byte("EHLO localhost\r\n"))
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
|
||||||
|
// Send AUTH
|
||||||
|
_, err = conn.Write([]byte("AUTH CRAM-MD5\r\n"))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
// Read the response
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, string(buf[0:n]), "334 PDQxOTI5NDIzNDEuMTI4Mjg0NzJAc291cmNlZm91ci5hbmRyZXcuY211LmVkdT4=\n")
|
||||||
|
|
||||||
|
// Send AUTH
|
||||||
|
_, err = conn.Write([]byte("foobar\r\n"))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
// Read the response
|
||||||
|
n, err = conn.Read(buf)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, string(buf[0:n]), "235 Authentication successful\n")
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ func (c *Session) Process(line string) {
|
||||||
case c.state == AUTH2:
|
case c.state == AUTH2:
|
||||||
c.log("Got LOGIN authentication response: '%s', switching to AUTH state", args)
|
c.log("Got LOGIN authentication response: '%s', switching to AUTH state", args)
|
||||||
c.state = AUTH
|
c.state = AUTH
|
||||||
c.Write("334", "VXNlcm5hbWU6")
|
c.Write("334", "UGFzc3dvcmQ6")
|
||||||
case c.state == MAIL: // TODO rename/split state
|
case c.state == MAIL: // TODO rename/split state
|
||||||
switch command {
|
switch command {
|
||||||
case "AUTH":
|
case "AUTH":
|
||||||
|
@ -171,10 +171,10 @@ func (c *Session) Process(line string) {
|
||||||
c.Write("235", "Authentication successful")
|
c.Write("235", "Authentication successful")
|
||||||
case args == "LOGIN":
|
case args == "LOGIN":
|
||||||
c.log("Got LOGIN authentication, switching to AUTH state")
|
c.log("Got LOGIN authentication, switching to AUTH state")
|
||||||
c.state = AUTH
|
c.state = AUTH2
|
||||||
c.Write("334", "VXNlcm5hbWU6")
|
c.Write("334", "VXNlcm5hbWU6")
|
||||||
case args == "PLAIN":
|
case args == "PLAIN":
|
||||||
c.log("Got PLAIN authentication (no args), switching to AUTH state")
|
c.log("Got PLAIN authentication (no args), switching to AUTH2 state")
|
||||||
c.state = AUTH
|
c.state = AUTH
|
||||||
c.Write("334", "")
|
c.Write("334", "")
|
||||||
case args == "CRAM-MD5":
|
case args == "CRAM-MD5":
|
||||||
|
@ -189,7 +189,7 @@ func (c *Session) Process(line string) {
|
||||||
}
|
}
|
||||||
case "MAIL":
|
case "MAIL":
|
||||||
c.log("Got MAIL command, switching to RCPT state")
|
c.log("Got MAIL command, switching to RCPT state")
|
||||||
r, _ := regexp.Compile("From:<([^>]+)>")
|
r, _ := regexp.Compile("(?i:From):<([^>]+)>")
|
||||||
match := r.FindStringSubmatch(args)
|
match := r.FindStringSubmatch(args)
|
||||||
c.message.From = match[1]
|
c.message.From = match[1]
|
||||||
c.state = RCPT
|
c.state = RCPT
|
||||||
|
@ -202,7 +202,7 @@ func (c *Session) Process(line string) {
|
||||||
switch command {
|
switch command {
|
||||||
case "RCPT":
|
case "RCPT":
|
||||||
c.log("Got RCPT command")
|
c.log("Got RCPT command")
|
||||||
r, _ := regexp.Compile("To:<([^>]+)>")
|
r, _ := regexp.Compile("(?i:To):<([^>]+)>")
|
||||||
match := r.FindStringSubmatch(args)
|
match := r.FindStringSubmatch(args)
|
||||||
c.message.To = append(c.message.To, match[1])
|
c.message.To = append(c.message.To, match[1])
|
||||||
c.state = RCPT
|
c.state = RCPT
|
||||||
|
|
Loading…
Add table
Reference in a new issue