package docs_test import ( "net/http" "strings" "testing" "github.com/carlosframework/docs/internal/docs" ) // A reader grantee must not be handed an editor. Found by the branch // review, and the worst defect on this branch: `show` used GetFor // (correct — a reader may read) and then rendered the owner's page // verbatim, so ProseMirror mounted, the toolbar enabled, and the document // became contenteditable for somebody the server will refuse. // // The server refusal was never in doubt: ApplyUpdate returns ErrNotWritable // and updatesPost answers 404. The damage is upstream of that. The browser // has already taken the keystrokes; the save queue classifies the 404 as // permanent, drops the batch, and keeps accepting typing. The person is // told "save failed" after writing a paragraph into a page that told them // they could. // // "It fails safely on the server" is not a defence when the cost is a // person's work. func TestAReaderIsNotGivenAnEditor(t *testing.T) { app, _ := docs.NewForTest(t) alice := signInCookies(t, app, "alice@example.com") sqid := createDoc(t, app, alice, "Minutes") bob := signInCookies(t, app, "bob@example.com") post(t, app, alice, "/d/"+sqid+"/share", "address=bob@example.com&role=reader") rec := get(t, app, bob, "/d/"+sqid) if rec.Code != http.StatusOK { t.Fatalf("GET /d/%s as a reader: status %d, want 200", sqid, rec.Code) } body := rec.Body.String() // The mount ELEMENT, not the string: `[docs-editor]` also appears a // dozen times in this page's own