-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: copy process environment before changing it to avoid side effects (
#107) --------- Co-authored-by: Jason Luong <jason.luong@snyk.io>
- Loading branch information
1 parent
30edf37
commit c851b60
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { test } from 'tap'; | ||
import { execute } from '../lib/sub-process'; | ||
|
||
test('sub-process', (t) => { | ||
let preTestEnv; | ||
t.beforeEach(async () => { | ||
preTestEnv = { ...process.env }; | ||
}); | ||
|
||
t.afterEach(async () => { | ||
process.env = { ...preTestEnv }; | ||
}); | ||
|
||
t.test('restore proxy environment', async (t) => { | ||
process.env.SNYK_SYSTEM_HTTPS_PROXY = "http://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 result = await execute('env', []); | ||
|
||
t.contains(result, 'HTTPS_PROXY=http://1.1.1.1'); | ||
t.contains(result, 'HTTP_PROXY=http://2.2.2.2'); | ||
t.contains(result, 'NO_PROXY=snyk.com'); | ||
|
||
t.equals(process.env.HTTPS_PROXY, 'http://127.0.0.1'); | ||
t.equals(process.env.HTTP_PROXY, 'http://127.0.0.1'); | ||
t.equals(process.env.NO_PROXY, 'example.com'); | ||
}); | ||
|
||
t.end(); | ||
}); |