mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-12-02 18:54:04 +00:00
115 lines
2.9 KiB
Go
115 lines
2.9 KiB
Go
|
package smtp
|
||
|
|
||
|
import (
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestMAILParsing(t *testing.T) {
|
||
|
from, err := ParseMAIL("From:<foo@bar>")
|
||
|
assert.Equal(t, from, "foo@bar")
|
||
|
assert.Nil(t, err)
|
||
|
|
||
|
from, err = ParseMAIL("From:<foo@bar.com>")
|
||
|
assert.Equal(t, from, "foo@bar.com")
|
||
|
assert.Nil(t, err)
|
||
|
|
||
|
from, err = ParseMAIL("From:<foo>")
|
||
|
assert.Equal(t, from, "foo")
|
||
|
assert.Nil(t, err)
|
||
|
|
||
|
from, err = ParseMAIL("To:<foo@bar>")
|
||
|
assert.Equal(t, from, "")
|
||
|
assert.NotNil(t, err)
|
||
|
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) {
|
||
|
from, err := ParseRCPT("To:<foo@bar>")
|
||
|
assert.Equal(t, from, "foo@bar")
|
||
|
assert.Nil(t, err)
|
||
|
|
||
|
from, err = ParseRCPT("To:<foo@bar.com>")
|
||
|
assert.Equal(t, from, "foo@bar.com")
|
||
|
assert.Nil(t, err)
|
||
|
|
||
|
from, err = ParseRCPT("To:<foo>")
|
||
|
assert.Equal(t, from, "foo")
|
||
|
assert.Nil(t, err)
|
||
|
|
||
|
from, err = ParseRCPT("From:<foo@bar>")
|
||
|
assert.Equal(t, from, "")
|
||
|
assert.NotNil(t, err)
|
||
|
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")
|
||
|
}
|