mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-08-28 08:35:57 +00:00
feat: vendor permission system source
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user