Files
Squid a79cb61104 Add Migadu domain admin with shared lists, compaction, and safer apply.
Build the Go API and React UI for managing domain denylist/allowlist/recipient
deny and spam settings, plus shared lists that import/apply across domains with
wildcard compaction, entry verification, and Migadu-friendly list encoding
(including per-domain recipient filtering and rejection bisect on apply).
2026-07-26 21:50:26 +02:00

46 lines
1.4 KiB
Go

package lists
import "testing"
func TestValidateEntries(t *testing.T) {
t.Parallel()
tests := []struct {
name string
entries []string
wantN int
}{
{name: "empty list", entries: nil, wantN: 0},
{name: "valid user", entries: []string{"user@example.com"}, wantN: 0},
{name: "valid star domain", entries: []string{"*@example.com"}, wantN: 0},
{name: "valid suffix glob", entries: []string{"*@*.shop", "*@*.ac.in"}, wantN: 0},
{name: "valid plus addressing", entries: []string{"a.b+c@mail-host.co.uk"}, wantN: 0},
{name: "repair then valid", entries: []string{"*vsa.instalily.ai"}, wantN: 0},
{name: "missing at", entries: []string{"not-an-email"}, wantN: 1},
{name: "bare domain", entries: []string{"example.com"}, wantN: 1},
{name: "spaces", entries: []string{"user @example.com"}, wantN: 1},
{name: "bad domain", entries: []string{"user@-example.com"}, wantN: 1},
{name: "single label domain", entries: []string{"*@localhost"}, wantN: 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := ValidateEntries(tt.entries)
if len(got) != tt.wantN {
t.Fatalf("ValidateEntries() issues=%v want %d", got, tt.wantN)
}
})
}
}
func TestValidateEntryReasons(t *testing.T) {
t.Parallel()
if got := ValidateEntry(""); got == "" {
t.Fatal("expected empty reason")
}
if got := ValidateEntry("lisa@simpsons.com"); got != "" {
t.Fatalf("unexpected: %s", got)
}
}