panel-redesign: Inbound domains, domain and delete on the kit; Spam filter box
Stage 2, step 5. Written by Sonnet, reviewed by Opus.
- Three pages named after their mockups: in-domains, in-domain,
in-domain-delete, with typed page data (view/inbound.go), fixtures
and tests. The engine pages inbound, inbound_domain and
inbound_delete are gone with their templates and are off
legacy_pages.txt.
- The Spam filter box (plan, Who sees what). The panel now reads
INBOUND_ANTISPAM_MILTER and INBOUND_ANTISPAM_MILTER_ACTION, with the
semantics of build/postfix-config.sh (on only with the inbound relay
on and a milter set; accept | tempfail). It reports them, nothing
more:
on Applies to / Filter (the address, global role only) / If the
filter is down (accepted unfiltered | deferred)
off one sentence; the variable is named for the global role only
The list shows "Spam filter on|off" in its head.
- Handlers pass typed data; routes, POST targets, field names,
validation and authorization (global: all inbound domains; domain
role: the assigned ones, another tenant's id is a 404; add and
delete are global-only) are unchanged. A test saves the upstream and
recipients forms untouched and finds the domain unchanged.
Left out of the mockups' Spam filter box and menu - no source before
inbound-antispam-panel (2.1): the engine name, the quarantine row, the
"refused at the door, see the log" row, the lists row, "Log for this
domain". Also "Checked N min ago" on the MX box: the check carries no
time.
Not done: the filter's socket on Health and Overview. internal/health
checks a unix socket by stat; the documented form of the filter's
address is inet:host:port and needs a dial that does not exist yet.
Differences from the mockups, for the owner:
- refusals and confirmations are the kit flash above the boxes;
- the MX tag is coloured by the check in every state; an MX that
points elsewhere shows "In DNS now";
- the lead of the domain page follows what is saved ("Not accepting
mail yet: no upstream is saved");
- the delete page lists only what the domain has;
- /help#inbound opens Help at the top until the Help step.
Evidence
- docs/assets/panel-redesign/evidence/in-domains.png, in-domain.png,
in-domain-delete.png: 1440 px wide, headless Edge, real templates
served locally with their fixtures (filter on) - NOT from the
container (no Docker on this machine).
- panel/audit.js on the three pages at 1440 and 1280: 352 texts
checked, problems: [].
- That the panel process sees the two variables inside the container
is read from supervisord.conf and entrypoint.sh, not run.
- go test -count=1 ./internal/web/... ./cmd/panel
ok internal/web
ok internal/web/auth
ok internal/web/handlers
ok internal/web/validate
ok internal/web/view
ok cmd/panel
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// ---- Inbound domains
|
||||
|
||||
// The global role adds and deletes domains; a domain administrator sees the
|
||||
// list alone, so the page has no add box, no Delete link, and numbers the table
|
||||
// box 01.
|
||||
func TestInDomainsOffersAddAndDeleteToTheGlobalRoleOnly(t *testing.T) {
|
||||
out := renderSignedIn(t, "in-domains", inDomainsFixture())
|
||||
pageHas(t, "Inbound domains", out,
|
||||
`<h1 class="title is-3">Inbound domains</h1>`, `<h2>Add a domain</h2>`, `action="/inbound/domains"`, `name="name"`,
|
||||
`2 domains`, `<th>TLS to upstream</th>`, `href="/inbound/domains/1"><strong>lists.example.org</strong>`,
|
||||
`<span class="tag is-success is-light">MX</span>`, `>mx.internal:25<`, `4 addresses`, `any address`, `>10.0.4.12:2525<`,
|
||||
`<span class="tag is-success is-light">required</span>`, `<span class="tag is-light">opportunistic</span>`,
|
||||
`>Delete</a>`, `href="/inbound/domains/2/delete"`,
|
||||
`The MX tag is green when at least one MX of the domain points at this server.`,
|
||||
)
|
||||
|
||||
p := NewInDomains(Meta{User: "ops", HasInbound: true}, false).WithRows([]InDomainRow{
|
||||
NewInDomainRow(InDomainInput{ID: 1, Name: "lists.example.org", DNSStatus: "ok", Host: "mx.internal", Port: 25,
|
||||
TLSMode: "encrypt", RecipientMode: "list", RecipientCount: 1}, false),
|
||||
})
|
||||
out = renderSignedIn(t, "in-domains", p)
|
||||
pageHas(t, "Inbound domains", out, `<span class="sp-no">01</span><h2>Domains</h2>`, `1 domain`, `1 address<`)
|
||||
pageLacks(t, "Inbound domains", out, `Add a domain`, `name="name"`, `>Delete</a>`, `/delete`)
|
||||
}
|
||||
|
||||
// The MX tag takes its colour from the check and its word stays MX; an upstream
|
||||
// not yet saved is a dash and TLS that is off is not dressed up as fine.
|
||||
func TestInDomainRowsWordTheStoresFields(t *testing.T) {
|
||||
p := NewInDomains(admin(), true).WithRows([]InDomainRow{
|
||||
NewInDomainRow(InDomainInput{ID: 7, Name: "new.example.org", DNSStatus: "error", TLSMode: "none", RecipientMode: "list"}, true),
|
||||
NewInDomainRow(InDomainInput{ID: 8, Name: "warn.example.org", DNSStatus: "warn", Host: "h", Port: 25, TLSMode: "may", RecipientMode: "list", RecipientCount: 2}, true),
|
||||
NewInDomainRow(InDomainInput{ID: 9, Name: "unk.example.org", DNSStatus: "unknown", TLSMode: "may", RecipientMode: "any"}, true),
|
||||
})
|
||||
out := renderSignedIn(t, "in-domains", p)
|
||||
pageHas(t, "Inbound domains", out,
|
||||
`<span class="tag is-danger is-light">MX</span>`, `<span class="tag is-warning is-light">MX</span>`, `<span class="tag is-light">MX</span>`,
|
||||
`>—<`, `0 addresses`, `<span class="tag is-light">off</span>`, `2 addresses`, `3 domains`)
|
||||
}
|
||||
|
||||
func TestInDomainsEmptyAndRefused(t *testing.T) {
|
||||
p := NewInDomains(admin(), true).WithRows(nil).WithResult("", "That inbound domain is already configured.", "lists.example.org")
|
||||
out := renderSignedIn(t, "in-domains", p)
|
||||
pageHas(t, "Inbound domains", out, `No inbound domains yet. Add the first one above`,
|
||||
`<div class="notification is-danger is-light">`, `That inbound domain is already configured.`, `value="lists.example.org"`, `0 domains`)
|
||||
pageLacks(t, "Inbound domains", out, `<table`)
|
||||
// the flash sits between the head and the first box
|
||||
if strings.Index(out, `class="notification`) < strings.Index(out, `class="sp-head"`) ||
|
||||
strings.Index(out, `class="notification`) > strings.Index(out, `class="box"`) {
|
||||
t.Error("the flash is not between page_head and the first box")
|
||||
}
|
||||
|
||||
out = renderSignedIn(t, "in-domains", NewInDomains(admin(), true).WithResult("Inbound domain deleted.", "", ""))
|
||||
pageHas(t, "Inbound domains", out, `<div class="notification is-success is-light">`, `Inbound domain deleted.`)
|
||||
|
||||
// A domain administrator with nothing listed is not told to add anything.
|
||||
out = renderSignedIn(t, "in-domains", NewInDomains(Meta{User: "ops", HasInbound: true}, false))
|
||||
pageHas(t, "Inbound domains", out, `No inbound domains yet.`)
|
||||
pageLacks(t, "Inbound domains", out, `Add the first one`)
|
||||
}
|
||||
|
||||
func TestInDomainsEscapesWhatPeopleTyped(t *testing.T) {
|
||||
p := NewInDomains(admin(), true).WithRows([]InDomainRow{
|
||||
NewInDomainRow(InDomainInput{ID: 1, Name: `<script>alert(1)</script>`, Host: `"><img src=x>`, Port: 25}, true),
|
||||
}).WithResult("", "bad", `"><i>`)
|
||||
out := renderSignedIn(t, "in-domains", p)
|
||||
pageLacks(t, "Inbound domains", out, `<script>alert(1)`, `<img src=x>`, `<i>`)
|
||||
}
|
||||
|
||||
// ---- Delete an inbound domain
|
||||
|
||||
func TestInDomainDeleteNamesWhatGoesWithIt(t *testing.T) {
|
||||
out := renderSignedIn(t, "in-domain-delete", inDomainDeleteFixture())
|
||||
pageHas(t, "Delete", out,
|
||||
`<h1 class="title is-3">Delete lists.example.org</h1>`, `<div class="box sp-danger-zone">`, `<h2>This cannot be undone</h2>`,
|
||||
`Deleting the inbound domain <strong>lists.example.org</strong> will:`,
|
||||
`stop accepting mail for it on port 25 — senders get a relay-denied reply;`,
|
||||
`remove its upstream and its 4 listed recipients.`, `Outbound domains are not touched.`,
|
||||
`<form method="post" action="/inbound/domains/1/delete">`, `class="button is-danger"`, `Delete lists.example.org</button>`,
|
||||
`href="/inbound/domains/1">Keep it</a>`,
|
||||
)
|
||||
|
||||
// Only what the domain really has is named.
|
||||
out = renderSignedIn(t, "in-domain-delete", NewInDomainDelete(admin(), 1, "lists.example.org", true, 0))
|
||||
pageHas(t, "Delete", out, `remove its upstream.`)
|
||||
pageLacks(t, "Delete", out, `recipient`)
|
||||
out = renderSignedIn(t, "in-domain-delete", NewInDomainDelete(admin(), 1, "lists.example.org", false, 1))
|
||||
pageHas(t, "Delete", out, `remove its 1 listed recipient.`)
|
||||
pageLacks(t, "Delete", out, `upstream`)
|
||||
out = renderSignedIn(t, "in-domain-delete", NewInDomainDelete(admin(), 1, "lists.example.org", false, 0))
|
||||
pageHas(t, "Delete", out, `stop accepting mail for it`)
|
||||
pageLacks(t, "Delete", out, `upstream`, `recipient`)
|
||||
}
|
||||
Reference in New Issue
Block a user