Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

test(windows): pin the PowerShell module path in scan-output fixtures (#2384)

Michael D'Angelo1ae19fa01333
diff --git a/sdk/typescript/tests-ts/windows-scan-output.test.ts b/sdk/typescript/tests-ts/windows-scan-output.test.ts
index 12ae15be8..036ce6e5f 100644
--- a/sdk/typescript/tests-ts/windows-scan-output.test.ts
+++ b/sdk/typescript/tests-ts/windows-scan-output.test.ts
@@ -54,8 +54,11 @@ async function runPowerShell(script: string, environment: NodeJS.ProcessEnv) {
],
{
env: {
- ...process.env,
- ...environment,
+ ...Object.fromEntries(
+ Object.entries({ ...process.env, ...environment }).filter(
+ ([name]) => name.toUpperCase() !== "PSMODULEPATH",
+ ),
+ ),
PSModulePath: join(powershell, "Modules"),
},
},
@@ -63,6 +66,22 @@ async function runPowerShell(script: string, environment: NodeJS.ProcessEnv) {
return stdout.trim();
}
+windowsTest(
+ "pins the system PowerShell modules for case-variant environment keys",
+ async () => {
+ const alternate = await temporaryDirectory();
+ const result = await runPowerShell(
+ [
+ "$ErrorActionPreference = 'Stop'",
+ "$null = Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $env:CODEX_SECURITY_TEST_MODULES",
+ "($env:PSModulePath -split ';') -notcontains $env:CODEX_SECURITY_TEST_MODULES",
+ ].join("; "),
+ { PSMODULEPATH: alternate, CODEX_SECURITY_TEST_MODULES: alternate },
+ );
+ expect(result).toBe("True");
+ },
+);
+
function inspectAcl(path: string, expression: string): Promise<string> {
return runPowerShell(
`$ErrorActionPreference = 'Stop'; $acl = Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $env:CODEX_SECURITY_TEST_ACL_PATH; ${expression}`,