Skip to content

Commit 6c0f74e

Browse files
authored
fix(cli): assume role calls are skipping the proxy (#32291)
`STSClientConfig` and `NodeHttpHandlerOptions` are different types, but all have optional properties only. That means that a call like this: ```ts const credentials = await fromTemporaryCredentials({ masterCredentials: mainCredentials.credentials, params: { RoleArn: roleArn, ExternalId: externalId, RoleSessionName: `aws-cdk-${safeUsername()}`, ...additionalOptions, TransitiveTagKeys: additionalOptions?.Tags ? additionalOptions.Tags.map((t) => t.Key!) : undefined, }, clientConfig: { region, ...this.requestHandler, // type NodeHttpHandlerOptions }, })(); ``` compiles just fine, when the intention was to write: ```ts fromTemporaryCredentials({ ... clientConfig: { region, requestHandler: this.requestHandler, // type NodeHttpHandlerOptions }, }); ``` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent deeb2ad commit 6c0f74e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { existsSync, promises as fs } from 'fs';
2+
import * as querystring from 'node:querystring';
23
import * as os from 'os';
34
import * as path from 'path';
45
import {
@@ -23,6 +24,7 @@ import { PutObjectLockConfigurationCommand } from '@aws-sdk/client-s3';
2324
import { CreateTopicCommand, DeleteTopicCommand } from '@aws-sdk/client-sns';
2425
import { AssumeRoleCommand, GetCallerIdentityCommand } from '@aws-sdk/client-sts';
2526
import * as mockttp from 'mockttp';
27+
import { CompletedRequest } from 'mockttp';
2628
import {
2729
cloneDirectory,
2830
integTest,
@@ -2846,10 +2848,19 @@ integTest('requests go through a proxy when configured',
28462848
});
28472849
} finally {
28482850
await fs.rm(certDir, { recursive: true, force: true });
2851+
await proxyServer.stop();
28492852
}
28502853

2851-
// Checking that there was some interaction with the proxy
2852-
const requests = await endpoint.getSeenRequests();
2853-
expect(requests.length).toBeGreaterThan(0);
2854+
const actionsUsed = actions(await endpoint.getSeenRequests());
2855+
expect(actionsUsed).toContain('AssumeRole');
2856+
expect(actionsUsed).toContain('CreateChangeSet');
28542857
}),
28552858
);
2859+
2860+
function actions(requests: CompletedRequest[]): string[] {
2861+
return [...new Set(requests
2862+
.map(req => req.body.buffer.toString('utf-8'))
2863+
.map(body => querystring.decode(body))
2864+
.map(x => x.Action as string)
2865+
.filter(action => action != null))];
2866+
}

packages/aws-cdk/lib/api/aws-auth/sdk-provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ export class SdkProvider {
375375
},
376376
clientConfig: {
377377
region,
378-
...this.requestHandler,
378+
requestHandler: this.requestHandler,
379379
},
380380
})();
381381

0 commit comments

Comments
 (0)