Remove old session tests and add basic validation handler tests

This commit is contained in:
Ian Kent 2014-11-23 04:14:25 +00:00
parent f5a70dd078
commit c6ae2e15dc

View file

@ -3,113 +3,41 @@ package server
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert" . "github.com/smartystreets/goconvey/convey"
) )
func TestMAILParsing(t *testing.T) { func TestValidateAuthentication(t *testing.T) {
from, err := ParseMAIL("From:<foo@bar>") Convey("validateAuthentication is always successful", t, func() {
assert.Equal(t, from, "foo@bar") c := &Session{}
assert.Nil(t, err)
from, err = ParseMAIL("From:<foo@bar.com>") err, ok := c.validateAuthentication("OINK")
assert.Equal(t, from, "foo@bar.com") So(err, ShouldBeNil)
assert.Nil(t, err) So(ok, ShouldBeTrue)
from, err = ParseMAIL("From:<foo>") err, ok = c.validateAuthentication("OINK", "arg1")
assert.Equal(t, from, "foo") So(err, ShouldBeNil)
assert.Nil(t, err) So(ok, ShouldBeTrue)
from, err = ParseMAIL("To:<foo@bar>") err, ok = c.validateAuthentication("OINK", "arg1", "arg2")
assert.Equal(t, from, "") So(err, ShouldBeNil)
assert.NotNil(t, err) So(ok, ShouldBeTrue)
assert.Equal(t, err.Error(), "Invalid sender") })
from, err = ParseMAIL("To:<foo@bar.com>")
assert.Equal(t, from, "")
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "Invalid sender")
from, err = ParseMAIL("To:<foo>")
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: <foo@bar>")
assert.Equal(t, from, "")
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "Invalid sender")
} }
func TestRCPTParsing(t *testing.T) { func TestValidateRecipient(t *testing.T) {
from, err := ParseRCPT("To:<foo@bar>") Convey("validateRecipient is always successful", t, func() {
assert.Equal(t, from, "foo@bar") c := &Session{}
assert.Nil(t, err)
from, err = ParseRCPT("To:<foo@bar.com>") So(c.validateRecipient("OINK"), ShouldBeTrue)
assert.Equal(t, from, "foo@bar.com") So(c.validateRecipient("foo@bar.mailhog"), ShouldBeTrue)
assert.Nil(t, err) })
}
from, err = ParseRCPT("To:<foo>")
assert.Equal(t, from, "foo") func TestValidateSender(t *testing.T) {
assert.Nil(t, err) Convey("validateSender is always successful", t, func() {
c := &Session{}
from, err = ParseRCPT("From:<foo@bar>")
assert.Equal(t, from, "") So(c.validateSender("OINK"), ShouldBeTrue)
assert.NotNil(t, err) So(c.validateSender("foo@bar.mailhog"), ShouldBeTrue)
assert.Equal(t, err.Error(), "Invalid recipient") })
from, err = ParseRCPT("From:<foo@bar.com>")
assert.Equal(t, from, "")
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "Invalid recipient")
from, err = ParseRCPT("From:<foo>")
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: <foo@bar>")
assert.Equal(t, from, "")
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "Invalid recipient")
} }