Skip to content

Commit

Permalink
adding assertion of integ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shikha372 committed Jan 29, 2025
1 parent 8fcf6c4 commit 7041843
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ const requestorStack = new RequestorStack(app, 'requestor-stack', {

new IntegTest(app, 'VpcpcCrossAccountInteg', {
testCases: [acceptorStack, requestorStack],
});
});
47 changes: 0 additions & 47 deletions packages/@aws-cdk/aws-ec2-alpha/test/integ.vpc-peering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@ import * as cdk from 'aws-cdk-lib';

const app = new cdk.App();

/**
* Instructions to run this test
* 1. Replace requestor account with a valid requestor account id.
* 2. Replace acceptor account with a valid acceptor account id.
* 3. Replace the policyName to the new policy name created in acceptor account after first deployment.
* 4. Replace vpcId under encoded policy to id of acceptor VPC once deployed in account.
* 5. Run the test using `yarn integ integ.vpc-peerings.js`
*/

const requestorAccount = process.env.CDK_INTEG_ACCOUNT || '123456789012';
const acceptorAccount = process.env.CDK_INTEG_CROSS_ACCOUNT || '234567890123';
const policyName = 'acceptorVpcVpcPeeringRoleDefaultPolicyE79C72D0'; // Replace policy name

const stack = new cdk.Stack(app, 'VpcPeeringSameAccountIntegStack');

const acceptorVpc = new vpc_v2.VpcV2(stack, 'acceptorVpc', {
Expand All @@ -32,9 +19,6 @@ const connection = requestorVpc.createPeeringConnection('sameAccountPeering', {
acceptorVpc: acceptorVpc,
});

// Required only for cross-account peering connection, added here for assertion on policy
const peeringRole = acceptorVpc.createAcceptorVpcRole(requestorAccount);

const integ = new IntegTest(app, 'VpcSameAccountInteg', {
testCases: [stack],
});
Expand All @@ -55,34 +39,3 @@ peeringAssertion.expect(ExpectedResult.objectLike({
]),
}));

const policyAssertion = integ.assertions.awsApiCall('IAM', 'GetRolePolicyCommand', {
RoleName: peeringRole.roleName,
PolicyName: policyName,
});

const encodedPolicy = encodeURIComponent(JSON.stringify({
Version: '2012-10-17',
Statement: [
{
Action: 'ec2:AcceptVpcPeeringConnection',
Resource: `arn:aws:ec2:eu-west-2:${acceptorAccount}:vpc/vpc-067bee2f1080d0e83`, // Replace VPC id here
Effect: 'Allow',
},
{
Condition: {
StringEquals: {
'ec2:AccepterVpc': `arn:aws:ec2:eu-west-2:${acceptorAccount}:vpc/vpc-067bee2f1080d0e83`, // Replace VPC id here
},
},
Action: 'ec2:AcceptVpcPeeringConnection',
Resource: `arn:aws:ec2:eu-west-2:${acceptorAccount}:vpc-peering-connection/*`,
Effect: 'Allow',
},
],
},
)).replace(/%2F\*/g, '%2F%2A'); // Needed to replace /* in the policy which is encoded as '%2F%2A' in API response of `GetRolePolicyCommand` policy document.

policyAssertion.expect(ExpectedResult.objectLike({
PolicyDocument: encodedPolicy,
}));

0 comments on commit 7041843

Please sign in to comment.