test: FormatHTML keep and refuse coverage, admin re-save keeps HTML
- TestFormatHTMLKeepsRawHTML: imported-style bodies (paragraphs, attributes, https links and images, entities) round-trip; markdown keeps a trailing raw footer and style - TestFormatHTMLRejectsUnsafeHTML: every unsafe case must return an error now that the gate is the only defence; adds svg onload, mixed-case schemes and tags, object, embed, script in an HTML block and raw data URLs - TestPostsAdminResaveKeepsHTML: an admin update of HTML content keeps content_html
This commit is contained in:
@@ -103,3 +103,51 @@ func TestPostsAdminCreateSmoke(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestPostsAdminResaveKeepsHTML is the acceptance test of the todo
|
||||
// journal-imported-html-admin-resave (D-03): an admin save of a post whose
|
||||
// content is HTML, as imported posts are, keeps that HTML in content_html
|
||||
// instead of goldmark's raw-HTML placeholder.
|
||||
func TestPostsAdminResaveKeepsHTML(t *testing.T) {
|
||||
env := newPostsEnv(t)
|
||||
token := env.admin(t,
|
||||
controllers.PermissionAccessPosts,
|
||||
controllers.PermissionAccessPublish,
|
||||
controllers.PermissionAccessOtherPosts,
|
||||
)
|
||||
const content = "<p>Grzyby rosną w lesie.</p>\n<p>Druga <b>część</b> z <a href=\"https://example.test/zrodlo\">linkiem</a>.</p>"
|
||||
body := map[string]any{
|
||||
"title": map[string]any{"en": "Imported", "pl": "Zaimportowany"},
|
||||
"slug": map[string]any{"en": "imported-html", "pl": "zaimportowany-html"},
|
||||
"content": map[string]any{"en": content, "pl": content},
|
||||
"excerpt": map[string]any{"en": "Excerpt", "pl": "Wyjątek"},
|
||||
}
|
||||
rec := env.expect(t, http.StatusCreated, http.MethodPost, adminAPI(adminPostsPath), token, body)
|
||||
var created struct {
|
||||
ID uint `json:"id"`
|
||||
}
|
||||
if err := json.Unmarshal(adminDecode(t, rec).Data, &created); err != nil || created.ID == 0 {
|
||||
t.Fatalf("create data %s: %v", rec.Body.String(), err)
|
||||
}
|
||||
|
||||
assertHTML := func(stage string) {
|
||||
t.Helper()
|
||||
var stored models.Post
|
||||
if err := env.gdb.First(&stored, created.ID).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(stored.ContentHTML, "raw HTML omitted") {
|
||||
t.Fatalf("%s: content_html holds the goldmark placeholder: %q", stage, stored.ContentHTML)
|
||||
}
|
||||
if strings.TrimSpace(stored.ContentHTML) != content {
|
||||
t.Fatalf("%s: content_html = %q, want %q", stage, strings.TrimSpace(stored.ContentHTML), content)
|
||||
}
|
||||
if stored.Content != content {
|
||||
t.Fatalf("%s: content = %q, want %q", stage, stored.Content, content)
|
||||
}
|
||||
}
|
||||
assertHTML("create")
|
||||
|
||||
env.expect(t, http.StatusOK, http.MethodPut, adminAPI(fmt.Sprintf("%s/%d", adminPostsPath, created.ID)), token, body)
|
||||
assertHTML("re-save")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user