mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-09-25 15:25:44 +00:00
77 lines
2.4 KiB
TypeScript
77 lines
2.4 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
describe("local media path policy", () => {
|
|
let tempRoot: string;
|
|
let appDataPath: string;
|
|
let userDataPath: string;
|
|
let tempPath: string;
|
|
let appPath: string;
|
|
|
|
beforeEach(async () => {
|
|
tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "recordly-media-policy-"));
|
|
appDataPath = path.join(tempRoot, "AppData");
|
|
userDataPath = path.join(tempRoot, "UserData");
|
|
tempPath = path.join(tempRoot, "Temp");
|
|
appPath = path.join(tempRoot, "App");
|
|
|
|
await Promise.all(
|
|
[appDataPath, userDataPath, tempPath, appPath].map((dirPath) =>
|
|
fs.mkdir(dirPath, { recursive: true }),
|
|
),
|
|
);
|
|
|
|
vi.resetModules();
|
|
vi.doMock("electron", () => ({
|
|
app: {
|
|
isPackaged: false,
|
|
getAppPath: () => appPath,
|
|
getPath: (name: string) => {
|
|
if (name === "appData") return appDataPath;
|
|
if (name === "userData") return userDataPath;
|
|
if (name === "temp") return tempPath;
|
|
return tempRoot;
|
|
},
|
|
setPath: () => undefined,
|
|
},
|
|
}));
|
|
});
|
|
|
|
afterEach(async () => {
|
|
vi.resetModules();
|
|
vi.doUnmock("electron");
|
|
if (tempRoot) {
|
|
await fs.rm(tempRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it("allows existing exported media files outside the session directories", async () => {
|
|
const downloadsPath = path.join(tempRoot, "Downloads");
|
|
const exportPath = path.join(downloadsPath, "export-test.mp4");
|
|
await fs.mkdir(downloadsPath, { recursive: true });
|
|
await fs.writeFile(exportPath, "test-video");
|
|
|
|
const { isAllowedLocalMediaPath } = await import("./manager");
|
|
|
|
await expect(isAllowedLocalMediaPath(exportPath)).resolves.toBe(true);
|
|
});
|
|
|
|
it("rejects missing media files outside the allowed directories", async () => {
|
|
const missingPath = path.join(tempRoot, "Downloads", "missing.mp4");
|
|
const { isAllowedLocalMediaPath } = await import("./manager");
|
|
|
|
await expect(isAllowedLocalMediaPath(missingPath)).resolves.toBe(false);
|
|
});
|
|
|
|
it("allows approved media paths before the file exists", async () => {
|
|
const pendingExportPath = path.join(tempRoot, "Downloads", "pending-export.mp4");
|
|
const { isAllowedLocalMediaPath, rememberApprovedLocalReadPath } = await import("./manager");
|
|
|
|
await rememberApprovedLocalReadPath(pendingExportPath);
|
|
|
|
await expect(isAllowedLocalMediaPath(pendingExportPath)).resolves.toBe(true);
|
|
});
|
|
});
|