package view import "testing" // ---- One inbound domain func TestInDomainShowsTheMockupsBoxes(t *testing.T) { out := renderSignedIn(t, "in-domain", inDomainFixture()) pageHas(t, "Inbound domain", out, `

lists.example.org

`, `OK`, `MX POINTS HERE`, `Accepted on port 25, handed to mx.internal:25 over required TLS · 4 recipients`, `action="/inbound/domains/1/dns-recheck"`, `Re-check DNS`, `

MX record

`, `published`, `value="10 mail.example.org."`, `

Upstream

`, `action="/inbound/domains/1/upstream"`, `name="host" value="mx.internal"`, `name="port" inputmode="numeric" value="25"`, `name="tls_mode"`, ``, `

Valid recipients

`, `action="/inbound/domains/1/recipients"`, `name="recipient_mode" data-list-mode="list"`, ``, `name="addresses"`, "announce@lists.example.org\ndev@lists.example.org\nowner@lists.example.org\nsecurity@lists.example.org", `

Spam filter

`, `href="#filter"`, `href="/inbound/domains/1/delete"`, `Delete domain`, ) // What has no source in this build is not drawn. pageLacks(t, "Inbound domain", out, `rspamd`, `quarantine`, `Quarantine`, `Log for this domain`, `/inbound/quarantine`, `Allow and deny`) } // The Spam filter box states what the server is set up with, and what of it the // viewer needs: the global role also gets the milter address and the name of the // variable that turns the filter on. func TestInDomainSpamFilterBoxInTheFourCases(t *testing.T) { domain := func(m Meta, on bool, milter, action string) string { p := NewInDomain(m, InDomainInput{ID: 1, Name: "lists.example.org", DNSStatus: "ok", Host: "mx.internal", Port: 25, TLSMode: "may", RecipientMode: "any"}). WithMX("mail.example.org", DNSCheck{Status: "ok"}).WithFilter(on, milter, action) return renderSignedIn(t, "in-domain", p) } ops := Meta{User: "ops", HasInbound: true} out := domain(admin(), true, "inet:antispam:11332", "accept") pageHas(t, "filter on, global", out, `on`, `
Applies to
Every inbound domain of this server
`, `
Filter
inet:antispam:11332
`, `
If the filter is down
Mail is accepted unfiltered
`) out = domain(ops, true, "inet:antispam:11332", "tempfail") pageHas(t, "filter on, domain role", out, `
Applies to
`, `Mail is deferred until it answers`) pageLacks(t, "filter on, domain role", out, `inet:antispam`, `
Filter
`, `Delete domain`, `Rarely changed`) out = domain(admin(), false, "", "") pageHas(t, "filter off, global", out, `off`, `Mail for this domain is passed to the upstream unfiltered; turning the filter on is a server setting (INBOUND_ANTISPAM_MILTER).`) pageLacks(t, "filter off, global", out, `
`, `Applies to`) out = domain(ops, false, "", "") pageHas(t, "filter off, domain role", out, `turning the filter on is a server setting, set by the server's administrator.`) pageLacks(t, "filter off, domain role", out, `INBOUND_ANTISPAM_MILTER`) // An action nobody can name is not guessed at. out = domain(admin(), true, "unix:/run/spam.sock", "") pageHas(t, "filter on, unknown action", out, `unix:/run/spam.sock`) pageLacks(t, "filter on, unknown action", out, `If the filter is down`) } // The stamp, the record's tag and the menu say the same about the MX check. func TestInDomainMXStates(t *testing.T) { page := func(c DNSCheck) string { p := NewInDomain(admin(), InDomainInput{ID: 1, Name: "lists.example.org", DNSStatus: c.Status, Host: "mx.internal", Port: 25, TLSMode: "may"}). WithMX("mail.example.org", c).WithFilter(false, "", "") return renderSignedIn(t, "in-domain", p) } out := page(DNSCheck{Status: "error", Detail: "No MX points at mail.example.org (this server).", Found: []string{"10 mx.other.net."}}) pageHas(t, "mismatch", out, `FAIL`, `NO MX HERE`, `sp-fail`, `mismatch`, `value="10 mx.other.net."`, `No MX points at mail.example.org (this server).`, `fail`) out = page(DNSCheck{Status: "error", Detail: "No MX record is published at lists.example.org."}) pageHas(t, "missing", out, `missing`, `No MX record is published at lists.example.org.`) pageLacks(t, "missing", out, `In DNS now`) out = page(DNSCheck{Status: "unknown"}) pageHas(t, "unknown", out, `WARN`, `NOT CHECKED`, `not checked`, `unknown`) } // A domain with nothing saved yet says so in its lead; any-recipient mode shows // an empty list, and what was refused is a flash above the boxes. func TestInDomainNewAndRefused(t *testing.T) { p := NewInDomain(admin(), InDomainInput{ID: 3, Name: "new.example.org", DNSStatus: "unknown", Host: "", Port: 25, TLSMode: "may", RecipientMode: "list"}). WithMX("mail.example.org", DNSCheck{Status: "unknown"}).WithFilter(false, "", "").WithResult("", "Host is required.") out := renderSignedIn(t, "in-domain", p) pageHas(t, "new domain", out, `Not accepting mail yet: no upstream is saved · no recipients listed`, `
`, `Host is required.`, `0`) p = NewInDomain(admin(), InDomainInput{ID: 3, Name: "new.example.org", Host: "h", Port: 25, TLSMode: "none", RecipientMode: "any"}). WithMX("mail.example.org", DNSCheck{Status: "ok"}).WithFilter(false, "", "").WithResult("Upstream saved.", "") out = renderSignedIn(t, "in-domain", p) pageHas(t, "any recipient", out, `without TLS · any recipient`, ``, ``, `any`, `
`, `Upstream saved.`) } func TestInDomainEscapesWhatPeopleTyped(t *testing.T) { p := NewInDomain(admin(), InDomainInput{ID: 1, Name: ``, Host: `">`, Port: 25, TLSMode: "may", RecipientMode: "list", Addresses: []string{`x`}}). WithMX("mail.example.org", DNSCheck{Status: "error", Found: []string{`x`}}).WithFilter(true, `inet::1`, "accept").WithResult("", `bad`) out := renderSignedIn(t, "in-domain", p) pageLacks(t, "Inbound domain", out, `