Skip to content

Commit 539ff2a

Browse files
committed
fix unit tests for annotations with tokens
1 parent 766a431 commit 539ff2a

File tree

4 files changed

+14
-37
lines changed

4 files changed

+14
-37
lines changed

packages/aws-cdk-lib/aws-events-targets/test/lambda/lambda.test.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,9 @@ test('must display a warning when using a Dead Letter Queue from another account
320320

321321
Template.fromStack(stack1).resourceCountIs('AWS::SQS::QueuePolicy', 0);
322322

323-
Annotations.fromStack(stack1).hasWarning('/Stack1/Rule', Match.objectLike({
324-
'Fn::Join': Match.arrayWith([
325-
Match.arrayWith([
326-
'Cannot add a resource policy to your dead letter queue associated with rule ',
327-
]),
328-
]),
329-
}));
323+
Annotations.fromStack(stack1).hasWarning('/Stack1/Rule', Match.stringLikeRegexp(
324+
'Cannot add a resource policy to your dead letter queue associated with rule \\${Token\\[TOKEN\\.[0-9]+\\]} because the queue is in a different account\\. You must add the resource policy manually to the dead letter queue in account 444455556666\\. \\[ack: @aws-cdk/aws-events-targets:manuallyAddDLQResourcePolicy\\]',
325+
));
330326
});
331327

332328
test('specifying retry policy', () => {

packages/aws-cdk-lib/aws-lambda/test/function.test.ts

+1-16
Original file line numberDiff line numberDiff line change
@@ -254,22 +254,7 @@ describe('function', () => {
254254

255255
expect(getWarnings(app.synth())).toEqual([
256256
{
257-
message: {
258-
'Fn::Join': [
259-
'',
260-
[
261-
'addPermission() has no effect on a Lambda Function with region=us-west-2, account=123456789012, in a Stack with region=',
262-
{
263-
Ref: 'AWS::Region',
264-
},
265-
', account=',
266-
{
267-
Ref: 'AWS::AccountId',
268-
},
269-
'. Suppress this warning if this is is intentional, or pass sameEnvironment=true to fromFunctionAttributes() if you would like to add the permissions. [ack: UnclearLambdaEnvironment]',
270-
],
271-
],
272-
},
257+
message: expect.stringMatching(/^addPermission\(\) has no effect on a Lambda Function with region=us-west-2, account=123456789012, in a Stack with region=\${Token\[AWS\.Region\.\d+]}, account=\${Token\[AWS\.AccountId\.\d+]}. Suppress this warning if this is is intentional, or pass sameEnvironment=true to fromFunctionAttributes\(\) if you would like to add the permissions\. \[ack: UnclearLambdaEnvironment]$/),
273258
path: '/Default/Imported',
274259
},
275260
]);

packages/aws-cdk-lib/aws-s3-notifications/test/queue.test.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,7 @@ test('if the queue is encrypted with a imported kms key, printout warning', () =
109109

110110
bucket.addObjectCreatedNotification(new notif.SqsDestination(queue));
111111

112-
Annotations.fromStack(stack).hasWarning('/Default/ImportedKey', `Can not change key policy of imported kms key. Ensure that your key policy contains the following permissions: \n${JSON.stringify({
113-
Action: [
114-
'kms:GenerateDataKey*',
115-
'kms:Decrypt',
116-
],
117-
Effect: 'Allow',
118-
Principal: {
119-
Service: 's3.amazonaws.com',
120-
},
121-
Resource: '*',
122-
}, null, 2)} [ack: @aws-cdk/aws-s3-notifications:sqsKMSPermissionsNotAdded]`);
112+
Annotations.fromStack(stack).hasWarning('/Default/ImportedKey', Match.stringLikeRegexp(
113+
'Can not change key policy of imported kms key\\. Ensure that your key policy contains the following permissions: \\n\\{\\n "Action": \\[\\n "kms:GenerateDataKey\\*",\\n "kms:Decrypt"\\n \\],\\n "Effect": "Allow",\\n "Principal": \\{\\n "Service": "\\${Token\\[s3\\.amazonaws\\.com\\.[0-9]+\\]}"\\n \\},\\n "Resource": "\\*"\\n\\} \\[ack: @aws-cdk/aws-s3-notifications:sqsKMSPermissionsNotAdded\\]',
114+
));
123115
});

packages/aws-cdk-lib/aws-s3/test/notification.test.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,13 @@ describe('notification', () => {
162162
});
163163

164164
// THEN - Following is warning thrown as a part of fix in : https://github.com/aws/aws-cdk/pull/31212
165-
const warningMessage = { 'Fn::Join': ['', ["Can't combine imported IManagedPolicy: arn:", { Ref: 'AWS::Partition' }, ':iam::aws:policy/service-role/AWSLambdaBasicExecutionRole to imported role IRole: DevsNotAllowedToTouch. Use ManagedPolicy directly. [ack: @aws-cdk/aws-iam:IRoleCantBeUsedWithIManagedPolicy]']] };
166-
const warningFromStack = Annotations.fromStack(stack).findWarning('*', {});
167-
expect(warningFromStack[0].entry.data).toEqual(warningMessage);
165+
const warningMessage = /Can't combine imported IManagedPolicy: arn:\${Token\[AWS\.Partition\.\d+\]}:iam::aws:policy\/service-role\/AWSLambdaBasicExecutionRole to imported role IRole: DevsNotAllowedToTouch\. Use ManagedPolicy directly\. \[ack: @aws-cdk\/aws-iam:IRoleCantBeUsedWithIManagedPolicy\]/;
166+
const warningFromStack = Annotations.fromStack(stack).findWarning('*',
167+
Match.stringLikeRegexp(
168+
'@aws-cdk/aws-iam:IRoleCantBeUsedWithIManagedPolicy',
169+
),
170+
);
171+
expect(warningFromStack[0].entry.data).toEqual(expect.stringMatching(warningMessage));
168172
});
169173

170174
test('If `Role` is provided, PutBucketNotification, GetBucketNotification will be added along with `service-role/AWSLambdaBasicExecutionRole`', () => {

0 commit comments

Comments
 (0)