mirror of
https://github.com/C4illin/ConvertX.git
synced 2026-09-13 02:14:32 +02:00
866510373b
Co-authored-by: Jennifer Wang <jennifer123wang@gmail.com> Co-authored-by: strawberry-raccoon <253751817+strawberry-raccoon@users.noreply.github.com>
35 lines
1010 B
TypeScript
35 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);
|
|
});
|
|
});
|