-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: snap env variables leaking into terminal env (#185834)
* fix: snap env variables leaking into terminal env * chore: add spec
- Loading branch information
1 parent
982869f
commit 42457bd
Showing
5 changed files
with
200 additions
and
39 deletions.
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
128 changes: 128 additions & 0 deletions
128
src/vs/platform/environment/test/electron-main/environmentMainService.test.ts
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,128 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as assert from 'assert'; | ||
import { EnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService'; | ||
import product from 'vs/platform/product/common/product'; | ||
import { isLinux } from 'vs/base/common/platform'; | ||
|
||
suite('EnvironmentMainService', () => { | ||
|
||
test('can unset and restore snap env variables', () => { | ||
const service = new EnvironmentMainService({ '_': [] }, { '_serviceBrand': undefined, ...product }); | ||
|
||
process.env['TEST_ARG1_VSCODE_SNAP_ORIG'] = 'original'; | ||
process.env['TEST_ARG1'] = 'modified'; | ||
process.env['TEST_ARG2_SNAP'] = 'test_arg2'; | ||
process.env['TEST_ARG3_VSCODE_SNAP_ORIG'] = ''; | ||
process.env['TEST_ARG3'] = 'test_arg3_non_empty'; | ||
|
||
// Unset snap env variables | ||
service.unsetSnapExportedVariables(); | ||
if (isLinux) { | ||
assert.strictEqual(process.env['TEST_ARG1'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2'], undefined); | ||
assert.strictEqual(process.env['TEST_ARG1_VSCODE_SNAP_ORIG'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2_SNAP'], 'test_arg2'); | ||
assert.strictEqual(process.env['TEST_ARG3_VSCODE_SNAP_ORIG'], ''); | ||
assert.strictEqual(process.env['TEST_ARG3'], undefined); | ||
} else { | ||
assert.strictEqual(process.env['TEST_ARG1'], 'modified'); | ||
assert.strictEqual(process.env['TEST_ARG2'], undefined); | ||
assert.strictEqual(process.env['TEST_ARG1_VSCODE_SNAP_ORIG'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2_SNAP'], 'test_arg2'); | ||
assert.strictEqual(process.env['TEST_ARG3_VSCODE_SNAP_ORIG'], ''); | ||
assert.strictEqual(process.env['TEST_ARG3'], 'test_arg3_non_empty'); | ||
} | ||
|
||
// Restore snap env variables | ||
service.restoreSnapExportedVariables(); | ||
if (isLinux) { | ||
assert.strictEqual(process.env['TEST_ARG1'], 'modified'); | ||
assert.strictEqual(process.env['TEST_ARG1_VSCODE_SNAP_ORIG'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2_SNAP'], 'test_arg2'); | ||
assert.strictEqual(process.env['TEST_ARG2'], undefined); | ||
assert.strictEqual(process.env['TEST_ARG3_VSCODE_SNAP_ORIG'], ''); | ||
assert.strictEqual(process.env['TEST_ARG3'], 'test_arg3_non_empty'); | ||
} else { | ||
assert.strictEqual(process.env['TEST_ARG1'], 'modified'); | ||
assert.strictEqual(process.env['TEST_ARG1_VSCODE_SNAP_ORIG'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2_SNAP'], 'test_arg2'); | ||
assert.strictEqual(process.env['TEST_ARG2'], undefined); | ||
assert.strictEqual(process.env['TEST_ARG3_VSCODE_SNAP_ORIG'], ''); | ||
assert.strictEqual(process.env['TEST_ARG3'], 'test_arg3_non_empty'); | ||
} | ||
}); | ||
|
||
test('can invoke unsetSnapExportedVariables and restoreSnapExportedVariables multiple times', () => { | ||
const service = new EnvironmentMainService({ '_': [] }, { '_serviceBrand': undefined, ...product }); | ||
// Mock snap environment | ||
process.env['SNAP'] = '1'; | ||
process.env['SNAP_REVISION'] = 'test_revision'; | ||
|
||
process.env['TEST_ARG1_VSCODE_SNAP_ORIG'] = 'original'; | ||
process.env['TEST_ARG1'] = 'modified'; | ||
process.env['TEST_ARG2_SNAP'] = 'test_arg2'; | ||
process.env['TEST_ARG3_VSCODE_SNAP_ORIG'] = ''; | ||
process.env['TEST_ARG3'] = 'test_arg3_non_empty'; | ||
|
||
// Unset snap env variables | ||
service.unsetSnapExportedVariables(); | ||
service.unsetSnapExportedVariables(); | ||
service.unsetSnapExportedVariables(); | ||
if (isLinux) { | ||
assert.strictEqual(process.env['TEST_ARG1'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2'], undefined); | ||
assert.strictEqual(process.env['TEST_ARG1_VSCODE_SNAP_ORIG'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2_SNAP'], 'test_arg2'); | ||
assert.strictEqual(process.env['TEST_ARG3_VSCODE_SNAP_ORIG'], ''); | ||
assert.strictEqual(process.env['TEST_ARG3'], undefined); | ||
} else { | ||
assert.strictEqual(process.env['TEST_ARG1'], 'modified'); | ||
assert.strictEqual(process.env['TEST_ARG2'], undefined); | ||
assert.strictEqual(process.env['TEST_ARG1_VSCODE_SNAP_ORIG'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2_SNAP'], 'test_arg2'); | ||
assert.strictEqual(process.env['TEST_ARG3_VSCODE_SNAP_ORIG'], ''); | ||
assert.strictEqual(process.env['TEST_ARG3'], 'test_arg3_non_empty'); | ||
} | ||
|
||
// Restore snap env variables | ||
service.restoreSnapExportedVariables(); | ||
service.restoreSnapExportedVariables(); | ||
if (isLinux) { | ||
assert.strictEqual(process.env['TEST_ARG1'], 'modified'); | ||
assert.strictEqual(process.env['TEST_ARG1_VSCODE_SNAP_ORIG'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2_SNAP'], 'test_arg2'); | ||
assert.strictEqual(process.env['TEST_ARG2'], undefined); | ||
assert.strictEqual(process.env['TEST_ARG3_VSCODE_SNAP_ORIG'], ''); | ||
assert.strictEqual(process.env['TEST_ARG3'], 'test_arg3_non_empty'); | ||
} else { | ||
assert.strictEqual(process.env['TEST_ARG1'], 'modified'); | ||
assert.strictEqual(process.env['TEST_ARG1_VSCODE_SNAP_ORIG'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2_SNAP'], 'test_arg2'); | ||
assert.strictEqual(process.env['TEST_ARG2'], undefined); | ||
assert.strictEqual(process.env['TEST_ARG3_VSCODE_SNAP_ORIG'], ''); | ||
assert.strictEqual(process.env['TEST_ARG3'], 'test_arg3_non_empty'); | ||
} | ||
|
||
// Unset snap env variables | ||
service.unsetSnapExportedVariables(); | ||
if (isLinux) { | ||
assert.strictEqual(process.env['TEST_ARG1'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2'], undefined); | ||
assert.strictEqual(process.env['TEST_ARG1_VSCODE_SNAP_ORIG'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2_SNAP'], 'test_arg2'); | ||
assert.strictEqual(process.env['TEST_ARG3_VSCODE_SNAP_ORIG'], ''); | ||
assert.strictEqual(process.env['TEST_ARG3'], undefined); | ||
} else { | ||
assert.strictEqual(process.env['TEST_ARG1'], 'modified'); | ||
assert.strictEqual(process.env['TEST_ARG2'], undefined); | ||
assert.strictEqual(process.env['TEST_ARG1_VSCODE_SNAP_ORIG'], 'original'); | ||
assert.strictEqual(process.env['TEST_ARG2_SNAP'], 'test_arg2'); | ||
assert.strictEqual(process.env['TEST_ARG3_VSCODE_SNAP_ORIG'], ''); | ||
assert.strictEqual(process.env['TEST_ARG3'], 'test_arg3_non_empty'); | ||
} | ||
}); | ||
}); |
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