Skip to content

Commit 36c12c9

Browse files
authored
chore(cli-integ): new test case for proxied requests (#32254)
This important scenario was missing from the integ test suite. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d1b07d9 commit 36c12c9

File tree

4 files changed

+746
-32
lines changed

4 files changed

+746
-32
lines changed

packages/@aws-cdk-testing/cli-integ/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"jest": "^29.7.0",
6060
"jest-junit": "^14.0.1",
6161
"make-runnable": "^1.4.1",
62+
"mockttp": "^3.15.4",
6263
"npm": "^8.19.4",
6364
"p-queue": "^6.6.2",
6465
"semver": "^7.6.3",

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

+53-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { promises as fs, existsSync } from 'fs';
1+
import { existsSync, promises as fs } from 'fs';
22
import * as os from 'os';
33
import * as path from 'path';
44
import {
@@ -22,21 +22,22 @@ import { InvokeCommand } from '@aws-sdk/client-lambda';
2222
import { PutObjectLockConfigurationCommand } from '@aws-sdk/client-s3';
2323
import { CreateTopicCommand, DeleteTopicCommand } from '@aws-sdk/client-sns';
2424
import { AssumeRoleCommand, GetCallerIdentityCommand } from '@aws-sdk/client-sts';
25+
import * as mockttp from 'mockttp';
2526
import {
26-
integTest,
2727
cloneDirectory,
28-
shell,
29-
withDefaultFixture,
30-
retry,
31-
sleep,
28+
integTest,
3229
randomInteger,
33-
withSamIntegrationFixture,
30+
randomString,
3431
RESOURCES_DIR,
32+
retry,
33+
shell,
34+
sleep,
3535
withCDKMigrateFixture,
36+
withDefaultFixture,
3637
withExtendedTimeoutFixture,
37-
randomString,
38-
withSpecificFixture,
3938
withoutBootstrap,
39+
withSamIntegrationFixture,
40+
withSpecificFixture,
4041
} from '../../lib';
4142

4243
jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime
@@ -2809,3 +2810,46 @@ integTest('cdk notices are displayed correctly', withDefaultFixture(async (fixtu
28092810
expect(output).toContain(`AffectedEnvironments:<aws://${await fixture.aws.account()}/${fixture.aws.region}>`);
28102811

28112812
}));
2813+
2814+
integTest('requests go through a proxy when configured',
2815+
withDefaultFixture(async (fixture) => {
2816+
// Set up key and certificate
2817+
const { key, cert } = await mockttp.generateCACertificate();
2818+
const certDir = await fs.mkdtemp(path.join(os.tmpdir(), 'cdk-'));
2819+
const certPath = path.join(certDir, 'cert.pem');
2820+
const keyPath = path.join(certDir, 'key.pem');
2821+
await fs.writeFile(keyPath, key);
2822+
await fs.writeFile(certPath, cert);
2823+
2824+
const proxyServer = mockttp.getLocal({
2825+
https: { keyPath, certPath },
2826+
});
2827+
2828+
// We don't need to modify any request, so the proxy
2829+
// passes through all requests to the host.
2830+
const endpoint = await proxyServer
2831+
.forAnyRequest()
2832+
.thenPassThrough();
2833+
2834+
proxyServer.enableDebug();
2835+
await proxyServer.start();
2836+
2837+
// The proxy is now ready to intercept requests
2838+
2839+
try {
2840+
await fixture.cdkDeploy('test-2', {
2841+
captureStderr: true,
2842+
options: [
2843+
'--proxy', proxyServer.url,
2844+
'--ca-bundle-path', certPath,
2845+
],
2846+
});
2847+
} finally {
2848+
await fs.rm(certDir, { recursive: true, force: true });
2849+
}
2850+
2851+
// Checking that there was some interaction with the proxy
2852+
const requests = await endpoint.getSeenRequests();
2853+
expect(requests.length).toBeGreaterThan(0);
2854+
}),
2855+
);

packages/aws-cdk/lib/api/aws-auth/awscli-compatible.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function getRegionFromIniFile(profile: string, data?: any) {
179179
function tryGetCACert(bundlePath?: string) {
180180
const path = bundlePath || caBundlePathFromEnvironment();
181181
if (path) {
182-
debug('Using CA bundle path: %s', bundlePath);
182+
debug('Using CA bundle path: %s', path);
183183
return readIfPossible(path);
184184
}
185185
return undefined;

0 commit comments

Comments
 (0)