parsimony/internal/ingest/publisher_test.go
tgiachi d4f706523f feat(router): the publishers post policy refuses non-publishers
- Route on a publishers list lets through a member flagged publisher, after the
  unchanged discard and loop checks, and applies the usual From header check
- anyone else gets the new ErrNotPublisher: never held, archived or queued
- ingest answers ErrNotPublisher with 550 5.7.1 only the publishers of this list may post
- tests: publisher ok, plain member and stranger refused, disabled publisher posts,
  identity mismatch held and released, discard rules first, other policies unchanged
2026-11-10 12:37:00 +01:00

31 lines
1,017 B
Go

package ingest
import (
"errors"
"testing"
"github.com/emersion/go-smtp"
"codeberg.org/squidd/parsimony/internal/store"
)
func TestANonPublisherIsRefusedPermanentlyByANewsletter(t *testing.T) {
st := newStack(t, nil)
l, _ := st.store.FindList("dev@example.org")
st.store.SetPolicies(l.ID, store.PostPublishers, store.JoinOpen, store.ArchivePrivate)
res := deliver(t, st.addr, "alice@example.com", []string{"dev@example.org"})
var se *smtp.SMTPError
if !errors.As(res["dev@example.org"], &se) || se.Code != 550 ||
se.EnhancedCode != (smtp.EnhancedCode{5, 7, 1}) || se.Message != "only the publishers of this list may post" {
t.Fatalf("want 550 5.7.1, got %v", res["dev@example.org"])
}
if st.queued(t) != 0 {
t.Fatal("nothing may be queued")
}
st.store.SetPublisher(l.ID, "alice@example.com", true)
if res := deliver(t, st.addr, "alice@example.com", []string{"dev@example.org"}); res["dev@example.org"] != nil {
t.Fatalf("a publisher posts: %v", res["dev@example.org"])
}
st.sent(t, 2)
}