Skip to content

Build your personal knowledge base with Trilium Notes

test(server): increase coverage for routes

Elian Doran303d70d0296c
diff --git a/apps/server/src/share/routes.spec.ts b/apps/server/src/share/routes.spec.ts
index 6a37fb4d53..c982a383ec 100644
--- a/apps/server/src/share/routes.spec.ts
+++ b/apps/server/src/share/routes.spec.ts
@@ -125,6 +125,14 @@ describe("Share API test", () => {
expect(cannotSetHeadersCount).toBe(0);
});
+ it("rejects search results whose note path bypasses the share ancestor (clones)", async () => {
+ // A note cloned both under the share tree and elsewhere can surface with a
+ // best note path that never passes through the requested ancestor — such a
+ // result must be treated as not visible.
+ const { isVisibleInShareTree } = await import("./routes.js");
+ expect(isVisibleInShareTree(SHARE_ROOT_ID, ["root", "someUnsharedNote"])).toBe(false);
+ });
+
it("renders custom share template", async () => {
// Custom EJS templates require scripting to be enabled
const originalEnabled = config.Security.backendScriptingEnabled;
diff --git a/apps/server/src/share/routes.ts b/apps/server/src/share/routes.ts
index b4d38f5440..350a4c703f 100644
--- a/apps/server/src/share/routes.ts
+++ b/apps/server/src/share/routes.ts
@@ -103,8 +103,10 @@ function hasCredentialAccess(note: SNote, req: Request) {
// the public share tree below `ancestorNoteId`: every hop from the ancestor down
// to the note must be a non-hidden branch whose child note is not
// `shareHiddenFromTree`. Mirrors SNote.getVisibleChildBranches() so that search
-// cannot enumerate notes the navigation tree deliberately hides.
-function isVisibleInShareTree(ancestorNoteId: string, notePathArray: string[]) {
+// cannot enumerate notes the navigation tree deliberately hides. Exported for
+// tests: a clone's best note path can bypass the share subtree entirely, which
+// is impractical to stage through the full search stack.
+export function isVisibleInShareTree(ancestorNoteId: string, notePathArray: string[]) {
const startIndex = notePathArray.indexOf(ancestorNoteId);
if (startIndex < 0) {