test: cover external output traversal rejection
This commit is contained in:
parent
f4a7bb1a65
commit
cfda97c828
@ -81,6 +81,24 @@ describe("writeExternalFileWithinRoot", () => {
|
||||
await expect(fs.stat(outsidePath)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
|
||||
it("rejects traversal targets before invoking the external writer", async () => {
|
||||
const rootDir = await tempRoot("fs-safe-output-traversal-root-");
|
||||
let called = false;
|
||||
|
||||
await expect(
|
||||
writeExternalFileWithinRoot({
|
||||
rootDir,
|
||||
path: "../../../pwned.txt",
|
||||
write: async (candidate) => {
|
||||
called = true;
|
||||
await fs.writeFile(candidate, "pwned", "utf8");
|
||||
},
|
||||
}),
|
||||
).rejects.toMatchObject({ code: "outside-workspace" });
|
||||
|
||||
expect(called).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects root directory targets before invoking the external writer", async () => {
|
||||
const rootDir = await tempRoot("fs-safe-output-root-target-");
|
||||
let called = false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user