@@ -2,7 +2,7 @@ import fs from "node:fs/promises";
|
2 | 2 | import path from "node:path"; |
3 | 3 | import { describe, expect, it } from "vitest"; |
4 | 4 | import { resolveStateDir } from "../config/paths.js"; |
5 | | -import { assertLocalMediaAllowed } from "./local-media-access.js"; |
| 5 | +import { assertLocalMediaAllowed, LocalMediaAccessError } from "./local-media-access.js"; |
6 | 6 | |
7 | 7 | describe("assertLocalMediaAllowed", () => { |
8 | 8 | it("allows managed inbound media paths before explicit root checks", async () => { |
@@ -26,9 +26,21 @@ describe("assertLocalMediaAllowed", () => {
|
26 | 26 | await fs.writeFile(filePath, Buffer.from("png")); |
27 | 27 | |
28 | 28 | try { |
29 | | -await expect(assertLocalMediaAllowed(filePath, [])).rejects.toMatchObject({ |
30 | | -code: "path-not-allowed", |
31 | | -}); |
| 29 | +let accessError: unknown; |
| 30 | +try { |
| 31 | +await assertLocalMediaAllowed(filePath, []); |
| 32 | +} catch (error) { |
| 33 | +accessError = error; |
| 34 | +} |
| 35 | +expect(accessError).toBeInstanceOf(LocalMediaAccessError); |
| 36 | +if (!(accessError instanceof LocalMediaAccessError)) { |
| 37 | +throw new Error("expected LocalMediaAccessError"); |
| 38 | +} |
| 39 | +expect(accessError.name).toBe("LocalMediaAccessError"); |
| 40 | +expect(accessError.code).toBe("path-not-allowed"); |
| 41 | +expect(accessError.message).toBe( |
| 42 | +`Local media path is not under an allowed directory: ${filePath}`, |
| 43 | +); |
32 | 44 | } finally { |
33 | 45 | await fs.rm(path.dirname(filePath), { recursive: true, force: true }); |
34 | 46 | } |
|