31 lines
693 B
Go
31 lines
693 B
Go
package policy
|
|
|
|
import "testing"
|
|
|
|
func TestMatchAddress(t *testing.T) {
|
|
wl := []string{"bob@example.com", "@trusted.com"}
|
|
cases := []struct {
|
|
addr string
|
|
want bool
|
|
}{
|
|
{"bob@example.com", true},
|
|
{"BOB@Example.com", true},
|
|
{`"Bob" <bob@example.com>`, true},
|
|
{"alice@trusted.com", true},
|
|
{"alice@untrusted.com", false},
|
|
{"eve@example.com", false},
|
|
{"", false},
|
|
}
|
|
for _, c := range cases {
|
|
if got := MatchAddress(wl, c.addr); got != c.want {
|
|
t.Fatalf("MatchAddress(%q)=%v want %v", c.addr, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNormalizeAddr(t *testing.T) {
|
|
if got := NormalizeAddr(`"Bob Smith" <Bob@Example.COM>`); got != "bob@example.com" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
}
|