Smail/backend/utils/validation/notification_test.go
smail 596b233999
Some checks are pending
Security Checks / security (push) Waiting to run
feat: 移除notification+system历史发信地址兼容并发布V2.13.1部署包
2026-10-18 01:44:40 +08:00

40 lines
1.5 KiB
Go

package validation
import "testing"
func TestNotificationAddressAndSenderValidation(t *testing.T) {
domain := "example.com"
primarySender := NotificationAddress(domain)
if primarySender != "notification@example.com" {
t.Fatalf("NotificationAddress want notification@example.com, got %s", primarySender)
}
domains := []string{"example.com", "other.com"}
if !IsNotificationAddress("notification@example.com", domains) {
t.Fatalf("notification@example.com should be recognized as notification address")
}
if IsNotificationAddress("notification+system@example.com", domains) {
t.Fatalf("notification+system@example.com should NOT be notification address")
}
if !IsNotificationAddress("NOTIFICATION@OTHER.COM", domains) {
t.Fatalf("case insensitive notification address check failed")
}
if IsNotificationAddress("user@example.com", domains) {
t.Fatalf("user@example.com should NOT be notification address")
}
if !IsAuthorizedNotificationSender("notification@example.com", domain) {
t.Fatalf("notification@example.com should be authorized sender")
}
if IsAuthorizedNotificationSender("notification+system@example.com", domain) {
t.Fatalf("notification+system@example.com should NOT be authorized notification sender")
}
if IsAuthorizedNotificationSender("attacker@example.com", domain) {
t.Fatalf("attacker@example.com should NOT be authorized notification sender")
}
if IsAuthorizedNotificationSender("notification@attacker.com", domain) {
t.Fatalf("notification@attacker.com should NOT be authorized notification sender for domain")
}
}