A bounce could be recorded as a successful delivery. The log-tailer's Fixed: - A bounce could be recorded as a successful delivery. The log-tailer's - Log-tailer resumes where it stopped instead of jumping to end-of-file on - Level-2 rate limit no longer overshoots under concurrency: messages that Changed: - The project has a single public home: `github.com/mixeme/selfpost`. Codeberg - Code comments no longer cite the archived specification. References like - `docs/code-review.md` is gone. Its plan is finished — phases 0 (bar the - `docs/architecture.md` gained a *Code layers* section: a diagram of - Phase 1 doc/code hygiene (`docs/code-review.md`): removed ~30 stale … (1 more in CHANGELOG) Security: - Pre-release security review (plan § D, model Fable, 2026-08-06): full pass - `saslpasswd2` argv: the application login is now passed after a `--` Added: - Optional password encryption for the two secret-bearing downloads (plan - Domain import accepts an encrypted export: the envelope is detected by its - `selfpost-backup` writes encrypted archives and reads them back: - `TestParseDelivery` covers the exotic mail.log shapes the review asked for - docs: README *Encrypting a backup or export*; `docs/security.md` § … (14 more in CHANGELOG) Removed: - docs: `security.md` — accepted risk «restore old backup revives session rows» Changed: - docs: `implementation-plan.md` trimmed to the sole open v1.x gate — pre-release - docs: `architecture.md` — sessions (SQLite, idle renew, password change), - docs: `development.md` — expanded e2e stack and `release.yml` matrix workflow. - docs: `security.md` — accepted risk for send-log rows stuck at `queued` after - docs: `roadmap.md` — optional send-log / `mail.log` follow-ups under v1.x tail. … (10 more in CHANGELOG) Full detail: CHANGELOG.md (0.5.0).
119 lines
3.2 KiB
Go
119 lines
3.2 KiB
Go
package postfix
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestRenderSenderLoginMaps(t *testing.T) {
|
|
// Deliberately unsorted, with two logins sharing one wildcard key
|
|
// (many-to-one, architecture.md § Mail path) to exercise merge + sort.
|
|
bindings := []Binding{
|
|
{"@zeta.example", "z1"},
|
|
{"alerts@alpha.example", "a-listed"},
|
|
{"@alpha.example", "a2"},
|
|
{"@alpha.example", "a1"},
|
|
}
|
|
got, err := renderSenderLoginMaps(bindings)
|
|
if err != nil {
|
|
t.Fatalf("renderSenderLoginMaps: %v", err)
|
|
}
|
|
want := "@alpha.example a1,a2\n" +
|
|
"@zeta.example z1\n" +
|
|
"alerts@alpha.example a-listed\n"
|
|
if string(got) != want {
|
|
t.Errorf("map =\n%q\nwant\n%q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestRenderSenderLoginMapsEmpty(t *testing.T) {
|
|
got, err := renderSenderLoginMaps(nil)
|
|
if err != nil {
|
|
t.Fatalf("renderSenderLoginMaps(nil): %v", err)
|
|
}
|
|
if len(got) != 0 {
|
|
t.Errorf("expected empty map, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestRenderSenderLoginMapsDedupesLogin(t *testing.T) {
|
|
bindings := []Binding{
|
|
{"@a.example", "dup"},
|
|
{"@a.example", "dup"},
|
|
}
|
|
got, err := renderSenderLoginMaps(bindings)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(got) != "@a.example dup\n" {
|
|
t.Errorf("map = %q, want single deduped login", got)
|
|
}
|
|
}
|
|
|
|
func TestAssertMapSafeRejectsInjection(t *testing.T) {
|
|
bad := []struct{ addr, login string }{
|
|
{"@exa mple.com", "log"},
|
|
{"@example.com\nx y z", "log"},
|
|
{"@example.com", "log,evil"},
|
|
{"@example.com", "log in"},
|
|
{"@example.com", "log@realm"}, // '@' would confuse sasldb realm handling
|
|
{"", "log"},
|
|
{"@example.com", ""},
|
|
}
|
|
for _, b := range bad {
|
|
if err := assertMapSafe(b.addr, b.login); err == nil {
|
|
t.Errorf("assertMapSafe(%q,%q) = nil, want error", b.addr, b.login)
|
|
}
|
|
}
|
|
if err := assertMapSafe("alerts@example.com", "app_1-x"); err != nil {
|
|
t.Errorf("assertMapSafe of a clean pair errored: %v", err)
|
|
}
|
|
}
|
|
|
|
func newTestPostfix(t *testing.T) (*Postfix, *int) {
|
|
t.Helper()
|
|
dir := t.TempDir()
|
|
reloads := 0
|
|
p := New(dir)
|
|
p.reload = func() error { reloads++; return nil }
|
|
return p, &reloads
|
|
}
|
|
|
|
func TestRebuildSenderLoginMapsWritesAndReloads(t *testing.T) {
|
|
p, reloads := newTestPostfix(t)
|
|
if err := p.RebuildSenderLoginMaps([]Binding{{"@example.com", "app1"}}); err != nil {
|
|
t.Fatalf("RebuildSenderLoginMaps: %v", err)
|
|
}
|
|
if *reloads != 1 {
|
|
t.Errorf("reload called %d times, want 1", *reloads)
|
|
}
|
|
data, err := os.ReadFile(p.senderLoginMapsPath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(data) != "@example.com app1\n" {
|
|
t.Errorf("map file = %q", data)
|
|
}
|
|
}
|
|
|
|
func TestRebuildRejectsUnsafeWithoutWriting(t *testing.T) {
|
|
p, reloads := newTestPostfix(t)
|
|
// Seed a known-good file so we can prove the failed rebuild left it untouched.
|
|
if err := p.RebuildSenderLoginMaps([]Binding{{"@good.example", "ok"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
before, _ := os.ReadFile(p.senderLoginMapsPath)
|
|
|
|
err := p.RebuildSenderLoginMaps([]Binding{{"@bad.example", "evil\nlogin"}})
|
|
if err == nil {
|
|
t.Fatal("expected rebuild to reject unsafe login")
|
|
}
|
|
after, _ := os.ReadFile(p.senderLoginMapsPath)
|
|
if string(after) != string(before) {
|
|
t.Errorf("map file changed on failed rebuild: %q", after)
|
|
}
|
|
if *reloads != 1 {
|
|
t.Errorf("reload called %d times, want 1 (no reload on failure)", *reloads)
|
|
}
|
|
}
|