feat: vendor permission system source

This commit is contained in:
云服务部-叶林立
2026-08-19 14:35:19 +08:00
parent 198584daf8
commit 410c50a3e5
809 changed files with 157793 additions and 139 deletions
@@ -0,0 +1,46 @@
import { describe, expect, test } from "vitest";
import { isSafeSystemPath, SAFE_SYSTEM_PATHS } from "#src/safe-system-paths";
describe("SAFE_SYSTEM_PATHS", () => {
test("contains /dev/null, /dev/stdin, /dev/stdout, /dev/stderr", () => {
expect(SAFE_SYSTEM_PATHS.has("/dev/null")).toBe(true);
expect(SAFE_SYSTEM_PATHS.has("/dev/stdin")).toBe(true);
expect(SAFE_SYSTEM_PATHS.has("/dev/stdout")).toBe(true);
expect(SAFE_SYSTEM_PATHS.has("/dev/stderr")).toBe(true);
});
});
describe("isSafeSystemPath", () => {
test("returns true for /dev/null", () => {
expect(isSafeSystemPath("/dev/null")).toBe(true);
});
test("returns true for /dev/stdin", () => {
expect(isSafeSystemPath("/dev/stdin")).toBe(true);
});
test("returns true for /dev/stdout", () => {
expect(isSafeSystemPath("/dev/stdout")).toBe(true);
});
test("returns true for /dev/stderr", () => {
expect(isSafeSystemPath("/dev/stderr")).toBe(true);
});
test("returns false for an arbitrary absolute path", () => {
expect(isSafeSystemPath("/etc/passwd")).toBe(false);
});
test("returns false for a path prefixed with a safe system path", () => {
expect(isSafeSystemPath("/dev/null/subdir")).toBe(false);
});
test("returns false for an empty string", () => {
expect(isSafeSystemPath("")).toBe(false);
});
test("returns false for a relative path", () => {
expect(isSafeSystemPath("dev/null")).toBe(false);
});
});