- 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.
28 lines
621 B
Go
28 lines
621 B
Go
package smtp
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestOutboxRetryDelay_exponentialCap(t *testing.T) {
|
|
d0 := OutboxRetryDelay(0)
|
|
if d0 != baseRetryDelay {
|
|
t.Fatalf("retry 0 = %v, want %v", d0, baseRetryDelay)
|
|
}
|
|
d3 := OutboxRetryDelay(3)
|
|
if d3 != 4*time.Minute {
|
|
t.Fatalf("retry 3 = %v, want 4m", d3)
|
|
}
|
|
dLarge := OutboxRetryDelay(20)
|
|
if dLarge != maxRetryDelay {
|
|
t.Fatalf("retry 20 = %v, want cap %v", dLarge, maxRetryDelay)
|
|
}
|
|
if OutboxRetryDelay(1) <= OutboxRetryDelay(0) {
|
|
t.Fatal("expected increasing backoff")
|
|
}
|
|
if OutboxRetryDelay(10) > time.Hour {
|
|
t.Fatal("delay must not exceed one hour")
|
|
}
|
|
}
|