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
test(server): cover HttpError status and non-string TOTP token (#11919)
Claude7ec7b52481fb
diff --git a/apps/server/src/routes/login.spec.ts b/apps/server/src/routes/login.spec.tsindex 391d4489c0..fe7e9386d7 100644--- a/apps/server/src/routes/login.spec.ts+++ b/apps/server/src/routes/login.spec.ts@@ -7,6 +7,7 @@ import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";import { cls, options } from "@triliumnext/core";import { refreshAuth } from "../services/auth.js";import config from "../services/config.js";+import totp from "../services/totp.js";import { createLoginRateLimiter } from "./login.js";import { type SQLiteSessionStore } from "./session_parser.js";@@ -80,6 +81,23 @@ describe("Login Route test", () => {}});+ it("rejects a TOTP token that is not a string without verifying it", async () => {+ vi.spyOn(totp, "isTotpEnabled").mockReturnValue(true);+ const verifyTOTP = vi.spyOn(totp, "verifyTOTP");++ try {+ const res = await supertest(app)+ .post("/login")+ .send({ password: "demo1234", totpToken: ["123456"] })+ .expect(401);++ expect(res.body).toEqual({ success: false, factor: "totp" });+ expect(verifyTOTP).not.toHaveBeenCalled();+ } finally {+ vi.restoreAllMocks();+ }+ });+describe("login stays reachable with redirectBareDomain enabled (#10552)", () => {// The fixture DB contains a #shareRoot note (y0AFOwgOgkWO), so enabling// redirectBareDomain arms the bare-domain → share redirect in checkAuth.diff --git a/apps/server/src/routes/route_api.spec.ts b/apps/server/src/routes/route_api.spec.tsindex 595b53e246..11716afc68 100644--- a/apps/server/src/routes/route_api.spec.ts+++ b/apps/server/src/routes/route_api.spec.ts@@ -1,4 +1,4 @@-import { cls } from "@triliumnext/core";+import { cls, NotFoundError } from "@triliumnext/core";import express from "express";import { existsSync } from "fs";import request from "supertest";@@ -239,6 +239,10 @@ describe("internalRoute without a result handler", () => {throw new Error("boom");}, null);+ asyncRoute("get", "/no-handler/reject-http", [], async () => {+ throw new NotFoundError("missing");+ }, null);+app = express();app.use(router);});@@ -248,4 +252,10 @@ describe("internalRoute without a result handler", () => {expect(res.body).toEqual({ message: "boom" });});++ it("keeps the status of a rejected HttpError", async () => {+ const res = await request(app).get("/no-handler/reject-http").timeout(2000).expect(404);++ expect(res.body).toEqual({ message: "missing" });+ });});