Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
87 lines
3.3 KiB
Go
87 lines
3.3 KiB
Go
package server
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPlainTextEditorCanonicalAndExistingHTML(t *testing.T) {
|
|
s, token, domain, htmlObject := editorFixture(t)
|
|
page := configRequest(s, token, "GET", "/e/-/notes.txt?edittype=plain", nil)
|
|
if page.Code != 200 || !strings.Contains(page.Body.String(), `value="plain"`) || !strings.Contains(page.Body.String(), `value="text/plain; charset=utf-8"`) {
|
|
t.Fatalf("plain editor: %d %s", page.Code, page.Body.String())
|
|
}
|
|
object, err := s.store.ResolvePathInDomain(domain, "/notes.txt")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body := "<script>alert('literal')</script>\n# Not Markdown\n{{children}}\n日本語 & <>\n"
|
|
payload, _ := json.Marshal(map[string]any{"object_uuid": object, "body": body, "lang": "und", "content_type": "text/plain; charset=utf-8", "filename": "notes.txt", "base_revision_uuid": ""})
|
|
r := httptest.NewRequest("POST", "http://localhost/_/api/v1/revisions/save", bytes.NewReader(payload))
|
|
r.Header.Set("Authorization", "Bearer "+token)
|
|
r.Header.Set("Content-Type", "application/json")
|
|
w := httptest.NewRecorder()
|
|
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
|
if w.Code != 200 {
|
|
t.Fatalf("plain save: %d %s", w.Code, w.Body.String())
|
|
}
|
|
rev, err := s.store.GetRevisionForExactLanguage(object, "und")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if rev.Body != body || rev.ContentType != "text/plain; charset=utf-8" {
|
|
t.Fatalf("plain content mutated: %#v", rev)
|
|
}
|
|
if view := revisionContentView(rev, "/notes.txt"); view.Kind != "code" {
|
|
t.Fatalf("plain rendered as %s", view.Kind)
|
|
}
|
|
page = configRequest(s, token, "GET", "/e/-/notes.txt?edittype=markdown", nil)
|
|
if page.Code != 200 || !strings.Contains(page.Body.String(), `value="plain"`) || strings.Contains(page.Body.String(), `data-editor-action="markdown"`) {
|
|
t.Fatal("reopen switched plain file to HTML")
|
|
}
|
|
before, _ := s.store.GetRevisionForExactLanguage(htmlObject, "und")
|
|
page = configRequest(s, token, "GET", "/e/-/editor-fixture?edittype=plain", nil)
|
|
if page.Code != http.StatusConflict {
|
|
t.Fatalf("existing HTML converted: %d", page.Code)
|
|
}
|
|
after, _ := s.store.GetRevisionForExactLanguage(htmlObject, "und")
|
|
if before.UUID != after.UUID {
|
|
t.Fatal("existing HTML changed")
|
|
}
|
|
page = configRequest(s, token, "GET", "/e/-/invalid-format?edittype=not-a-format", nil)
|
|
if page.Code != http.StatusBadRequest {
|
|
t.Fatal("invalid editor format accepted")
|
|
}
|
|
if _, err = s.store.ResolvePathInDomain(domain, "/invalid-format"); err == nil {
|
|
t.Fatal("invalid format created a Page")
|
|
}
|
|
}
|
|
|
|
func TestBrowserEditorCreationRequiresPermission(t *testing.T) {
|
|
s, _, domain, _ := editorFixture(t)
|
|
user, err := s.store.CreatePasswordAccount(domain, "reader", "a long test password", "Reader", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.store.SetPrincipalState(domain, user.UUID, "readonly"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
token, err := s.store.CreateAuthSession(domain, user.UUID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, format := range []string{"html", "plain"} {
|
|
response := configRequest(s, token, "GET", "/e/-/denied?edittype="+format, nil)
|
|
if response.Code != http.StatusForbidden {
|
|
t.Fatalf("read-only create: %d", response.Code)
|
|
}
|
|
if _, err := s.store.ResolvePathInDomain(domain, "/denied"); err == nil {
|
|
t.Fatal("denied editor created a Page")
|
|
}
|
|
}
|
|
}
|