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, `

Inbound domains

`, `

Add a domain

`, `action="/inbound/domains"`, `name="name"`, `2 domains`, `TLS to upstream`, `href="/inbound/domains/1">lists.example.org`, `MX`, `>mx.internal:25<`, `4 addresses`, `any address`, `>10.0.4.12:2525<`, `required`, `opportunistic`, `>Delete`, `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, `01

Domains

`, `1 domain`, `1 address<`) pageLacks(t, "Inbound domains", out, `Add a domain`, `name="name"`, `>Delete`, `/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, `MX`, `MX`, `MX`, `>—<`, `0 addresses`, `off`, `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`, `
`, `That inbound domain is already configured.`, `value="lists.example.org"`, `0 domains`) pageLacks(t, "Inbound domains", out, ``, `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: ``, Host: `">`, Port: 25}, true), }).WithResult("", "bad", `">`) out := renderSignedIn(t, "in-domains", p) pageLacks(t, "Inbound domains", out, `