Skip to content

Commit

Permalink
chore(stepfunction-tasks): eventbridge aws. event source prefix check…
Browse files Browse the repository at this point in the history
… is more strict than it should be (#30237)

1. fix the event source validation
2. move the validation from renderEntries() to validateEntries() 
3. add unit tests

### Issue # (if applicable)

Closes #30191

### Reason for this change



### Description of changes



### Description of how you validated changes



### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
pahud authored Jun 6, 2024
1 parent 516ecef commit 8f4d4d7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,23 @@ export class EventBridgePutEvents extends sfn.TaskStateBase {
}

private renderEntries(): Object[] {
// we should have validated all entries in validateEntries()
return this.props.entries.map(entry => {
if (entry.source?.startsWith('aws')) {
throw new Error('Event source cannot start with "aws."');
} else {
return {
Detail: entry.detail?.value,
DetailType: entry.detailType,
EventBusName: entry.eventBus?.eventBusArn,
Source: entry.source,
};
}
return {
Detail: entry.detail?.value,
DetailType: entry.detailType,
EventBusName: entry.eventBus?.eventBusArn,
Source: entry.source,
};
});
}

private validateEntries(): void {
if (this.props.entries.length <= 0) {
throw new Error('Value for property `entries` must be a non-empty array.');
}
if (this.props.entries.some(e => e.source.startsWith('aws.'))) {
throw new Error('Event source cannot start with "aws."');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,30 @@ describe('Put Events', () => {
}).toThrowError('Unsupported service integration pattern');
});

test('event source cannot start with "aws."', () => {
expect(() => {
new EventBridgePutEvents(stack, 'PutEvents', {
entries: [{
detail: sfn.TaskInput.fromText('MyDetail'),
detailType: 'MyDetailType',
source: 'aws.source',
}],
});
}).toThrow(/Event source cannot start with "aws."/);
});

test('event source can start with "aws" without trailing dot', () => {
expect(() => {
new EventBridgePutEvents(stack, 'PutEvents', {
entries: [{
detail: sfn.TaskInput.fromText('MyDetail'),
detailType: 'MyDetailType',
source: 'awssource',
}],
});
}).not.toThrow(/Event source cannot start with "aws."/);
});

test('provided EventBus', () => {
// GIVEN
const eventBus = new events.EventBus(stack, 'EventBus');
Expand Down

0 comments on commit 8f4d4d7

Please sign in to comment.