Behaviour SwRS-MDOKFSTUDIO-TRUST-005
The host handles the page messages of every preview, whatever the trust
When the host receives a page message from a preview, the extension SHALL handle it as for a trusted workspace, whether the preview belongs to a trusted workspace, to Restricted Mode or to a standalone file, and SHALL refuse a write request only for a reason that does not depend on trust (an older render, an open edit, a document that is not a saved file, a file VS Code holds read-only, a malformed request) or because it needs a read that Restricted Mode narrows (the citation list). A refusal names its real cause and changes nothing.
Step 2 of path 1 in StRS-MDOKFSTUDIO-TRUST-001: from “The document is editable” to “The edit is written to the document”.
Part of StRS-MDOKFSTUDIO-BLOCK-014, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-BLOCK-025, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-BLOCK-016, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-BLOCK-006, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-PALETTE-018, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-PALETTE-013, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-TOOLBAR-001, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-TOOLBAR-009, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-TOOLBAR-011, outside the paths drawn on its map.
Scenarios 6
The situations the tests check; open one to read it.
nominalEvery write request type is handled
| Request type | Outcome in a preview with restricted reads |
|---|---|
| previewEditOpen, previewEditSave, previewEditCancel | the block editor opens, saves and closes; the document is edited |
| previewFrontmatterSave | the frontmatter is saved in one document edit |
| previewCheckboxToggle | the checkbox or radio option is written to the source |
| previewBlockMove | the two blocks swap in one edit |
| previewBlocksCopy, previewBlocksCut, previewBlocksPaste, previewDropFiles | the blocks are copied, cut and pasted; dropped files are written as links, a Markdown file without a title read in a preview with restricted reads, and for a standalone document any file, linked relative to the document |
| previewLabelRename | the label line is renamed |
| previewThreadReply, previewThreadDelete | the thread comment is changed in the document |
| previewFindReplace | the matched spans are replaced in one undo step |
| previewCommentCreate, previewCommentReply, previewCommentResolve, previewCommentDelete | the comments file next to the document is read and written |
| previewPickDocument | the document dialog opens |
| previewPickImage | the image dialog opens; the picked image must lie in a workspace folder, or in the folder of the document for a standalone file ("The image must be inside the folder of the document.") |
| previewPasteImage | the image is saved next to the document; for a standalone file the folder of the document is the root, for a document in a workspace folder that folder is |
| previewPaletteModeChanged, previewEditModeChanged | the choice is stored for the workspace |
nominalViewing actions of a preview with restricted reads
A preview has restricted reads because the workspace is untrusted or the file is standalone. Each action below reaches its handler and has the outcome of the row.
| Action (page message) | Outcome in a preview with restricted reads |
|---|---|
| Theme button (previewThemeModeChanged) | the mode is stored for the workspace, no error is shown |
| Zoom in (zoom preference of previewViewPreferenceChanged) | the zoom is stored for the workspace and applied to the next page |
| Table of contents button (previewViewPreferenceChanged) | the host stores the toc preference |
| Back and Next (previewHistoryGo) | the previous or next document opens, for a file outside the workspace with a history of two places |
| Follow a link to a sibling Markdown file (previewLink) | the file opens |
| Ask about a visible relative link (previewLinkDiscover) | the host answers with the target or the reason |
| Copy code (previewCopyText) | the requested code text is on the clipboard and the document is unchanged |
| Label list (previewListTargets) | answered from the document text, as with full reads |
nominalThe dispatcher stops no request for trust
refusalThe citation list needs a trusted workspace folder
refusalReasons that do not depend on trust
| Input | Outcome |
|---|---|
| A write request that names an older render | Answered with the out-of-date reason, or dropped for a message of another document (see SwRS-MDOKFSTUDIO-TRUST-065) |
| A write while a Markdown edit is open on the host side | Refused with "Save or cancel the open Markdown edit ..." |
| A document that is not a saved file | Refused (for example "Save the document before pasting an image.") |
| A file that VS Code holds read-only (files.readonlyInclude, or made read-only in the session) | VS Code accepts the edit and writes nothing: every write above (the label rename, thread reply and delete, find and replace, block save, move, cut, paste and drop, checkbox toggle, metadata save) checks that the text changed and answers "This file is read-only in VS Code." instead of success (see SwRS-MDOKFSTUDIO-TRUST-001); a pasted image whose block save fails that way is deleted again |
| A malformed checkbox toggle or radio group | Answered with "The checkbox request was not understood. Refresh the preview." |
nominalHost-side writes follow the trust-free rule
| Input | Outcome |
|---|---|
| A preview with restricted reads switches document | A previewFlushEdit is posted, like for any preview |
| A document is saved and the only preview of it has restricted reads | The moved lines are written to the review comments file |
| previewThemeModeChanged or a zoom change with the old revision after a newer render | Dropped by the render gate, as for a preview with full reads |
Implemented in 8
Tested by 17
- test/host/fmtableReq.requirements.test.tsunit
- test/integration/blockClipboard.test.tsintegration
- test/integration/blockMove.test.tsintegration
- test/integration/commentWrite.test.tsintegration
- test/integration/imagePaste.test.tsintegration
- test/integration/standalone-suite.tsintegration
- test/integration/untrusted-suite.tsintegration
- test/session/blockReq.requirements.test.tsunit
- test/session/checkboxRefusal.test.tsunit
- test/session/diagReq.viewState.requirements.test.tsunit
- test/session/dropFiles.requirements.test.tsunit
- test/session/paletteReq.requirements.test.tsunit
- test/session/renderReq.codeCopy.requirements.test.tsunit
- test/session/renderReq.labelRename.requirements.test.tsunit
- test/session/reviewReqComments.requirements.test.tsunit
- test/session/reviewReqThreads.requirements.test.tsunit
- test/session/toolbarReq.requirements.test.tsunit