Skip to content

Commit

Permalink
mid work
Browse files Browse the repository at this point in the history
  • Loading branch information
iliapolo committed Aug 31, 2024
1 parent bb4f087 commit 911260e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class DefaultAwsClient implements IAws {
RoleArn: roleArn,
ExternalId: externalId,
RoleSessionName: `cdk-assets-${safeUsername()}`,
// ...(additionalOptions ?? {}),
...(additionalOptions ?? {}),
},
stsConfig: {
region,
Expand Down
41 changes: 30 additions & 11 deletions test/aws.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import * as os from 'os';
import { DefaultAwsClient } from '../lib';

afterEach(() => {
jest.requireActual('aws-sdk');
});

beforeEach(() => {
jest.requireActual('aws-sdk');
});
Expand Down Expand Up @@ -60,7 +56,7 @@ test('assumeRole passes the right parameters to STS', async () => {

test('assumeRole defaults session tags to all', async () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('aws-sdk');
const AWS = require('aws-sdk');

jest.mock('aws-sdk', () => {
return {
Expand All @@ -75,13 +71,36 @@ test('assumeRole defaults session tags to all', async () => {
ChainableTemporaryCredentials: jest.fn(),
};
});

const aws = new DefaultAwsClient();

const account = await aws.discoverTargetAccount({});
expect(account).toEqual({
accountId: '123456789012',
partition: 'aws',
await withMocked(os, 'userInfo', async (userInfo) => {
userInfo.mockReturnValue({
username: 'foo',
uid: 1,
gid: 1,
homedir: '/here',
shell: '/bin/sh',
});
await aws.discoverTargetAccount({
region: 'us-east-1',
assumeRoleArn: 'arn:aws:iam::123456789012:role/my-role',
assumeRoleExternalId: 'external-id',
assumeRoleAdditionalOptions: {
Tags: [{ Key: 'Departement', Value: 'Engineering' }],
},
});
expect(AWS.ChainableTemporaryCredentials).toHaveBeenCalledWith({
params: {
ExternalId: 'external-id',
RoleArn: 'arn:aws:iam::123456789012:role/my-role',
Tags: [{ Key: 'Departement', Value: 'Engineering' }],
TransitiveTagKeys: ['Departement'],
RoleSessionName: `cdk-assets-foo`,
},
stsConfig: {
customUserAgent: 'cdk-assets',
region: 'us-east-1',
},
});
});
});

Expand Down

0 comments on commit 911260e

Please sign in to comment.