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

feat(sns): add validation of displayName for topic #30770

Merged
merged 6 commits into from
Jul 29, 2024
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
4 changes: 4 additions & 0 deletions packages/aws-cdk-lib/aws-sns/lib/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ export class Topic extends TopicBase {
throw new Error(`signatureVersion must be "1" or "2", received: "${props.signatureVersion}"`);
}

if (props.displayName && !Token.isUnresolved(props.displayName) && props.displayName.length > 100) {
throw new Error(`displayName must be less than or equal to 100 characters, got ${props.displayName.length}`);
}

const resource = new CfnTopic(this, 'Resource', {
archivePolicy: props.messageRetentionPeriodInDays ? {
MessageRetentionPeriod: props.messageRetentionPeriodInDays,
Expand Down
10 changes: 10 additions & 0 deletions packages/aws-cdk-lib/aws-sns/test/sns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ describe('Topic', () => {
signatureVersion: '3',
})).toThrow(/signatureVersion must be "1" or "2", received: "3"/);
});

test('throw error when displayName is too long', () => {
const stack = new cdk.Stack();

expect(() => {
new sns.Topic(stack, 'MyTopic', {
displayName: 'a'.repeat(101),
});
}).toThrow('displayName must be less than or equal to 100 characters, got 101');
});
});

test('can add a policy to the topic', () => {
Expand Down
Loading