Skip to content

Commit

Permalink
Merge branch 'main' into bobertzh/apigwv2-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
HBobertz authored Jan 24, 2025
2 parents 00b66e6 + b1dfdd2 commit 0d29662
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import { shell, rimraf, addToShellPath } from '../shell';

export class ReleasePackageSourceSetup implements IPackageSourceSetup {
readonly name = 'release';
readonly description: string;
readonly description = `release @ ${this.version}`;

private tempDir?: string;

constructor(private readonly version: string, private readonly frameworkVersion?: string) {
this.description = `release @ ${this.version}`;
}

public async prepare(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { shell, addToShellPath } from '../shell';

export class RepoPackageSourceSetup implements IPackageSourceSetup {
readonly name = 'repo';
readonly description: string;
readonly description = `repo(${this.repoRoot})`;

constructor(private readonly repoRoot: string) {
this.description = `repo(${this.repoRoot})`;
}

public async prepare(): Promise<void> {
Expand Down
62 changes: 0 additions & 62 deletions packages/@aws-cdk-testing/cli-integ/lib/proxy.ts

This file was deleted.

32 changes: 8 additions & 24 deletions packages/@aws-cdk-testing/cli-integ/lib/with-cdk-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export interface CdkGarbageCollectionCommandOptions {
}

export class TestFixture extends ShellHelper {
public readonly qualifier: string;
public readonly qualifier = this.randomString.slice(0, 10);
private readonly bucketsToDelete = new Array<string>();
public readonly packages: IPackageSource;

Expand All @@ -334,7 +334,6 @@ export class TestFixture extends ShellHelper {

super(integTestDir, output);

this.qualifier = this.randomString.slice(0, 10);
this.packages = packageSourceInSubprocess();
}

Expand All @@ -343,22 +342,16 @@ export class TestFixture extends ShellHelper {
}

public async cdkDeploy(stackNames: string | string[], options: CdkCliOptions = {}, skipStackRename?: boolean) {
return this.cdk(this.cdkDeployCommandLine(stackNames, options, skipStackRename));
}

public cdkDeployCommandLine(stackNames: string | string[], options: CdkCliOptions = {}, skipStackRename?: boolean) {
stackNames = typeof stackNames === 'string' ? [stackNames] : stackNames;

const neverRequireApproval = options.neverRequireApproval ?? true;

return [
'deploy',
return this.cdk(['deploy',
...(neverRequireApproval ? ['--require-approval=never'] : []), // Default to no approval in an unattended test
...(options.options ?? []),
...(options.verbose ? ['-v'] : []),
// use events because bar renders bad in tests
'--progress', 'events',
...(skipStackRename ? stackNames : this.fullStackName(stackNames)),
];
...(skipStackRename ? stackNames : this.fullStackName(stackNames))], options);
}

public async cdkSynth(options: CdkCliOptions = {}) {
Expand Down Expand Up @@ -508,24 +501,15 @@ export class TestFixture extends ShellHelper {
return this.shell(['cdk', ...(verbose ? ['-v'] : []), ...args], {
...options,
modEnv: {
...this.cdkShellEnv(),
AWS_REGION: this.aws.region,
AWS_DEFAULT_REGION: this.aws.region,
STACK_NAME_PREFIX: this.stackNamePrefix,
PACKAGE_LAYOUT_VERSION: this.packages.majorVersion(),
...options.modEnv,
},
});
}

/**
* Return the environment variables with which to execute CDK
*/
public cdkShellEnv() {
return {
AWS_REGION: this.aws.region,
AWS_DEFAULT_REGION: this.aws.region,
STACK_NAME_PREFIX: this.stackNamePrefix,
PACKAGE_LAYOUT_VERSION: this.packages.majorVersion(),
};
}

public template(stackName: string): any {
const fullStackName = this.fullStackName(stackName);
const templatePath = path.join(this.integTestDir, 'cdk.out', `${fullStackName}.template.json`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { existsSync, promises as fs } from 'fs';
import * as querystring from 'node:querystring';
import * as os from 'os';
import * as path from 'path';
import {
Expand All @@ -22,6 +23,8 @@ import { InvokeCommand } from '@aws-sdk/client-lambda';
import { PutObjectLockConfigurationCommand } from '@aws-sdk/client-s3';
import { CreateTopicCommand, DeleteTopicCommand } from '@aws-sdk/client-sns';
import { AssumeRoleCommand, GetCallerIdentityCommand } from '@aws-sdk/client-sts';
import * as mockttp from 'mockttp';
import { CompletedRequest } from 'mockttp';
import {
cloneDirectory,
integTest,
Expand All @@ -38,7 +41,6 @@ import {
withSamIntegrationFixture,
withSpecificFixture,
} from '../../lib';
import { awsActionsFromRequests, startProxyServer } from '../../lib/proxy';

jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime

Expand Down Expand Up @@ -2875,29 +2877,60 @@ integTest('cdk notices are displayed correctly', withDefaultFixture(async (fixtu

integTest('requests go through a proxy when configured',
withDefaultFixture(async (fixture) => {
const proxyServer = await startProxyServer();
// Set up key and certificate
const { key, cert } = await mockttp.generateCACertificate();
const certDir = await fs.mkdtemp(path.join(os.tmpdir(), 'cdk-'));
const certPath = path.join(certDir, 'cert.pem');
const keyPath = path.join(certDir, 'key.pem');
await fs.writeFile(keyPath, key);
await fs.writeFile(certPath, cert);

const proxyServer = mockttp.getLocal({
https: { keyPath, certPath },
});

// We don't need to modify any request, so the proxy
// passes through all requests to the target host.
const endpoint = await proxyServer
.forAnyRequest()
.thenPassThrough();

proxyServer.enableDebug();
await proxyServer.start();

// The proxy is now ready to intercept requests

try {
await fixture.cdkDeploy('test-2', {
captureStderr: true,
options: [
'--proxy', proxyServer.url,
'--ca-bundle-path', proxyServer.certPath,
'--ca-bundle-path', certPath,
],
modEnv: {
CDK_HOME: fixture.integTestDir,
},
});

const requests = await proxyServer.getSeenRequests();

expect(requests.map(req => req.url))
.toContain('https://cli.cdk.dev-tools.aws.dev/notices.json');

const actionsUsed = awsActionsFromRequests(requests);
expect(actionsUsed).toContain('AssumeRole');
expect(actionsUsed).toContain('CreateChangeSet');
} finally {
await fs.rm(certDir, { recursive: true, force: true });
await proxyServer.stop();
}

const requests = await endpoint.getSeenRequests();

expect(requests.map(req => req.url))
.toContain('https://cli.cdk.dev-tools.aws.dev/notices.json');

const actionsUsed = actions(requests);
expect(actionsUsed).toContain('AssumeRole');
expect(actionsUsed).toContain('CreateChangeSet');
}),
);

function actions(requests: CompletedRequest[]): string[] {
return [...new Set(requests
.map(req => req.body.buffer.toString('utf-8'))
.map(body => querystring.decode(body))
.map(x => x.Action as string)
.filter(action => action != null))];
}

This file was deleted.

2 changes: 1 addition & 1 deletion packages/@aws-cdk-testing/cli-integ/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020", "dom"],
"lib": ["es2019", "es2020", "dom"],
"strict": true,
"alwaysStrict": true,
"declaration": true,
Expand Down
Loading

0 comments on commit 0d29662

Please sign in to comment.