Files
ConvertX/tests/validatePath.test.ts
T

34 lines
1010 B
TypeScript
Raw Normal View History

import { expect, test, describe } from "bun:test";
import { isSafePath } from "../src/helpers/validatePath";
describe("isSafePath", () => {
test("should allow no slash", () => {
const path = "cat.jpg";
const result = isSafePath("./job/", `./job/${path}`);
expect(result).toEqual(true);
});
test("should allow safe slash", () => {
const path = "dir/cat.jpg";
const result = isSafePath("./job/", `./job/${path}`);
expect(result).toEqual(true);
});
test("should allow leading slash", () => {
const path = "/dir/cat.jpg";
const result = isSafePath("./job/", `./job/${path}`);
expect(result).toEqual(true);
});
test("should allow leading dots", () => {
const path = "dir/..cat.jpg";
const result = isSafePath("./job/", `./job/${path}`);
expect(result).toEqual(true);
});
test("should disallow parent", () => {
const path = "../cat.jpg";
const result = isSafePath("./job/", `./job/${path}`);
expect(result).toEqual(false);
});
});