test / test (push) Waiting to run
The panel's signer is the only one. Gone: the opendkim package and its
configuration, the syslog-relay and opendkim programs, /dev/log and
/run/opendkim, the reload by USR1 through supervisord
(internal/supervisor/supervisor.go), internal/syslogrelay, the port of
OpenDKIM's From: parser (internal/milter/mailparse.go and its probe,
harness and test/upstream scripts), OPENDKIM_SOCKET and OPENDKIM_DIR.
Keys: internal/domain/keys.go (Keys, NewKeys, DKIM_DIR=/data/dkim) keeps
the keys and writes a selector table, /data/dkim/selectors ("<name>
<selector>"), which the signer reads in place of the KeyTable - it reads
no database, as the sender check reads none. The table is written before
the signer serves (EnsureServerSigned moved there from the notifier).
Keys and table 0600, directories 0700, the panel's. The entrypoint copies
/data/opendkim/keys once, as the panel user, into /data/dkim.new renamed
when whole, and stops the start if the copy fails; /data/opendkim is left
for a rollback to 2.7.x.
Sender check: one RFC 5322 address as a mail program reads it, held
against the bindings; the 256-byte refusal and the texts naming OpenDKIM
go. Allowed() folded the domain through strings.ToLower, which makes the
Kelvin sign a "k" - the comparison with OpenDKIM's reading had hidden it;
it folds ASCII only now.
Health: two dkim-signer rows (applications, notifications) in Milter
sockets, opendkim out of the liveness set; the card no longer takes any
row with a note for the spam filter. Texts as in the design commit.
KILL stays in deploy/docker-compose.yml: measured on the test server,
root without it cannot signal a process of another uid - supervisord
stopping the panel, Postfix's master its children. The plan's "only use
was the reload" was wrong; the comment now gives the real uses.
e2e: one signature, the panel's, verified by dkimpy; the /data/dkim modes;
the OpenDKIM log and process checks, testNeverSignedForAnother and the
cited opendkim, libopendkim11 and libmilter1.0.1 go.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
2.9 KiB
Go
97 lines
2.9 KiB
Go
package domain
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/mixeme/selfpost/internal/store"
|
|
)
|
|
|
|
// countingApps is fakeApps that counts the sender map's rebuilds and can
|
|
// fail them.
|
|
type countingApps struct {
|
|
fakeApps
|
|
resyncs int
|
|
resyncErr error
|
|
}
|
|
|
|
func (c *countingApps) Resync() error {
|
|
c.resyncs++
|
|
return c.resyncErr
|
|
}
|
|
|
|
// A deletion that fails after the domain's row is gone says the domain is
|
|
// deleted, and runs every rebuild anyway: the sender map was left naming the
|
|
// purged logins when the signing tables failed first (audit 2026-10-12, L17).
|
|
// The key stays while the selector table may still name it.
|
|
func TestDeleteRunsEveryRebuildAndSaysTheDomainIsGone(t *testing.T) {
|
|
apps := &countingApps{}
|
|
s, keys := newTestService(t, apps)
|
|
d, err := s.Add("gone.example")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
keyDir := filepath.Join(keys.keysDir, d.Name)
|
|
apps.resyncs = 0
|
|
|
|
// A directory where the table goes: no file can be renamed over it.
|
|
if err := os.Remove(keys.selectorsPath); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(keys.selectorsPath, "x"), 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = s.Delete(d.ID)
|
|
if !errors.Is(err, ErrDeletedIncomplete) {
|
|
t.Fatalf("Delete with the selector table unwritable = %v, want ErrDeletedIncomplete", err)
|
|
}
|
|
if _, err := s.Get(d.ID); !errors.Is(err, store.ErrDomainNotFound) {
|
|
t.Errorf("the domain is still in the registry: %v", err)
|
|
}
|
|
if apps.resyncs != 1 {
|
|
t.Errorf("the sender map was rebuilt %d times, want once", apps.resyncs)
|
|
}
|
|
if _, err := os.Stat(keyDir); err != nil {
|
|
t.Errorf("the key went while the tables may still name it: %v", err)
|
|
}
|
|
|
|
// Reload configuration finishes the deletion: the tables rebuilt, the
|
|
// key of a domain that is gone goes too; the others' stay.
|
|
if err := os.RemoveAll(keys.selectorsPath); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
keep, err := s.Add("kept.example")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.Resync(); err != nil {
|
|
t.Fatalf("Resync: %v", err)
|
|
}
|
|
if _, err := os.Stat(keyDir); !os.IsNotExist(err) {
|
|
t.Errorf("the deleted domain's key is still there after Resync: %v", err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(keys.keysDir, keep.Name)); err != nil {
|
|
t.Errorf("Resync removed a domain's key: %v", err)
|
|
}
|
|
}
|
|
|
|
// The sender map failing is the same: deleted, said so; the tables were
|
|
// rebuilt, so the key goes.
|
|
func TestDeleteWithTheSenderMapFailing(t *testing.T) {
|
|
apps := &countingApps{resyncErr: errors.New("postfix away")}
|
|
s, keys := newTestService(t, apps)
|
|
d, err := s.Add("gone.example")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
keyDir := filepath.Join(keys.keysDir, d.Name)
|
|
if err := s.Delete(d.ID); !errors.Is(err, ErrDeletedIncomplete) {
|
|
t.Fatalf("Delete with the sender map failing = %v, want ErrDeletedIncomplete", err)
|
|
}
|
|
if _, err := os.Stat(keyDir); !os.IsNotExist(err) {
|
|
t.Errorf("the key is still there after the table was rebuilt: %v", err)
|
|
}
|
|
}
|