Skip to content

Build your personal knowledge base with Trilium Notes

test(server/share): protected notes

Elian Doran1ad8b1bf853a
diff --git a/apps/server/src/share/content_renderer.spec.ts b/apps/server/src/share/content_renderer.spec.ts
index 04f60bd715..363b743907 100644
--- a/apps/server/src/share/content_renderer.spec.ts
+++ b/apps/server/src/share/content_renderer.spec.ts
@@ -4,7 +4,13 @@ import { trimIndentation } from "@triliumnext/commons";
import { buildShareNote } from "../test/shaca_mocking.js";
describe("content_renderer", () => {
- describe("renderText", () => {
+ it("Reports protected notes not being renderable", () => {
+ const note = buildShareNote({ isProtected: true });
+ const result = getContent(note);
+ expect(result.content).toStrictEqual("<p>Protected note cannot be displayed</p>");
+ });
+
+ describe("Text note", () => {
it("parses simple note", () => {
const content = trimIndentation`\
<figure class="image image-style-align-right image_resized" style="width:29.84%;">
diff --git a/apps/server/src/test/shaca_mocking.ts b/apps/server/src/test/shaca_mocking.ts
index e92411500e..022ee999ad 100644
--- a/apps/server/src/test/shaca_mocking.ts
+++ b/apps/server/src/test/shaca_mocking.ts
@@ -8,8 +8,9 @@ type RelationDefinitions = { [key in `~${string}`]: string; };
interface NoteDefinition extends AttributeDefinitions, RelationDefinitions {
id?: string | undefined;
- title: string;
+ title?: string;
content?: string | Buffer<ArrayBufferLike>;
+ isProtected?: boolean;
}
/**
@@ -41,18 +42,21 @@ export function buildShareNote(noteDef: NoteDefinition) {
const blobId = "foo";
const note = new SNote([
noteDef.id ?? utils.randomString(12),
- noteDef.title,
+ noteDef.title ?? "New note",
"text",
"text/html",
blobId,
new Date().toUTCString(), // utcDateModified
- false // is protected
+ !!noteDef.isProtected
]);
shaca.notes[note.noteId] = note;
// Handle content
if (noteDef.content) {
- note.getContent = () => noteDef.content;
+ note.getContent = () => {
+ if (noteDef.isProtected) return undefined;
+ return noteDef.content;
+ };
}
// Handle labels & relations