test: add vitest unit coverage

This commit is contained in:
Federico Jaramillo Martinez
2026-05-07 23:50:25 +02:00
parent 0338ba532b
commit a77012ba83
8 changed files with 435 additions and 7 deletions
+16
View File
@@ -0,0 +1,16 @@
import { describe, expect, it } from "vitest";
import { normalizeRelativePath } from "./pathSafety.js";
describe("normalizeRelativePath", () => {
it("normalizes separators and dot segments", () => {
expect(normalizeRelativePath("./src//client\\main.ts")).toBe("src/client/main.ts");
});
it("rejects absolute paths", () => {
expect(() => normalizeRelativePath("/etc/passwd")).toThrow("Absolute paths are not allowed");
});
it("rejects traversal", () => {
expect(() => normalizeRelativePath("src/../secret")).toThrow("Path traversal is not allowed");
});
});