fix(share): double request of credentials

This commit is contained in:
Elian Doran 2025-02-26 20:33:18 +02:00
parent 7ea3cb71f3
commit 6f9fd76465
No known key found for this signature in database
2 changed files with 17 additions and 4 deletions

View File

@ -1,20 +1,34 @@
import { beforeAll, describe, it } from "vitest"; import { beforeAll, beforeEach, describe, expect, it } from "vitest";
import supertest from "supertest"; import supertest from "supertest";
import type { App } from "supertest/types.js";
import { initializeTranslations } from "../services/i18n.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", () => { describe("Share API test", () => {
let cannotSetHeadersCount = 0;
beforeAll(async () => { beforeAll(async () => {
initializeTranslations(); initializeTranslations();
app = (await import("../app.js")).default; 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 () => { it("requests password for password-protected share", async () => {
await supertest(app) await supertest(app)
.get("/share/YjlPRj2E9fOV") .get("/share/YjlPRj2E9fOV")
.expect("WWW-Authenticate", 'Basic realm="User Visible Realm", charset="UTF-8"'); .expect("WWW-Authenticate", 'Basic realm="User Visible Realm", charset="UTF-8"');
expect(cannotSetHeadersCount).toBe(0);
}); });
}); });

View File

@ -87,7 +87,6 @@ function checkNoteAccess(noteId: string, req: Request, res: Response) {
const header = req.header("Authorization"); const header = req.header("Authorization");
if (!header?.startsWith("Basic ")) { if (!header?.startsWith("Basic ")) {
requestCredentials(res);
return false; return false;
} }