", 129), strings.Repeat("{{children}}", 33)} {
got = s.safeHTMLProjection(r, body, "/guide", true)
if !strings.Contains(got, "projection-warning") {
t.Fatal("limit did not fail closed")
}
checkInertProjection(t, got)
}
ctx, cancel := context.WithCancel(r.Context())
cancel()
if got = s.safeHTMLProjection(r.WithContext(ctx), projectionAttack, "/guide", true); !strings.Contains(got, "projection-warning") {
t.Fatal("cancellation ignored")
}
}
func TestHTMLProjectionFailedMacroRemainsText(t *testing.T) {
s, _, _ := configFixture(t)
// Force a locality lookup failure in this temporary fixture. Decoded text
// must not acquire the final policy's application-owned macro attributes.
if _, err := s.store.DB.Exec(`ALTER TABLE zones RENAME TO unavailable_zones`); err != nil {
t.Fatal(err)
}
r := httptest.NewRequest("GET", "http://localhost/guide", nil)
for _, tail := range []string{"", "{{children:/guide}}"} {
body := `
{{spot ignored="<section class='children-async' data-children-src='/sentinel'>fake</section>` + tail + `"}}
`
got := s.safeHTMLProjection(r, body, "/guide", true)
if strings.Contains(got, "
document.documentElement.dataset.attack`) || strings.Contains(w.Body.String(), `onerror="document.documentElement.dataset.attack`) {
t.Fatalf("unsafe source in %s", route)
}
for _, m := range regexp.MustCompile(``), "", "en", "text/plain", "code.txt"); err != nil {
t.Fatal(err)
}
w := configRequest(s, token, "GET", "/o/uuid:"+object, nil)
if w.Code != 200 || strings.Contains(w.Body.String(), ``
}