This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
test: rstudio alb integration tests #813
Merged
nguyen102
merged 17 commits into
awslabs:chore-merge-feature-rstudio
from
nguyen102:feat-rstudio-alb-integration-tests
Nov 18, 2021
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
145790f
fix: count logic alb workspaces (#764)
SanketD92 f519a0b
chore: merge develop to rstudio (#776)
SanketD92 4cf6119
fix: better error message
SanketD92 2b73875
fix: bootstrap changes
SanketD92 07d03e3
fix: replace get with post rstudio connect (#796)
SanketD92 079e11c
fix: Don't delete ALB if another instance is starting (#797)
nguyen102 bd0e7ad
fix: Update naming of terminate-launch-dependency test
599b19a
Add integration tests for RStudio
b2360fa
Merge branch 'rstudio-integration-tests' into feat-rstudio-alb-integr…
ad16fcb
Fix merge conflict issues
039d82e
Fix merge conflict issues
d1eb483
Fix merge conflict issues
ce1265b
Fix merge conflict issues
ab0f185
Updated to work with AppStream
3813a4d
Merge branch 'chore-merge-feature-rstudio' into feat-rstudio-alb-inte…
0c4fc28
Working
384395c
Update
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
158 changes: 158 additions & 0 deletions
158
main/integration-tests/__test__/advanced-tests/rstudio/launch-rstudio-workspace.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,158 @@ | ||
/* | ||
* 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 axios = require('axios').default; | ||
const { runSetup } = require('../../../support/setup'); | ||
const { deleteWorkspaceServiceCatalog } = require('../../../support/complex/delete-workspace-service-catalog'); | ||
|
||
describe('Launch and terminate RStudio instance', () => { | ||
let setup; | ||
let adminSession; | ||
|
||
beforeAll(async () => { | ||
setup = await runSetup(); | ||
adminSession = await setup.defaultAdminSession(); | ||
}); | ||
|
||
afterAll(async () => { | ||
// await setup.cleanup(); | ||
}); | ||
|
||
async function checkAllRstudioWorkspaceIsTerminated() { | ||
const response = await adminSession.resources.workspaceServiceCatalogs.get(); | ||
const workspaces = response.filter(workspace => { | ||
return ( | ||
workspace.envTypeId === setup.defaults.envTypes.rstudio.envTypeId && | ||
!['TERMINATED', 'FAILED'].includes(workspace.status) | ||
); | ||
}); | ||
if (workspaces.length > 0) { | ||
throw new Error('All RStudio workspaces should be terminated or failed'); | ||
} | ||
} | ||
|
||
// eslint-disable-next-line jest/expect-expect | ||
it('should launch a RStudio instance', async () => { | ||
// Putting checkAllRstudioWorkspaceIsTerminated check here, because putting this check in `beforeAll` will not stop executing the test if the check does fail | ||
// https://github.com/facebook/jest/issues/2713 | ||
await checkAllRstudioWorkspaceIsTerminated(); | ||
|
||
const envId = await launchRStudioWorkspace(); | ||
// const envId = 'f7cb0f78-3fd2-4351-bea0-b6a05096c2c5'; | ||
|
||
// For installations without AppStream enabled, check that workspace CIDR can be changed | ||
if (!setup.defaults.isAppStreamEnabled) { | ||
await checkCIDR(envId); | ||
} | ||
|
||
const rstudioServerUrlResponse = await checkConnectionUrlCanBeCreated(envId); | ||
await checkConnectionUrlNetworkConnectivity(rstudioServerUrlResponse); | ||
await checkWorkspaceCanBeTerminatedCorrectly(envId); | ||
}); | ||
|
||
async function launchRStudioWorkspace() { | ||
const workspaceName = setup.gen.string({ prefix: 'launch-studio-workspace-test' }); | ||
const createWorkspaceBody = { | ||
name: workspaceName, | ||
envTypeId: setup.defaults.envTypes.rstudio.envTypeId, | ||
envTypeConfigId: setup.defaults.envTypes.rstudio.envTypeConfigId, | ||
studyIds: [], | ||
description: 'test', | ||
projectId: setup.defaults.project.id, | ||
}; | ||
if (!setup.defaults.isAppStreamEnabled) { | ||
createWorkspaceBody.cidr = '0.0.0.0/24'; | ||
} | ||
const env = await adminSession.resources.workspaceServiceCatalogs.create(createWorkspaceBody); | ||
await sleep(2000); | ||
await adminSession.resources.workflows | ||
.versions('wf-provision-environment-sc') | ||
.version(1) | ||
.findAndPollWorkflow(env.id, 10000, 90); | ||
return env.id; | ||
} | ||
|
||
async function checkCIDR(envId) { | ||
const cidrs = { | ||
cidr: [ | ||
{ | ||
protocol: 'tcp', | ||
fromPort: 22, | ||
toPort: 22, | ||
cidrBlocks: ['0.0.0.0/32'], | ||
}, | ||
{ | ||
protocol: 'tcp', | ||
fromPort: 80, | ||
toPort: 80, | ||
cidrBlocks: ['0.0.0.0/32'], | ||
}, | ||
{ | ||
protocol: 'tcp', | ||
fromPort: 443, | ||
toPort: 443, | ||
cidrBlocks: ['0.0.0.0/32'], | ||
}, | ||
], | ||
}; | ||
await expect( | ||
adminSession.resources.workspaceServiceCatalogs.workspaceServiceCatalog(envId).cidr(cidrs), | ||
).resolves.toBeDefined(); | ||
} | ||
|
||
async function checkWorkspaceCanBeTerminatedCorrectly(envId) { | ||
await adminSession.resources.workspaceServiceCatalogs.workspaceServiceCatalog(envId).delete(); | ||
await sleep(2000); | ||
await adminSession.resources.workflows | ||
.versions('wf-terminate-environment-sc') | ||
.version(1) | ||
.findAndPollWorkflow(envId, 10000, 35); | ||
|
||
const envState = await adminSession.resources.workspaceServiceCatalogs.workspaceServiceCatalog(envId).get(); | ||
|
||
// Check that workspace terminated correctly | ||
expect(envState.status).toEqual('TERMINATED'); | ||
await deleteWorkspaceServiceCatalog({ aws: setup.aws, id: envId }); | ||
} | ||
|
||
async function checkConnectionUrlCanBeCreated(envId) { | ||
const rstudioServerUrlResponse = await adminSession.resources.workspaceServiceCatalogs | ||
.workspaceServiceCatalog(envId) | ||
.connections() | ||
.connection('id-1') | ||
.createUrl(); | ||
expect(rstudioServerUrlResponse.url).toBeDefined(); | ||
if (setup.defaults.isAppStreamEnabled) { | ||
expect(rstudioServerUrlResponse.appstreamDestinationUrl).toBeDefined(); | ||
} | ||
|
||
return rstudioServerUrlResponse; | ||
} | ||
|
||
async function checkConnectionUrlNetworkConnectivity(rstudioServerUrlResponse) { | ||
if (!setup.defaults.isAppStreamEnabled) { | ||
// VERIFY active workspaces are associated with unexpired TLSv1.2 certs | ||
// By default Axios verify that the domain's SSL cert is valid. If we're able to get a response from the domain it means the domain's cert is valid | ||
// Getting a 403 response code is expected because our client's IP address is not whitelisted to access the RStudio server | ||
const url = rstudioServerUrlResponse.url; | ||
await expect(axios.get(url)).rejects.toThrow('Request failed with status code 403'); | ||
} else { | ||
// If AppStream is enabled, we should not be able to access the RStudio url from the internet | ||
const url = rstudioServerUrlResponse.appstreamDestinationUrl; | ||
await expect(axios.get(url)).rejects.toThrow(/getaddrinfo ENOTFOUND .*/); | ||
} | ||
} | ||
}); |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making updates to CIDR is actually a
POST
method, not aPUT
method. (Link here]