From 2ac031d6fd3cb9b98ffb1801033d96675291f577 Mon Sep 17 00:00:00 2001 From: Leo K Date: Wed, 4 Aug 2021 21:47:43 +0200 Subject: feat(unstable): clean environmental variables for subprocess (#11571) This commit adds "Deno.RunOptions.clearEnv" option, that allows to clear environmental variables from parent process before spawning a subprocess. --- cli/tests/unit/process_test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/unit/process_test.ts b/cli/tests/unit/process_test.ts index 9bb4d7fc2..f187efe71 100644 --- a/cli/tests/unit/process_test.ts +++ b/cli/tests/unit/process_test.ts @@ -510,3 +510,31 @@ unitTest({ perms: { run: true, read: true } }, function killFailed(): void { p.close(); }); + +unitTest( + { perms: { run: true, read: true, env: true } }, + async function clearEnv(): Promise { + const p = Deno.run({ + cmd: [ + Deno.execPath(), + "eval", + "-p", + "JSON.stringify(Deno.env.toObject())", + ], + stdout: "piped", + clearEnv: true, + env: { + FOO: "23147", + }, + }); + + const obj = JSON.parse(new TextDecoder().decode(await p.output())); + + // can't check for object equality because the OS may set additional env vars for processes + // so we check if PATH isn't present as that is a common env var across OS's and isn't set for processes. + assertEquals(obj.FOO, "23147"); + assert(!("PATH" in obj)); + + p.close(); + }, +); -- cgit v1.2.3