mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 01:04:32 +00:00
fix(test): use NTFS junctions and platform guards for symlink tests on Windows (openclaw#28747) thanks @arosstale
Verified: - pnpm install --frozen-lockfile - pnpm test src/agents/apply-patch.test.ts src/agents/sandbox/fs-bridge.test.ts src/agents/sandbox/validate-sandbox-security.test.ts src/infra/archive.test.ts Co-authored-by: arosstale <117890364+arosstale@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -148,6 +148,10 @@ describe("applyPatch", () => {
|
||||
});
|
||||
|
||||
it("rejects symlink escape attempts by default", async () => {
|
||||
// File symlinks require SeCreateSymbolicLinkPrivilege on Windows.
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
}
|
||||
await withTempDir(async (dir) => {
|
||||
const outside = path.join(path.dirname(dir), "outside-target.txt");
|
||||
const linkPath = path.join(dir, "link.txt");
|
||||
@@ -232,6 +236,10 @@ describe("applyPatch", () => {
|
||||
});
|
||||
|
||||
it("allows symlinks that resolve within cwd by default", async () => {
|
||||
// File symlinks require SeCreateSymbolicLinkPrivilege on Windows.
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
}
|
||||
await withTempDir(async (dir) => {
|
||||
const target = path.join(dir, "target.txt");
|
||||
const linkPath = path.join(dir, "link.txt");
|
||||
@@ -259,7 +267,9 @@ describe("applyPatch", () => {
|
||||
await fs.writeFile(outsideFile, "victim\n", "utf8");
|
||||
|
||||
const linkDir = path.join(dir, "linkdir");
|
||||
await fs.symlink(outsideDir, linkDir);
|
||||
// Use 'junction' on Windows — junctions target directories without
|
||||
// requiring SeCreateSymbolicLinkPrivilege.
|
||||
await fs.symlink(outsideDir, linkDir, process.platform === "win32" ? "junction" : undefined);
|
||||
|
||||
const patch = `*** Begin Patch
|
||||
*** Delete File: linkdir/victim.txt
|
||||
@@ -310,7 +320,13 @@ describe("applyPatch", () => {
|
||||
await fs.writeFile(outsideTarget, "keep\n", "utf8");
|
||||
|
||||
const linkDir = path.join(dir, "link");
|
||||
await fs.symlink(outsideDir, linkDir);
|
||||
// Use 'junction' on Windows — junctions target directories without
|
||||
// requiring SeCreateSymbolicLinkPrivilege.
|
||||
await fs.symlink(
|
||||
outsideDir,
|
||||
linkDir,
|
||||
process.platform === "win32" ? "junction" : undefined,
|
||||
);
|
||||
|
||||
const patch = `*** Begin Patch
|
||||
*** Delete File: link
|
||||
|
||||
Reference in New Issue
Block a user