mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
fix(share): double request of credentials
This commit is contained in:
parent
7ea3cb71f3
commit
6f9fd76465
@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user