package handlers import ( "net/http" "net/url" "reflect" "testing" ) // The page of one inbound domain is filled from the store, the DNS checker and // the filter settings; each form's refusal comes back on it as a flash. func TestInboundDomainPageFromTheStore(t *testing.T) { h, st := inboundHandlers(t) d, err := st.AddInboundDomain("lists.example.com") if err != nil { t.Fatal(err) } id := itoa(d.ID) if err := h.inbound.SetTransport(d.ID, "mx.internal", "2525", "encrypt"); err != nil { t.Fatal(err) } if err := h.inbound.SetRecipients(d.ID, "list", []string{"a@lists.example.com", "b@lists.example.com"}); err != nil { t.Fatal(err) } body := inboundCall(h, http.MethodGet, "/inbound/domains/"+id, nil, globalPrincipal).Body.String() has(t, "domain page", body, `
INBOUND_ANTISPAM_MILTER)`)
lacks(t, "filter off", body, `Applies to`)
has(t, "filter off, domain administrator", get(true), `set by the server's administrator`)
lacks(t, "filter off, domain administrator", get(true), `INBOUND_ANTISPAM_MILTER`)
s.h.cfg.InboundAntispamMilter, s.h.cfg.InboundAntispamAction = "inet:antispam:11332", "tempfail"
body = get(false)
has(t, "filter on", body, `Every inbound domain of this server`, `inet:antispam:11332`, `Mail is deferred until it answers`)
body = get(true)
has(t, "filter on, domain administrator", body, `Every inbound domain of this server`, `Mail is deferred until it answers`)
lacks(t, "filter on, domain administrator", body, `inet:antispam`, `/delete`)
s.h.cfg.InboundAntispamAction = "accept"
has(t, "filter on, accept", get(false), `Mail is accepted unfiltered`)
s.h.cfg.InboundAntispamAction = ""
lacks(t, "filter on, action unknown", get(false), `If the filter is down`)
// The list says the same in its head.
list := send(s.h.HandleInboundList, &s.global, http.MethodGet, "/inbound/domains", nil, nil).Body.String()
has(t, "list", list, `Spam filter on · 2 domains`)
s.h.cfg.InboundAntispamMilter = ""
list = send(s.h.HandleInboundList, &s.global, http.MethodGet, "/inbound/domains", nil, nil).Body.String()
has(t, "list", list, `Spam filter off · 2 domains`)
}