-
Notifications
You must be signed in to change notification settings - Fork 736
test(ec2): add security related unit tests #5778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
24919b7
61f95f0
12cf3ec
423ca0c
9a72b73
b741e83
d6c052b
b2890bd
697f4bc
b47c788
57eb886
8a1131d
4071645
36c133b
4a55e56
a92ba99
c2e17bd
4cb7b3c
60c2bed
5c48e66
eff906a
622c4d2
07026be
f13cf65
a11c2fc
b910f85
bb1c3b9
5697da1
b57053d
ba9fa6f
ff0cf37
bd292c2
6bec701
3d1740a
6b1bf0f
69f09ab
d10f613
cfcc6bb
4b0785f
deff2a2
c6f02ac
5810995
2d0d4fb
912d579
f2441ea
7e7b0cb
a28c33e
3c80c2f
b82672a
e103c1e
a8880de
6cc9743
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| import assert from 'assert' | ||
| import { minimumSsmActions, promptToAddInlinePolicy } from '../../shared/remoteSession' | ||
| import { IamClient } from '../../shared/clients/iamClient' | ||
| import { getTestWindow } from './vscode/window' | ||
| import { cancel } from '../../shared' | ||
|
|
||
| describe('minimumSsmActions', function () { | ||
| it('should contain minimal actions needed for ssm connection', function () { | ||
| assert.deepStrictEqual(minimumSsmActions, [ | ||
| 'ssmmessages:CreateControlChannel', | ||
| 'ssmmessages:CreateDataChannel', | ||
| 'ssmmessages:OpenControlChannel', | ||
| 'ssmmessages:OpenDataChannel', | ||
| 'ssm:DescribeAssociation', | ||
| 'ssm:ListAssociations', | ||
| 'ssm:UpdateInstanceInformation', | ||
| ]) | ||
| }) | ||
|
|
||
| it('prompts the user for confirmation before adding policies and allow cancels', async function () { | ||
| getTestWindow().onDidShowMessage((message) => { | ||
| assert.ok(message.message.includes('add'), 'should prompt to add policies') | ||
| getTestWindow().getFirstMessage().selectItem(cancel) | ||
| }) | ||
| const added = await promptToAddInlinePolicy({} as IamClient, 'roleArnTest') | ||
| assert.ok(!added, 'should not add policies by default') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,16 +7,15 @@ import assert from 'assert' | |
| import * as vscode from 'vscode' | ||
| import * as os from 'os' | ||
| import * as path from 'path' | ||
|
|
||
| import * as testutil from '../../testUtil' | ||
| import { findTypescriptCompiler, getVscodeCliPath } from '../../../shared/utilities/pathFind' | ||
| import { fs } from '../../../shared' | ||
| import { findSshPath, findTypescriptCompiler, getVscodeCliPath } from '../../../shared/utilities/pathFind' | ||
| import { isWin } from '../../../shared/vscode/env' | ||
|
|
||
| describe('pathFind', function () { | ||
| it('findTypescriptCompiler()', async function () { | ||
| const iswin = process.platform === 'win32' | ||
| const workspace = vscode.workspace.workspaceFolders![0] | ||
| const tscNodemodules = path.join(workspace.uri.fsPath, `foo/bar/node_modules/.bin/tsc${iswin ? '.cmd' : ''}`) | ||
| const tscNodemodules = path.join(workspace.uri.fsPath, `foo/bar/node_modules/.bin/tsc${isWin() ? '.cmd' : ''}`) | ||
| await fs.delete(tscNodemodules, { force: true }) | ||
|
|
||
| // The test workspace normally doesn't have node_modules so this will | ||
|
|
@@ -42,4 +41,50 @@ describe('pathFind', function () { | |
| const regex = /bin[\\\/](code|code-insiders)$/ | ||
| assert.ok(regex.test(vscPath), `expected regex ${regex} to match: "${vscPath}"`) | ||
| }) | ||
|
|
||
| describe('findSshPath', function () { | ||
| it('first tries ssh in $PATH', async function () { | ||
| const workspace = await testutil.createTestWorkspaceFolder() | ||
| const fakeSshPath = path.join(workspace.uri.fsPath, `ssh${isWin() ? '.cmd' : ''}`) | ||
|
|
||
| await testutil.withEnvPath(workspace.uri.fsPath, async () => { | ||
|
||
| const firstResult = await findSshPath(false) | ||
|
|
||
| await testutil.createExecutableFile(fakeSshPath, 'echo "this is ssh"') | ||
|
|
||
| const secondResult = await findSshPath(false) | ||
|
|
||
| assert.notStrictEqual(firstResult, secondResult) | ||
| assert.strictEqual(secondResult, 'ssh') | ||
| }) | ||
| }) | ||
|
|
||
| it('only returns executable ssh path', async function () { | ||
| const workspace = await testutil.createTestWorkspaceFolder() | ||
| const fakeSshPath = path.join(workspace.uri.fsPath, `ssh${isWin() ? '.cmd' : ''}`) | ||
| await fs.writeFile(fakeSshPath, 'this is not executable') | ||
|
|
||
| await testutil.withEnvPath(workspace.uri.fsPath, async () => { | ||
| const firstResult = await findSshPath(false) | ||
| assert.notStrictEqual(firstResult, 'ssh') | ||
| }) | ||
| }) | ||
|
|
||
| it('caches result from previous runs', async function () { | ||
| const workspace = await testutil.createTestWorkspaceFolder() | ||
| const fakeSshPath = path.join(workspace.uri.fsPath, `ssh${isWin() ? '.cmd' : ''}`) | ||
| await testutil.createExecutableFile(fakeSshPath, 'echo "this is ssh"') | ||
|
|
||
| await testutil.withEnvPath(workspace.uri.fsPath, async () => { | ||
| const firstResult = await findSshPath(true) | ||
|
|
||
| await fs.delete(fakeSshPath) | ||
|
|
||
| const secondResult = await findSshPath(true) | ||
|
|
||
| assert.strictEqual(firstResult, secondResult) | ||
| assert.strictEqual(secondResult, 'ssh') | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| import assert from 'assert' | ||
| import { createTestWorkspaceFolder, readEnvPath, withEnvPath } from '../../testUtil' | ||
|
|
||
| describe('withEnvPath', function () { | ||
| it('resets path when error in task', async function () { | ||
| const originalPath = readEnvPath() | ||
| const tempFolder = await createTestWorkspaceFolder() | ||
| try { | ||
| await withEnvPath(tempFolder.uri.fsPath, async () => { | ||
| throw new Error() | ||
| }) | ||
| } catch {} | ||
| assert.strictEqual(readEnvPath(), originalPath) | ||
| }) | ||
|
|
||
| it('changes $PATH temporarily', async function () { | ||
| const originalPath = readEnvPath() | ||
| const tempFolder = await createTestWorkspaceFolder() | ||
| await withEnvPath(tempFolder.uri.fsPath, async () => { | ||
| assert.strictEqual(readEnvPath(), tempFolder.uri.fsPath) | ||
| }) | ||
| assert.strictEqual(readEnvPath(), originalPath) | ||
| }) | ||
| }) |
Uh oh!
There was an error while loading. Please reload this page.