ultisuite-backend/internal/api/mail/idempotency_test.go
R3D347HR4Y 4eadb91a64 Enhance mail API with rate limiting, idempotency, and attachment management
- Added rate limiting for outbound email sends to prevent abuse, implemented in `internal/api/mail/sendguard`.
- Introduced idempotency key support for email sending to avoid duplicate submissions.
- Enhanced attachment handling with new limits and validation in `internal/api/mail/limits`.
- Updated outbox processing to include retry logic and circuit breaker for SMTP failures.
- Improved HTML sanitization for email content to enhance security.
- Added unit tests for new features, ensuring robust functionality and error handling.
- Updated configuration options in `.env.example` for new mail settings.
2026-05-22 17:19:16 +02:00

31 lines
711 B
Go

package mail
import "testing"
func TestNormalizeIdempotencyKey(t *testing.T) {
t.Run("empty allowed", func(t *testing.T) {
key, ok := normalizeIdempotencyKey("")
if !ok || key != "" {
t.Fatalf("got %q ok=%v", key, ok)
}
})
t.Run("valid", func(t *testing.T) {
key, ok := normalizeIdempotencyKey(" send-abc-123_456 ")
if !ok || key != "send-abc-123_456" {
t.Fatalf("got %q ok=%v", key, ok)
}
})
t.Run("too short", func(t *testing.T) {
_, ok := normalizeIdempotencyKey("short")
if ok {
t.Fatal("expected invalid")
}
})
t.Run("invalid chars", func(t *testing.T) {
_, ok := normalizeIdempotencyKey("bad key with spaces!!!!")
if ok {
t.Fatal("expected invalid")
}
})
}