Skip to content
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

test: connection url appstream #673

Merged
merged 5 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('awsAccountMgmtPlugin', () => {
const expected = [];

// OPERATE
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, container });
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId, requestContext, container });

// CHECK
expect(retVal).toEqual(expected);
Expand Down Expand Up @@ -91,10 +91,10 @@ describe('awsAccountMgmtPlugin', () => {
return indexes;
});

const expected = [{ id: 'env2', indexId: 'index1', isAppStreamConfigured: false, status: 'COMPLETED' }];
const expected = ['env2'];

// OPERATE
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, container });
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId, requestContext, container });

// CHECK
expect(retVal).toEqual(expected);
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('awsAccountMgmtPlugin', () => {
const expected = [];

// OPERATE
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, container });
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId, requestContext, container });

// CHECK
expect(retVal).toEqual(expected);
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('awsAccountMgmtPlugin', () => {
const expected = [];

// OPERATE
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, container });
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId, requestContext, container });

// CHECK
expect(retVal).toEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const settingKeys = {
* and is triggered if the user attempts to update the AWS account using SWB APIs.
* A similar check is performed on the UI components (AccountUtils) as well.
*/
async function getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, container }) {
async function getActiveNonAppStreamEnvs(payload) {
const { awsAccountId, requestContext, container } = payload;
const settings = await container.find('settings');
const isAppStreamEnabled = settings.getBoolean(settingKeys.isAppStreamEnabled);
if (!isAppStreamEnabled) return [];
Expand All @@ -35,19 +36,24 @@ async function getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, con
const indexesService = await container.find('indexesService');

const indexes = await indexesService.list(requestContext);
const indexesIdsOfInterest = _.map(
_.filter(indexes, index => index.awsAccountId === awsAccountId),
'id',
);
const indexesOfInterest = _.filter(indexes, index => index.awsAccountId === awsAccountId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but for arrays, JS comes with the filter method already. Therefore we don't have to use lodash for this. We don't have to change it for this PR, but for future reference.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

Copy link
Contributor Author

@SanketD92 SanketD92 Aug 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but there's a minor performance difference.

if (_.isEmpty(indexesOfInterest)) return [];
const indexesIdsOfInterest = _.map(indexesOfInterest, index => {
return index.id;
});

const scEnvs = await environmentScService.list(requestContext);
const retVal = _.filter(
const scEnvsOfInterest = _.filter(
scEnvs,
scEnv =>
_.includes(indexesIdsOfInterest, scEnv.indexId) &&
!scEnv.isAppStreamConfigured &&
!_.includes(nonActiveStates, scEnv.status),
);
if (_.isEmpty(scEnvsOfInterest)) return [];
const retVal = _.map(scEnvsOfInterest, scEnv => {
return scEnv.id;
});

return retVal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,8 @@ class AwsAccountsService extends Service {
'aws-account-mgmt',
'getActiveNonAppStreamEnvs',
{
payload: {
awsAccountId,
},
payload: { requestContext, container: this.container, awsAccountId },
},
{ requestContext, container: this.container },
);

if (!_.isEmpty(activeNonAppStreamEnvs))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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 fetch = require('node-fetch');
SanketD92 marked this conversation as resolved.
Show resolved Hide resolved
const { runSetup } = require('../../../../../support/setup');

describe('Create URL scenarios', () => {
let setup;
let adminSession;

beforeAll(async () => {
setup = await runSetup();
adminSession = await setup.defaultAdminSession();
});

afterAll(async () => {
await setup.cleanup();
});

// These tests assume workspaces have already been created in the SWB environment
// TODO: Create a new workspace during these tests, and terminate once done (dependent on GALI-1093)
describe('Create AppStream URL', () => {
it('should return AppStream URL SageMaker', async () => {
const envId = '36f22de5-fefb-4f62-8ab4-e99ac4387ad4';
const connectionId = 'id-0';
const applicationName = 'Firefox';
const sagemakerUrlPrefix = 'https://basicnotebookinstance';
const preAuthStreamingUrl = 'https://appstream2.us-east-1.aws.amazon.com/authenticate?parameters=';
const redirectStreamingUrl = `appstream2.us-east-1.aws.amazon.com/#/streaming/?reference=fleet%2Finitial-stack-1629237287942-ServiceWorkbenchFleet&app=${applicationName}`;

const retVal = await adminSession.resources.workspaceServiceCatalogs
SanketD92 marked this conversation as resolved.
Show resolved Hide resolved
.workspaceServiceCatalog(envId)
.connections()
.connection(connectionId)
.createUrl();

const response = await fetch(retVal.url);
const redirectResponse = response[Object.getOwnPropertySymbols(response)[1]];
SanketD92 marked this conversation as resolved.
Show resolved Hide resolved

expect(retVal.appstreamDestinationUrl).toContain(sagemakerUrlPrefix);
expect(retVal.id).toEqual(connectionId);
expect(retVal.url).toContain(preAuthStreamingUrl);
expect(redirectResponse.url).toContain(redirectStreamingUrl);
});

// Simplify repetitive Jest test cases with it.each here
const testContexts = [
[
'Windows',
{
envId: '5360d995-fa4b-44eb-b67d-a0586886e1a3',
connectionId: 'id-1',
applicationName: 'MicrosoftRemoteDesktop',
preAuthStreamingUrl: 'https://appstream2.us-east-1.aws.amazon.com/authenticate?parameters=',
redirectStreamingUrl:
'appstream2.us-east-1.aws.amazon.com/#/streaming/?reference=fleet%2Finitial-stack-1629237287942-ServiceWorkbenchFleet&app=',
expected: { scheme: 'rdp', name: 'RDP to EC2 Windows Instance' },
},
],
[
'EC2 Linux',
{
envId: '4ceb23c8-c80c-4ded-b948-c63b21ba5c72',
connectionId: 'id-1',
applicationName: 'EC2Linux',
preAuthStreamingUrl: 'https://appstream2.us-east-1.aws.amazon.com/authenticate?parameters=',
redirectStreamingUrl:
'appstream2.us-east-1.aws.amazon.com/#/streaming/?reference=fleet%2Finitial-stack-1629237287942-ServiceWorkbenchFleet&app=',
expected: { scheme: 'ssh', name: 'SSH to Main EC2 instance' },
},
],
];

it.each(testContexts)('should return AppStream URL %s', async (_, testContext) => {
SanketD92 marked this conversation as resolved.
Show resolved Hide resolved
const retVal = await adminSession.resources.workspaceServiceCatalogs
.workspaceServiceCatalog(testContext.envId)
.connections()
.connection(testContext.connectionId)
.createUrl();

const response = await fetch(retVal.url);
const redirectResponse = response[Object.getOwnPropertySymbols(response)[1]];

expect(retVal.scheme).toContain(testContext.expected.scheme);
SanketD92 marked this conversation as resolved.
Show resolved Hide resolved
expect(retVal.name).toContain(testContext.expected.name);
expect(retVal.id).toEqual(testContext.connectionId);
expect(retVal.url).toContain(testContext.preAuthStreamingUrl);
expect(redirectResponse.url).toContain(`${testContext.redirectStreamingUrl}${testContext.applicationName}`);
});
});
});
1 change: 1 addition & 0 deletions main/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.2",
"husky": "^3.1.0",
"node-fetch": "^2.6.0",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"jest-junit": "^10.0.0",
Expand Down
Loading