import os from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; import {
extensionUsesSkippedScannerPath,
isPathInside,
isPathInsideWithRealpath,
} from "./scan-paths.js";
it("returns true when both paths exist and candidate is inside base", () => { // os.tmpdir() and itself both exist on disk const result = isPathInsideWithRealpath(tmpDir, tmpDir);
expect(result).toBe(true);
});
it("returns false (line 25) when candidate is outside base without realpath check needed", () => { // /etc is outside os.tmpdir() — isPathInside returns false immediately const result = isPathInsideWithRealpath(tmpDir, "/etc");
expect(result).toBe(false); // covers line 25: return false
});
it("returns false (safe default) when realpath fails for non-existent candidate", () => { // Non-existent path causes safeRealpathSync to return null (covers line 15) // New safe default (requireRealpath not set): returns false — secure by default const nonExistent = path.join(tmpDir, "__does_not_exist_clawin_test__"); const result = isPathInsideWithRealpath(tmpDir, nonExistent);
expect(result).toBe(false);
});
it("returns false when requireRealpath is true and realpath fails", () => { const nonExistent = path.join(tmpDir, "__does_not_exist_clawin_test__"); const result = isPathInsideWithRealpath(tmpDir, nonExistent, { requireRealpath: true });
expect(result).toBe(false);
});
it("returns true (explicit opt-out) when requireRealpath is false and realpath fails", () => { const nonExistent = path.join(tmpDir, "__does_not_exist_clawin_test__"); const result = isPathInsideWithRealpath(tmpDir, nonExistent, { requireRealpath: false });
expect(result).toBe(true);
});
it("returns false (safe default) when realpath fails for base path", () => { const nonExistentBase = path.join(tmpDir, "__nonexistent_base__"); const child = path.join(nonExistentBase, "child.ts"); const result = isPathInsideWithRealpath(nonExistentBase, child);
expect(result).toBe(false);
});
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.