diff --git a/mailhog/smtp/server/session_test.go b/mailhog/smtp/server/session_test.go index 0ab4b4b..2b9673d 100644 --- a/mailhog/smtp/server/session_test.go +++ b/mailhog/smtp/server/session_test.go @@ -3,113 +3,41 @@ package server import ( "testing" - "github.com/stretchr/testify/assert" + . "github.com/smartystreets/goconvey/convey" ) -func TestMAILParsing(t *testing.T) { - from, err := ParseMAIL("From:") - assert.Equal(t, from, "foo@bar") - assert.Nil(t, err) +func TestValidateAuthentication(t *testing.T) { + Convey("validateAuthentication is always successful", t, func() { + c := &Session{} - from, err = ParseMAIL("From:") - assert.Equal(t, from, "foo@bar.com") - assert.Nil(t, err) + err, ok := c.validateAuthentication("OINK") + So(err, ShouldBeNil) + So(ok, ShouldBeTrue) - from, err = ParseMAIL("From:") - assert.Equal(t, from, "foo") - assert.Nil(t, err) + err, ok = c.validateAuthentication("OINK", "arg1") + So(err, ShouldBeNil) + So(ok, ShouldBeTrue) - from, err = ParseMAIL("To:") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid sender") - - from, err = ParseMAIL("To:") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid sender") - - from, err = ParseMAIL("To:") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid sender") - - from, err = ParseMAIL("INVALID") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid sender") - - from, err = ParseMAIL("From:INVALID") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid sender") - - from, err = ParseMAIL("From:foo") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid sender") - - from, err = ParseMAIL("From:foo@bar") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid sender") - - from, err = ParseMAIL("From: ") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid sender") + err, ok = c.validateAuthentication("OINK", "arg1", "arg2") + So(err, ShouldBeNil) + So(ok, ShouldBeTrue) + }) } -func TestRCPTParsing(t *testing.T) { - from, err := ParseRCPT("To:") - assert.Equal(t, from, "foo@bar") - assert.Nil(t, err) +func TestValidateRecipient(t *testing.T) { + Convey("validateRecipient is always successful", t, func() { + c := &Session{} - from, err = ParseRCPT("To:") - assert.Equal(t, from, "foo@bar.com") - assert.Nil(t, err) - - from, err = ParseRCPT("To:") - assert.Equal(t, from, "foo") - assert.Nil(t, err) - - from, err = ParseRCPT("From:") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid recipient") - - from, err = ParseRCPT("From:") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid recipient") - - from, err = ParseRCPT("From:") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid recipient") - - from, err = ParseRCPT("INVALID") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid recipient") - - from, err = ParseRCPT("To:INVALID") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid recipient") - - from, err = ParseRCPT("To:foo") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid recipient") - - from, err = ParseRCPT("To:foo@bar") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid recipient") - - from, err = ParseRCPT("To: ") - assert.Equal(t, from, "") - assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Invalid recipient") + So(c.validateRecipient("OINK"), ShouldBeTrue) + So(c.validateRecipient("foo@bar.mailhog"), ShouldBeTrue) + }) +} + +func TestValidateSender(t *testing.T) { + Convey("validateSender is always successful", t, func() { + c := &Session{} + + So(c.validateSender("OINK"), ShouldBeTrue) + So(c.validateSender("foo@bar.mailhog"), ShouldBeTrue) + }) }