fix(browser): revalidate upload paths at use time

This commit is contained in:
Peter Steinberger
2026-02-26 00:40:43 +01:00
parent 15cfba7075
commit ef326f5cd0
8 changed files with 263 additions and 25 deletions

View File

@@ -6,6 +6,7 @@ import {
resolveExistingPathsWithinRoot,
resolvePathsWithinRoot,
resolvePathWithinRoot,
resolveStrictExistingPathsWithinRoot,
} from "./paths.js";
async function createFixtureRoot(): Promise<{ baseDir: string; uploadsDir: string }> {
@@ -194,6 +195,29 @@ describe("resolveExistingPathsWithinRoot", () => {
);
});
describe("resolveStrictExistingPathsWithinRoot", () => {
function expectInvalidResult(
result: Awaited<ReturnType<typeof resolveStrictExistingPathsWithinRoot>>,
expectedSnippet: string,
) {
expect(result.ok).toBe(false);
if (!result.ok) {
expect(result.error).toContain(expectedSnippet);
}
}
it("rejects missing files instead of returning lexical fallbacks", async () => {
await withFixtureRoot(async ({ uploadsDir }) => {
const result = await resolveStrictExistingPathsWithinRoot({
rootDir: uploadsDir,
requestedPaths: ["missing.txt"],
scopeLabel: "uploads directory",
});
expectInvalidResult(result, "regular non-symlink file");
});
});
});
describe("resolvePathWithinRoot", () => {
it("uses default file name when requested path is blank", () => {
const result = resolvePathWithinRoot({