mirror of
https://github.com/C4illin/ConvertX.git
synced 2026-11-12 17:20:54 +01:00
34 lines
1010 B
TypeScript
34 lines
1010 B
TypeScript
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);
|
||
|
|
});
|
||
|
|
});
|