Skip to content

Commit

Permalink
Merge pull request #610 from snyk/fix/do-not-overwrite-values
Browse files Browse the repository at this point in the history
fix: do not overwrite values [CLI-543]
  • Loading branch information
thisislawatts authored Oct 31, 2024
2 parents a204504 + e1495f3 commit 437ba25
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sub-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function execute(
args: string[],
options?,
): Promise<CmdOutput> {
const spawnOptions: any = { shell: true, env: process.env };
const spawnOptions: any = { shell: true, env: { ...process.env } };
if (options && options.cwd) {
spawnOptions.cwd = options.cwd;
}
Expand Down
34 changes: 34 additions & 0 deletions test/lib/sub-process.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { execute } from "../../lib/sub-process";

describe("sub-process", () => {
let preTestEnv: NodeJS.ProcessEnv;

beforeEach(() => {
preTestEnv = { ...process.env };
});

afterEach(() => {
process.env = { ...preTestEnv };
});

it("restores proxy environment", async () => {
process.env.SNYK_SYSTEM_HTTPS_PROXY = "https://1.1.1.1";
process.env.SNYK_SYSTEM_HTTP_PROXY = "http://2.2.2.2";
process.env.SNYK_SYSTEM_NO_PROXY = "snyk.com";

process.env.HTTPS_PROXY = "http://127.0.0.1";
process.env.HTTP_PROXY = "http://127.0.0.1";
process.env.NO_PROXY = "example.com";

const { stdout } = await execute("env", [], {});

expect(stdout).toContain("HTTPS_PROXY=https://1.1.1.1");
expect(process.env.HTTPS_PROXY).toStrictEqual("http://127.0.0.1");

expect(stdout).toContain("HTTP_PROXY=http://2.2.2.2");
expect(process.env.HTTP_PROXY).toStrictEqual("http://127.0.0.1");

expect(stdout).toContain("NO_PROXY=snyk.com");
expect(process.env.NO_PROXY).toStrictEqual("example.com");
});
});

0 comments on commit 437ba25

Please sign in to comment.