Every fix here is a case where the code and the plan disagreed, and the code was wrong. Certificates (section 8.2, 8.4). The parser documented that it skipped expired entries but never checked, so an expired certificate would be served until every handshake failed. LastReload() only advanced when acme.json changed - and it does not change for sixty days - which made the timestamp risk R2 monitors indistinguishable from a watcher gone blind. Expiry is now checked on every pass, LastReload records the check and LastChange the swap, and the <7d/<24h alerts of section 8.4 exist. ARC (section 5). buildArcSealer resolved the DKIM key at startup, before runDnsReconciler had provisioned one. On a first boot ARC was disabled until someone restarted the process, which the log even admitted while offering no way for it to start. A LazySealer binds on first use instead. Health (section 8.4). There was no degraded state at all. /health now reports one - still 200, because restarting cannot fix a certificate Traefik never issued. Bounces. DSNs were sent From postmaster@lambdamail.local, a domain that does not resolve, so the notification was itself undeliverable. They now carry the configured mail host, a Message-ID, and Auto-Submitted so a vacation responder cannot loop against them. Fan-out atomicity (section 6.1). Persist ran one transaction per recipient, so a failure halfway through an alias fan-out left earlier recipients with a copy while the sender was told to retry - and the retry delivered to them twice. PersistAll commits the whole delivery or none of it. Verified against Postgres by reverting the repository to the old behaviour and confirming the new test fails on it. SMTP replies. The use case encoded replies in error text ("550 5.7.1 ...") which the adapter re-parsed by prefix, so rewording a message could turn a permanent refusal into a retry. SmtpRejection carries the decision and the adapter renders it. Repository tests. These only run with TEST_DATABASE_URL, which CI does set - so the job was red: copy and expunge seeded a 68-character digest into a CHAR(64) column, and three others used fixed digests that collide with the UNIQUE index on any re-run. A shared testBlobDigest() helper fixes both; the suite now passes twice in a row against one database. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
65 lines
2.5 KiB
Go
65 lines
2.5 KiB
Go
package valueobject
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildDsnReport_PreventsBounceLoopForEmptySender(t *testing.T) {
|
|
_, isLoop := BuildDsnReport(DsnActionFailed, "mail.local.test", "", "user@external.test", "msg123", "550 User unknown")
|
|
if !isLoop {
|
|
t.Errorf("expected loop prevention for empty sender")
|
|
}
|
|
|
|
_, isLoop = BuildDsnReport(DsnActionFailed, "mail.local.test", "<>", "user@external.test", "msg123", "550 User unknown")
|
|
if !isLoop {
|
|
t.Errorf("expected loop prevention for <> sender")
|
|
}
|
|
}
|
|
|
|
func TestBuildDsnReport_GeneratesValidMIME(t *testing.T) {
|
|
payload, isLoop := BuildDsnReport(DsnActionFailed, "mail.local.test", "sender@local.test", "recipient@remote.test", "msg123", "550 User unknown")
|
|
if isLoop || payload == nil {
|
|
t.Fatalf("unexpected loop signal for valid sender")
|
|
}
|
|
|
|
raw := string(payload)
|
|
if !strings.Contains(raw, "Content-Type: multipart/report; report-type=delivery-status") {
|
|
t.Errorf("missing multipart/report header: %s", raw)
|
|
}
|
|
if !strings.Contains(raw, "Action: failed") {
|
|
t.Errorf("missing Action: failed: %s", raw)
|
|
}
|
|
if !strings.Contains(raw, "Diagnostic-Code: smtp; 550 User unknown") {
|
|
t.Errorf("missing Diagnostic-Code: %s", raw)
|
|
}
|
|
}
|
|
|
|
// A notification whose From and Reporting-MTA name a domain that does not
|
|
// resolve is itself undeliverable, which loses the very message the sender
|
|
// most needs to see.
|
|
func TestBuildDsnReport_UsesTheConfiguredMailHost(t *testing.T) {
|
|
payload, _ := BuildDsnReport(DsnActionFailed, "mail.example.test", "sender@example.test", "recipient@remote.test", "job-1", "550 User unknown")
|
|
|
|
raw := string(payload)
|
|
if !strings.Contains(raw, "From: Mail Delivery Subsystem <postmaster@mail.example.test>") {
|
|
t.Errorf("From does not use the configured mail host: %s", raw)
|
|
}
|
|
if !strings.Contains(raw, "Reporting-MTA: dns; mail.example.test") {
|
|
t.Errorf("Reporting-MTA does not use the configured mail host: %s", raw)
|
|
}
|
|
if strings.Contains(raw, "lambdamail.local") {
|
|
t.Errorf("the placeholder host leaked into the report: %s", raw)
|
|
}
|
|
}
|
|
|
|
// RFC 3834 section 5: without Auto-Submitted a vacation responder answers the
|
|
// bounce and the two loop against each other.
|
|
func TestBuildDsnReport_MarksItselfAutomatic(t *testing.T) {
|
|
payload, _ := BuildDsnReport(DsnActionDelayed, "mail.example.test", "sender@example.test", "recipient@remote.test", "job-1", "451 deferred")
|
|
|
|
if !strings.Contains(string(payload), "Auto-Submitted: auto-replied") {
|
|
t.Errorf("the report is not marked as automatic: %s", payload)
|
|
}
|
|
}
|