Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
fix: use principal.username (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
maghirardelli authored Oct 16, 2023
1 parent de56ffc commit e21163f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('VPCE Policy Service', () => {
let awsAccountsService;
let aws;
let awsCfnService;
const requestContext = { principalIdentifier: { username: 'sampleUsername' } };
const requestContext = { principal: { username: 'sampleUsername' } };
const studyEntity = { id: 'sampleBYOBstudyId' };
const projectId = 'sampleProjectId';
const awsAccountId = 'sampleAwsAccountId';
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('VPCE Policy Service', () => {
// CHECK
expect(mockAssumeRole).toHaveBeenCalledWith({
RoleArn: roleArn,
RoleSessionName: `RaaS-${requestContext.principalIdentifier.username}`,
RoleSessionName: `RaaS-${requestContext.principal.username}`,
ExternalId: externalId,
});
});
Expand All @@ -157,7 +157,7 @@ describe('VPCE Policy Service', () => {
studyService.mustFind = jest.fn().mockReturnValue(projectId);
projectService.getAccountForProjectId = jest.fn().mockReturnValue(awsAccountId);
awsAccountsService.mustFind = jest.fn().mockReturnValue({ roleArn, externalId });
requestContext.principalIdentifier.username = undefined;
requestContext.principal.username = undefined;

// OPERATE n CHECK
await expect(service.getEc2ServiceForStudy(requestContext, studyEntity)).rejects.toThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class VpcePolicyService extends Service {
});

const sts = new this.aws.sdk.STS();
if (!requestContext.principalIdentifier.username) {
if (!requestContext.principal.username) {
throw new Error('Username is required');
}
const {
Credentials: { AccessKeyId: accessKeyId, SecretAccessKey: secretAccessKey, SessionToken: sessionToken },
} = await sts
.assumeRole({
RoleArn,
RoleSessionName: `RaaS-${requestContext.principalIdentifier.username}`,
RoleSessionName: `RaaS-${requestContext.principal.username}`,
ExternalId,
})
.promise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class StartEc2EnvironmentSc extends StepBase {
} = await sts
.assumeRole({
RoleArn,
RoleSessionName: `RaaS-${requestContext.principalIdentifier.username}`,
RoleSessionName: `RaaS-${requestContext.principal.username}`,
ExternalId,
})
.promise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class StartRStudioEnvironmentSc extends StepBase {
} = await sts
.assumeRole({
RoleArn,
RoleSessionName: `RaaS-${requestContext.principalIdentifier.username}`,
RoleSessionName: `RaaS-${requestContext.principal.username}`,
ExternalId,
})
.promise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class StartSagemakerEnvironmentSc extends StepBase {
} = await sts
.assumeRole({
RoleArn,
RoleSessionName: `RaaS-${requestContext.principalIdentifier.username}`,
RoleSessionName: `RaaS-${requestContext.principal.username}`,
ExternalId,
})
.promise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class StopEc2EnvironmentSc extends StepBase {
} = await sts
.assumeRole({
RoleArn,
RoleSessionName: `RaaS-${requestContext.principalIdentifier.username}`,
RoleSessionName: `RaaS-${requestContext.principal.username}`,
ExternalId,
})
.promise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class StopSagemakerEnvironmentSc extends StepBase {
} = await sts
.assumeRole({
RoleArn,
RoleSessionName: `RaaS-${requestContext.principalIdentifier.username}`,
RoleSessionName: `RaaS-${requestContext.principal.username}`,
ExternalId,
})
.promise();
Expand Down

0 comments on commit e21163f

Please sign in to comment.