Smail/backend/utils/validation/sender_test.go
smail f60d3b0880
Some checks are pending
Security Checks / security (push) Waiting to run
整理前后端与测试构建目录并完善配置和安全引导
统一 frontend、backend、test、test-log 和 out 目录,更新构建、部署及测试入口;纳入配置管理兼容与首次安全引导修复;排除本机配置、密钥和测试产物。
2026-09-05 19:19:52 +08:00

32 lines
1.3 KiB
Go

package validation
import "testing"
func TestIsAuthorizedSender(t *testing.T) {
domains := []string{"example.com", "mail.example.net"}
tests := []struct {
name string
address string
account string
admin bool
want bool
}{
{name: "matching account", address: "alice@example.com", account: "alice", want: true},
{name: "case insensitive account", address: "Alice@EXAMPLE.COM", account: "alice", want: true},
{name: "external domain", address: "alice@external.example", account: "alice", want: false},
{name: "different account", address: "bob@example.com", account: "alice", want: false},
{name: "admin local alias", address: "alias@mail.example.net", account: "admin", admin: true, want: true},
{name: "admin external domain", address: "alias@external.example", account: "admin", admin: true, want: false},
{name: "display name rejected", address: "Alice <alice@example.com>", account: "alice", want: false},
{name: "missing local part", address: "@example.com", account: "alice", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsAuthorizedSender(tt.address, tt.account, tt.admin, domains); got != tt.want {
t.Fatalf("IsAuthorizedSender(%q) = %v, want %v", tt.address, got, tt.want)
}
})
}
}