- store: SQLite (WAL, foreign keys ON, CGO-free driver) + the embedded migration runner; each module's migrations are name-prefixed (D-012) - audit: the append-only audit log; the actor threads via context (R-1) - users: the user_id/GUID/email anchors (D-013) - config: the YAML settings file (D-035) + validation - httpx: cookies · loopback detection · trusted-proxy XFF · CSRF · security headers · redaction - middleware: correlation id · audit · rate limiting - mail: the invite/recovery mailer seam - server: the core DOOR — the resolution switch, the dispatch registry (RegisterModule), the role gates, /setup · enroll/login · recovery flows, the reserved `static` workflow, and the loopback-only bootstrap (D-025)
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package mail_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"git.lohmar.co.uk/cclohmar/NextMyDay/internal/core/mail"
|
|
)
|
|
|
|
// TestFakeRecordsAndFilters: the test seam records every message and can filter
|
|
// by recipient (case-insensitive).
|
|
func TestFakeRecordsAndFilters(t *testing.T) {
|
|
f := mail.NewFake()
|
|
ctx := context.Background()
|
|
|
|
if err := f.Send(ctx, mail.Message{To: "a@example.com", Subject: "one", Body: "hi"}); err != nil {
|
|
t.Fatalf("Send: %v", err)
|
|
}
|
|
if err := f.Send(ctx, mail.Message{To: "B@Example.com", Subject: "two"}); err != nil {
|
|
t.Fatalf("Send: %v", err)
|
|
}
|
|
|
|
if got := len(f.Sent()); got != 2 {
|
|
t.Fatalf("Sent len = %d, want 2", got)
|
|
}
|
|
toB := f.To("b@example.com")
|
|
if len(toB) != 1 || toB[0].Subject != "two" {
|
|
t.Errorf("To(b@example.com) = %+v, want the second message", toB)
|
|
}
|
|
if len(f.To("nobody@example.com")) != 0 {
|
|
t.Error("To returned a message for an unknown recipient")
|
|
}
|
|
}
|
|
|
|
// TestNopSend: the unconfigured fallback discards silently.
|
|
func TestNopSend(t *testing.T) {
|
|
if err := (mail.Nop{}).Send(context.Background(), mail.Message{To: "x@example.com"}); err != nil {
|
|
t.Errorf("Nop.Send = %v, want nil", err)
|
|
}
|
|
}
|
|
|
|
// TestSMTPRequiresHost: the SMTP mailer fails closed without a host.
|
|
func TestSMTPRequiresHost(t *testing.T) {
|
|
m := mail.NewSMTP("", 25, "", "", "myday@example.com")
|
|
if err := m.Send(context.Background(), mail.Message{To: "x@example.com"}); err == nil {
|
|
t.Error("SMTP.Send with no host = nil, want an error")
|
|
}
|
|
}
|