-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add method to get new token for adv tests (#638)
* Add Raymond Test * Add env w/ studies provisioning test case and support for env type configurations * Use MatchObject matcher and improve test descriptions * bug: multiple workflows provisioning * Add polling utility function and termination code for workspaces * chore: fix linting errors * Add delay between api call and polling * Move terminate workflow code to support file * Add verify study permissions test for EC2Linux * Fix import statement in resource file * Add node-ssh package * Update pnpm lock file * Fix linting errors * Add external study to config * fix: Add more cleanup to adv int tests * fix: Rename externalStudy to byobStudy * fix: emrConfigId name update * chore: empty commit to fix mainline protection * fix: Comment out adv tests to debug * fix: correct default ui timeout * fix: remove adv test file * fix: refresh token in tests that start workflows * feat: add method to get new token * feat: add new token method to other tests that poll workflows * fix: remove debug line * fix: uncomment sleep import * chore: empty commit to fix mainline protection * chore: remove debug new-token * chore: remove console logs Co-authored-by: Raymond Yu <raymyu@amazon.com> Co-authored-by: Sanket Dharwadkar <sdharwad@amazon.com>
- Loading branch information
1 parent
5453f5e
commit 01a87b1
Showing
4 changed files
with
298 additions
and
4 deletions.
There are no files selected for viewing
221 changes: 221 additions & 0 deletions
221
...on-tests/__test__/advanced-tests/study-permissions/verify-linux-study-permissions.test.js
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,221 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
const { sleep } = require('@aws-ee/base-services/lib/helpers/utils'); | ||
const { NodeSSH } = require('node-ssh'); | ||
const { mountStudies, readWrite } = require('../../../support/complex/run-shell-command'); | ||
const { runSetup } = require('../../../support/setup'); | ||
const { getIdToken } = require('../../../support/utils/id-token'); | ||
|
||
describe('EC2 Linux scenarios', () => { | ||
let setup; | ||
let ssh; | ||
// Obtains new global token to prevent mid-test expiration | ||
async function newToken() { | ||
const content = setup.settings.content; | ||
setup.settings.content.adminIdToken = await getIdToken({ | ||
username: content.username, | ||
password: content.password, | ||
apiEndpoint: content.apiEndpoint, | ||
authenticationProviderId: content.authenticationProviderId, | ||
}); | ||
} | ||
async function testSetup() { | ||
const adminSession = await setup.createAdminSession(); | ||
const admin2Session = await setup.createAdminSession(); | ||
await newToken(); | ||
const keyPair = await admin2Session.resources.keyPairs.create(); | ||
return { adminSession, admin2Session, keyPair }; | ||
} | ||
|
||
beforeAll(async () => { | ||
setup = await runSetup(); | ||
ssh = new NodeSSH(); | ||
jest.retryTimes(0); | ||
}); | ||
afterAll(async () => { | ||
await newToken(); | ||
await setup.cleanup(); | ||
}); | ||
|
||
describe('Updates to mounted study permissions', () => { | ||
it('should propagate for Org Study', async () => { | ||
const { adminSession, admin2Session, keyPair } = await testSetup(); | ||
const studyId = setup.gen.string({ prefix: `create-org-study-test` }); | ||
await adminSession.resources.studies.create({ id: studyId, name: studyId, category: 'Organization' }); | ||
await adminSession.resources.studies | ||
.study(studyId) | ||
.propagatePermission(admin2Session, ['admin', 'readwrite'], []); | ||
|
||
const workspaceName = setup.gen.string({ prefix: 'workspace-sc-test' }); | ||
|
||
const env = await admin2Session.resources.workspaceServiceCatalogs.create({ | ||
name: workspaceName, | ||
envTypeId: setup.defaults.envTypes.ec2Linux.envTypeId, | ||
envTypeConfigId: setup.defaults.envTypes.ec2Linux.envTypeConfigId, | ||
studyIds: [studyId], | ||
description: 'test', | ||
projectId: setup.defaults.project.id, | ||
cidr: '0.0.0.0/0', | ||
}); | ||
// Poll until workspace is provisioned | ||
await sleep(2000); | ||
await adminSession.resources.workflows | ||
.versions('wf-provision-environment-sc') | ||
.version(1) | ||
.findAndPollWorkflow(env.id, 10000, 48); | ||
|
||
// Connect to workspace | ||
const networkInfo = await admin2Session.resources.workspaceServiceCatalogs | ||
.workspaceServiceCatalog(env.id) // env.id | ||
.connections() | ||
.connection('id-1') | ||
.sendSshPublicKey({ keyPairId: keyPair.id }); | ||
|
||
await ssh.connect({ | ||
host: networkInfo.networkInterfaces[0].publicDnsName, | ||
username: 'ec2-user', | ||
privateKey: keyPair.privateKey, | ||
}); | ||
|
||
// Mount studies | ||
let output; | ||
output = await mountStudies(ssh, studyId); | ||
|
||
// Readwrite permission level | ||
output = await readWrite(ssh, studyId); | ||
expect(output.stdout).toEqual(expect.stringMatching(/ec2-user 20/)); | ||
|
||
// Admin permission level | ||
await adminSession.resources.studies.study(studyId).propagatePermission(admin2Session, ['admin'], ['readwrite']); | ||
output = await readWrite(ssh, studyId); | ||
expect(output.stderr).toEqual(expect.stringMatching(/write error: Permission denied/)); | ||
|
||
// Readonly permission level | ||
await adminSession.resources.studies.study(studyId).propagatePermission(admin2Session, ['readonly'], ['admin']); | ||
output = await readWrite(ssh, studyId); | ||
expect(output.stderr).toEqual(expect.stringMatching(/write error: Permission denied/)); | ||
|
||
// None permission level | ||
await adminSession.resources.studies.study(studyId).propagatePermission(admin2Session, [], ['readonly']); | ||
output = await readWrite(ssh, studyId); | ||
expect(output.stderr).toEqual(expect.stringMatching(/reading directory .: Permission denied/)); | ||
|
||
await ssh.dispose(); | ||
await newToken(); | ||
await setup.cleanup(); | ||
}); | ||
|
||
it('should propagate for BYOB Study', async () => { | ||
const { adminSession, admin2Session, keyPair } = await testSetup(); | ||
const externalStudy = setup.defaults.byobStudy; | ||
const workspaceName = setup.gen.string({ prefix: 'workspace-sc-test' }); | ||
await adminSession.resources.studies.study(externalStudy).propagatePermission(admin2Session, ['readwrite'], []); | ||
|
||
const env = await admin2Session.resources.workspaceServiceCatalogs.create({ | ||
name: workspaceName, | ||
envTypeId: setup.defaults.envTypes.ec2Linux.envTypeId, | ||
envTypeConfigId: setup.defaults.envTypes.ec2Linux.envTypeConfigId, | ||
studyIds: [externalStudy], | ||
description: 'test', | ||
projectId: setup.defaults.project.id, | ||
cidr: '0.0.0.0/0', | ||
}); | ||
// Poll until workspace is provisioned | ||
await sleep(2000); | ||
await adminSession.resources.workflows | ||
.versions('wf-provision-environment-sc') | ||
.version(1) | ||
.findAndPollWorkflow(env.id, 10000, 48); | ||
// Connect to workspace | ||
const networkInfo = await admin2Session.resources.workspaceServiceCatalogs | ||
.workspaceServiceCatalog(env.id) // env.id | ||
.connections() | ||
.connection('id-1') | ||
.sendSshPublicKey({ keyPairId: keyPair.id }); | ||
|
||
await ssh.connect({ | ||
host: networkInfo.networkInterfaces[0].publicDnsName, | ||
username: 'ec2-user', | ||
privateKey: keyPair.privateKey, | ||
}); | ||
|
||
// Mount studies | ||
let output; | ||
output = await mountStudies(ssh, externalStudy); | ||
// console.log(`STDOUT:\n${output.stdout}\n\nSTDERR:\n${output.stderr}`); | ||
|
||
// Readwrite permission level | ||
output = await readWrite(ssh, externalStudy); | ||
expect(output.stdout).toEqual(expect.stringMatching(/ec2-user 20/)); | ||
|
||
// Readonly permission level | ||
await adminSession.resources.studies | ||
.study(externalStudy) | ||
.propagatePermission(admin2Session, ['readonly'], ['readwrite']); | ||
output = await readWrite(ssh, externalStudy); | ||
expect(output.stderr).toEqual(expect.stringMatching(/reading directory .: Permission denied/)); | ||
|
||
await ssh.dispose(); | ||
// Removes user permission | ||
await adminSession.resources.studies.study(externalStudy).propagatePermission(admin2Session, [], ['readonly']); | ||
await newToken(); | ||
await setup.cleanup(); | ||
}); | ||
}); | ||
|
||
describe('Confirm study permissions', () => { | ||
it('should pass for My Study', async () => { | ||
const { adminSession, admin2Session, keyPair } = await testSetup(); | ||
const studyId = setup.gen.string({ prefix: `create-my-study-test` }); | ||
await admin2Session.resources.studies.create({ id: studyId, name: studyId, category: 'My Studies' }); | ||
|
||
const workspaceName = setup.gen.string({ prefix: 'workspace-sc-test' }); | ||
const env = await admin2Session.resources.workspaceServiceCatalogs.create({ | ||
name: workspaceName, | ||
envTypeId: setup.defaults.envTypes.ec2Linux.envTypeId, | ||
envTypeConfigId: setup.defaults.envTypes.ec2Linux.envTypeConfigId, | ||
studyIds: [studyId], | ||
description: 'test', | ||
projectId: setup.defaults.project.id, | ||
cidr: '0.0.0.0/0', | ||
}); | ||
|
||
// Poll until workspace is provisioned | ||
await sleep(2000); | ||
await adminSession.resources.workflows | ||
.versions('wf-provision-environment-sc') | ||
.version(1) | ||
.findAndPollWorkflow(env.id, 10000, 48); | ||
|
||
// Connect to workspace | ||
const networkInfo = await admin2Session.resources.workspaceServiceCatalogs | ||
.workspaceServiceCatalog(env.id) // env.id | ||
.connections() | ||
.connection('id-1') | ||
.sendSshPublicKey({ keyPairId: keyPair.id }); | ||
|
||
await ssh.connect({ | ||
host: networkInfo.networkInterfaces[0].publicDnsName, | ||
username: 'ec2-user', | ||
privateKey: keyPair.privateKey, | ||
}); | ||
|
||
const output = await mountStudies(ssh, studyId); | ||
expect(output.stdout).toEqual(expect.stringMatching(/output.txt/)); | ||
await newToken(); | ||
await setup.cleanup(); | ||
}); | ||
}); | ||
}); |
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
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