Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(pipelines): fix integration tests #19723

Merged
merged 3 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
730 changes: 678 additions & 52 deletions packages/@aws-cdk/pipelines/test/integ.pipeline-security.expected.json

Large diffs are not rendered by default.

32 changes: 12 additions & 20 deletions packages/@aws-cdk/pipelines/test/integ.pipeline-security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as codepipeline_actions from '@aws-cdk/aws-codepipeline-actions';
import * as iam from '@aws-cdk/aws-iam';
import * as s3 from '@aws-cdk/aws-s3';
import * as sns from '@aws-cdk/aws-sns';
import * as subscriptions from '@aws-cdk/aws-sns-subscriptions';
import { App, SecretValue, Stack, StackProps, Stage, StageProps } from '@aws-cdk/core';
import { App, RemovalPolicy, Stack, StackProps, Stage, StageProps } from '@aws-cdk/core';
import { Construct } from 'constructs';
import * as cdkp from '../lib';

class MyStage extends Stage {
constructor(scope: Construct, id: string, props?: StageProps) {
super(scope, id, props);
const stack = new Stack(this, 'MyStack', {
env: props?.env,
});
const topic = new sns.Topic(stack, 'Topic');
topic.grantPublish(new iam.AccountPrincipal(stack.account));
Expand All @@ -23,7 +23,6 @@ class MySafeStage extends Stage {
constructor(scope: Construct, id: string, props?: StageProps) {
super(scope, id, props);
const stack = new Stack(this, 'MySafeStack', {
env: props?.env,
});
new sns.Topic(stack, 'MySafeTopic');
}
Expand All @@ -36,18 +35,20 @@ export class TestCdkStack extends Stack {
// The code that defines your stack goes here
const sourceArtifact = new codepipeline.Artifact();
const cloudAssemblyArtifact = new codepipeline.Artifact('CloudAsm');
const sourceBucket = new s3.Bucket(this, 'SourceBucket', {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
});

const pipeline = new cdkp.CdkPipeline(this, 'TestPipeline', {
selfMutating: false,
pipelineName: 'TestPipeline',
cloudAssemblyArtifact,
sourceAction: new codepipeline_actions.GitHubSourceAction({
actionName: 'GitHub',
sourceAction: new codepipeline_actions.S3SourceAction({
bucket: sourceBucket,
output: sourceArtifact,
oauthToken: SecretValue.plainText('not-a-secret'),
owner: 'OWNER',
repo: 'REPO',
trigger: codepipeline_actions.GitHubTrigger.POLL,
bucketKey: 'key',
actionName: 'S3',
}),
synthAction: cdkp.SimpleSynthAction.standardYarnSynth({
sourceArtifact,
Expand All @@ -74,28 +75,21 @@ export class TestCdkStack extends Stack {
topic.addSubscription(new subscriptions.EmailSubscription('test@email.com'));

unattachedStage.addApplication(new MyStage(this, 'SingleStage', {
env: { account: this.account, region: this.region },
}), { confirmBroadeningPermissions: true, securityNotificationTopic: topic });

const stage1 = pipeline.addApplicationStage(new MyStage(this, 'PreProduction', {
env: { account: this.account, region: this.region },
}), { confirmBroadeningPermissions: true, securityNotificationTopic: topic });

stage1.addApplication(new MySafeStage(this, 'SafeProduction', {
env: { account: this.account, region: this.region },
}));

stage1.addApplication(new MySafeStage(this, 'DisableSecurityCheck', {
env: { account: this.account, region: this.region },
}), { confirmBroadeningPermissions: false });

const stage2 = pipeline.addApplicationStage(new MyStage(this, 'NoSecurityCheck', {
env: { account: this.account, region: this.region },
}));

stage2.addApplication(new MyStage(this, 'EnableSecurityCheck', {
env: { account: this.account, region: this.region },
}), { confirmBroadeningPermissions: true });
stage2.addApplication(new MyStage(this, 'EnableSecurityCheck', { }), { confirmBroadeningPermissions: true });
}
}

Expand All @@ -104,7 +98,5 @@ const app = new App({
'@aws-cdk/core:newStyleStackSynthesis': 'true',
},
});
new TestCdkStack(app, 'PipelineSecurityStack', {
env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
});
new TestCdkStack(app, 'PipelineSecurityStack');
app.synth();
Loading