Tests: extend exec allowlist glob coverage
This commit is contained in:
@@ -7,8 +7,18 @@ describe("matchesExecAllowlistPattern", () => {
|
|||||||
expect(matchesExecAllowlistPattern("/tmp/a?b", "/tmp/acb")).toBe(true);
|
expect(matchesExecAllowlistPattern("/tmp/a?b", "/tmp/acb")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keeps ** matching across path separators", () => {
|
||||||
|
expect(matchesExecAllowlistPattern("/tmp/**/tool", "/tmp/a/b/tool")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it.runIf(process.platform !== "win32")("preserves case sensitivity on POSIX", () => {
|
it.runIf(process.platform !== "win32")("preserves case sensitivity on POSIX", () => {
|
||||||
expect(matchesExecAllowlistPattern("/tmp/Allowed-Tool", "/tmp/allowed-tool")).toBe(false);
|
expect(matchesExecAllowlistPattern("/tmp/Allowed-Tool", "/tmp/allowed-tool")).toBe(false);
|
||||||
expect(matchesExecAllowlistPattern("/tmp/Allowed-Tool", "/tmp/Allowed-Tool")).toBe(true);
|
expect(matchesExecAllowlistPattern("/tmp/Allowed-Tool", "/tmp/Allowed-Tool")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.runIf(process.platform === "win32")("preserves case-insensitive matching on Windows", () => {
|
||||||
|
expect(matchesExecAllowlistPattern("C:/Tools/Allowed-Tool", "c:/tools/allowed-tool")).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ function escapeRegExpLiteral(input: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function compileGlobRegex(pattern: string): RegExp {
|
function compileGlobRegex(pattern: string): RegExp {
|
||||||
const cached = globRegexCache.get(pattern);
|
const cacheKey = `${process.platform}:${pattern}`;
|
||||||
|
const cached = globRegexCache.get(cacheKey);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
@@ -59,7 +60,7 @@ function compileGlobRegex(pattern: string): RegExp {
|
|||||||
if (globRegexCache.size >= GLOB_REGEX_CACHE_LIMIT) {
|
if (globRegexCache.size >= GLOB_REGEX_CACHE_LIMIT) {
|
||||||
globRegexCache.clear();
|
globRegexCache.clear();
|
||||||
}
|
}
|
||||||
globRegexCache.set(pattern, compiled);
|
globRegexCache.set(cacheKey, compiled);
|
||||||
return compiled;
|
return compiled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user