Skip to content

Commit 22fd338

Browse files
Reject events larger than the max size allowed (#11623)
Co-authored-by: maxhoheiser <max.hoheiser@gmail.com>
1 parent 0ae976e commit 22fd338

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

localstack-core/localstack/services/events/provider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ def validate_event(event: PutEventsRequestEntry) -> None | PutEventsResultEntry:
197197
"ErrorCode": "InvalidArgument",
198198
"ErrorMessage": "Parameter Detail is not valid. Reason: Detail is a required argument.",
199199
}
200+
elif event.get("Detail") and len(event["Detail"]) >= 262144:
201+
raise ValidationException("Total size of the entries in the request is over the limit.")
200202

201203

202204
def check_unique_tags(tags: TagsList) -> None:

tests/aws/services/events/test_events.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ def test_put_event_without_detail(self, snapshot, aws_client):
118118
response = aws_client.events.put_events(Entries=entries)
119119
snapshot.match("put-events", response)
120120

121+
@markers.aws.validated
122+
@pytest.mark.skipif(
123+
is_old_provider(),
124+
reason="V1 provider does not support this feature",
125+
)
126+
def test_put_event_with_too_big_detail(self, snapshot, aws_client):
127+
entries = [
128+
{
129+
"Source": TEST_EVENT_PATTERN_NO_DETAIL["source"][0],
130+
"DetailType": TEST_EVENT_PATTERN_NO_DETAIL["detail-type"][0],
131+
"Detail": json.dumps({"payload": ["p" * (256 * 1024 - 17)]}),
132+
},
133+
]
134+
135+
with pytest.raises(ClientError) as e:
136+
aws_client.events.put_events(Entries=entries)
137+
snapshot.match("put-events-too-big-detail-error", e.value.response)
138+
121139
@markers.aws.validated
122140
@pytest.mark.skipif(
123141
is_old_provider(),

tests/aws/services/events/test_events.snapshot.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,21 @@
17541754
]
17551755
}
17561756
},
1757-
"tests/aws/services/events/test_events.py::TestEvents::test_create_connection_validations": {
1757+
"tests/aws/services/events/test_events.py::TestEvents::test_put_event_with_too_big_detail": {
1758+
"recorded-date": "18-10-2024, 07:36:18",
1759+
"recorded-content": {
1760+
"put-events-too-big-detail-error": {
1761+
"Error": {
1762+
"Code": "ValidationException",
1763+
"Message": "Total size of the entries in the request is over the limit."},
1764+
"ResponseMetadata": {
1765+
"HTTPHeaders": {},
1766+
"HTTPStatusCode": 400
1767+
}
1768+
}
1769+
}
1770+
},
1771+
"tests/aws/services/events/test_events.py::TestEvents::test_create_connection_validations": {
17581772
"recorded-date": "14-11-2024, 20:29:49",
17591773
"recorded-content": {
17601774
"create_connection_exc": {

tests/aws/services/events/test_events.validation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
164164
"tests/aws/services/events/test_events.py::TestEvents::test_create_connection_validations": {
165165
"last_validated_date": "2024-11-14T20:29:49+00:00"
166166
},
167+
"tests/aws/services/events/test_events.py::TestEvents::test_put_event_with_too_big_detail": {
168+
"last_validated_date": "2024-10-18T07:36:18+00:00"
169+
},
167170
"tests/aws/services/events/test_events.py::TestEvents::test_put_event_without_detail": {
168171
"last_validated_date": "2024-06-19T10:40:51+00:00"
169172
},

0 commit comments

Comments
 (0)