Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(share): double request of credentials
Elian Doran6f9fd7646556
diff --git a/src/share/routes.spec.ts b/src/share/routes.spec.tsindex f4cc3fc981..86e1927bdd 100644--- a/src/share/routes.spec.ts+++ b/src/share/routes.spec.ts@@ -1,20 +1,34 @@-import { beforeAll, describe, it } from "vitest";+import { beforeAll, beforeEach, describe, expect, it } from "vitest";import supertest from "supertest";-import type { App } from "supertest/types.js";import { initializeTranslations } from "../services/i18n.js";+import type { Application, Request, Response, NextFunction } from "express";-let app: App;+let app: Application;describe("Share API test", () => {+ let cannotSetHeadersCount = 0;+beforeAll(async () => {initializeTranslations();app = (await import("../app.js")).default;+ app.use((err: any, req: Request, res: Response, next: NextFunction) => {+ if (err.message.includes("Cannot set headers after they are sent to the client")) {+ cannotSetHeadersCount++;+ }++ next();+ });+ });++ beforeEach(() => {+ cannotSetHeadersCount = 0;});it("requests password for password-protected share", async () => {await supertest(app).get("/share/YjlPRj2E9fOV").expect("WWW-Authenticate", 'Basic realm="User Visible Realm", charset="UTF-8"');+ expect(cannotSetHeadersCount).toBe(0);});});diff --git a/src/share/routes.ts b/src/share/routes.tsindex 3b62588722..3c6db87d54 100644--- a/src/share/routes.ts+++ b/src/share/routes.ts@@ -87,7 +87,6 @@ function checkNoteAccess(noteId: string, req: Request, res: Response) {const header = req.header("Authorization");if (!header?.startsWith("Basic ")) {- requestCredentials(res);return false;}