feat(policy): case-insensitive address and domain matching
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user