test(postcard): decoded URL scheme check, unsafe inlined output and the literal footer
- TestURLSchemeCheck: prose and scheme words in titles or queries pass; every URL-bearing attribute, CSS, meta refresh and each entity-encoded or whitespace-split script URL is refused with a snippet at the markup; a layout override with javascript: falls back to the file version with inlining on and off; the editor refuses it on content_html and CSS URLs on content_css - TestInlineUnsafeOutput: a failing inlined result sends the style-block version with one warning per layout - TestFooterSiteNameLiteral: the footer prints the site name escaped and literally on the default and system layouts; body stays Markdown - check-phase35.sh GO_TESTS requires the three tests
This commit is contained in:
@@ -279,3 +279,68 @@ func TestUnsafeText(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestFooterSiteNameLiteral covers the literal footer (WR-01): the built-in
|
||||
// layouts print the site name as text, escaped, in the footer as in the
|
||||
// header, so Markdown or markup in a name is never rendered; the footer
|
||||
// partial's body argument is still Markdown.
|
||||
func TestFooterSiteNameLiteral(t *testing.T) {
|
||||
t.Parallel()
|
||||
names := []struct{ name, escaped string }{
|
||||
{"*Acme*", "*Acme*"},
|
||||
{"Acme <Studio>", "Acme <Studio>"},
|
||||
{"[x](https://example.com)", "[x](https://example.com)"},
|
||||
}
|
||||
for _, l := range siteNameLayouts {
|
||||
for _, n := range names {
|
||||
t.Run(l.layout+"/"+n.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m, drv := siteNameMailer(t, Options{}, &Overrides{Brand: &Brand{SiteName: n.name}})
|
||||
logs := captureLog(m)
|
||||
msg := sendTemplate(t, m, drv, l.template, inlineVars)
|
||||
if got, want := footerText(t, msg.HTML), copyright()+" "+n.escaped; got != want {
|
||||
t.Errorf("footer = %q, want %q", got, want)
|
||||
}
|
||||
footer := footerTable(t, msg.HTML)
|
||||
for _, bad := range []string{"<em", "<strong", "<a ", "<a>", "raw HTML omitted", "<!--", "<Studio"} {
|
||||
if strings.Contains(footer, bad) {
|
||||
t.Errorf("the footer holds %q:\n%s", bad, footer)
|
||||
}
|
||||
}
|
||||
cell, ok := headerCell(msg.HTML)
|
||||
if m := logoSpan.FindStringSubmatch(cell); !ok || m == nil || m[1] != n.escaped {
|
||||
t.Errorf("header = %q, want %q", cell, n.escaped)
|
||||
}
|
||||
if !strings.Contains(msg.Text, "\n"+copyright()+" "+n.name+"\n") && !strings.HasSuffix(msg.Text, "\n"+copyright()+" "+n.name) {
|
||||
t.Errorf("the text part's footer line is not %q:\n%s", copyright()+" "+n.name, msg.Text)
|
||||
}
|
||||
if siteNameWarnings(logs.String()) != 0 {
|
||||
t.Errorf("a safe name was warned about:\n%s", logs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Called from a template: body is Markdown, text is printed as it is.
|
||||
cases := []struct {
|
||||
name, call, want, bad string
|
||||
}{
|
||||
{"body_markdown", `{{ partial "footer" "body" "*b*" }}`, "<em>b</em>", "*b*"},
|
||||
{"text_literal", `{{ partial "footer" "text" "*b*" }}`, "<p>*b*</p>", "<em>"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run("partial/"+tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m, drv := siteNameMailer(t, Options{}, &Overrides{Template: &TemplateOverride{Subject: "S", Body: tc.call}})
|
||||
msg := sendTemplate(t, m, drv, "acme.site::mail.hello", inlineVars)
|
||||
tables := withClass(msg.HTML, "table", "footer")
|
||||
if len(tables) != 2 {
|
||||
t.Fatalf("%d footer tables, want the body's and the layout's:\n%s", len(tables), msg.HTML)
|
||||
}
|
||||
body, _, _ := strings.Cut(msg.HTML[tables[0].start:], "</table>")
|
||||
if !strings.Contains(body, tc.want) || strings.Contains(body, tc.bad) {
|
||||
t.Errorf("footer partial %s = %q, want %q and no %q", tc.call, body, tc.want, tc.bad)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user