From 99fa0919f67dcc07f9cdb938865804f673327418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Wed, 2 Oct 2024 09:47:33 +0200 Subject: [PATCH 1/7] Reject events larger than the max size allowed --- .../localstack/services/events/provider.py | 5 +++++ .../events/test_archive_and_replay.py | 1 + tests/aws/services/events/test_events.py | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/localstack-core/localstack/services/events/provider.py b/localstack-core/localstack/services/events/provider.py index 3f3aaf14739fd..633a7f1b14db0 100644 --- a/localstack-core/localstack/services/events/provider.py +++ b/localstack-core/localstack/services/events/provider.py @@ -171,6 +171,11 @@ def validate_event(event: PutEventsRequestEntry) -> None | PutEventsResultEntry: "ErrorCode": "InvalidArgument", "ErrorMessage": "Parameter Detail is not valid. Reason: Detail is a required argument.", } + elif event.get("Detail") and len(event["Detail"]) >= 262144: + return { + "ErrorCode": "InvalidArgument", + "ErrorMessage": "Parameter Detail is not valid. Reason: Detail length is too long. Max 262144 bytes.", + } def check_unique_tags(tags: TagsList) -> None: diff --git a/tests/aws/services/events/test_archive_and_replay.py b/tests/aws/services/events/test_archive_and_replay.py index 9526f31233528..143d0c2d06624 100644 --- a/tests/aws/services/events/test_archive_and_replay.py +++ b/tests/aws/services/events/test_archive_and_replay.py @@ -15,6 +15,7 @@ EVENT_DETAIL, TEST_EVENT_PATTERN, TEST_EVENT_PATTERN_NO_DETAIL, + ) diff --git a/tests/aws/services/events/test_events.py b/tests/aws/services/events/test_events.py index e5032a4d48de3..fb237772abc76 100644 --- a/tests/aws/services/events/test_events.py +++ b/tests/aws/services/events/test_events.py @@ -42,6 +42,11 @@ "source": ["core.update-account-command"], "detail-type": ["core.update-account-command"], } +TEST_EVENT_PATTERN_DETAIL_TOO_BIG = { + "source": ["core.update-account-command"], + "detail-type": ["core.update-account-command"], + "detail": {"payload": ["p"*(256*1024-17)]} +} TEST_EVENT_PATTERN_NO_SOURCE = { "detail-type": ["core.update-account-command"], @@ -116,6 +121,22 @@ def test_put_event_without_detail(self, snapshot, aws_client): response = aws_client.events.put_events(Entries=entries) snapshot.match("put-events", response) + @markers.aws.validated + @pytest.mark.skipif( + is_old_provider(), + reason="V1 provider does not support this feature", + ) + def test_put_event_with_too_big_detail(self, snapshot, aws_client): + entries = [ + { + "Source": TEST_EVENT_PATTERN_DETAIL_TOO_BIG["source"][0], + "DetailType": TEST_EVENT_PATTERN_DETAIL_TOO_BIG["detail-type"][0], + "Detail": TEST_EVENT_PATTERN_DETAIL_TOO_BIG["detail"][0], + }, + ] + response = aws_client.events.put_events(Entries=entries) + snapshot.match("put-events", response) + @markers.aws.validated def test_put_events_time(self, put_events_with_filter_to_sqs, snapshot): entries1 = [ From e413de5a598053b7fad31eaa6c9f63b9cb523e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Wed, 2 Oct 2024 09:52:58 +0200 Subject: [PATCH 2/7] reformated files --- tests/aws/services/events/test_archive_and_replay.py | 1 - tests/aws/services/events/test_events.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/aws/services/events/test_archive_and_replay.py b/tests/aws/services/events/test_archive_and_replay.py index 143d0c2d06624..9526f31233528 100644 --- a/tests/aws/services/events/test_archive_and_replay.py +++ b/tests/aws/services/events/test_archive_and_replay.py @@ -15,7 +15,6 @@ EVENT_DETAIL, TEST_EVENT_PATTERN, TEST_EVENT_PATTERN_NO_DETAIL, - ) diff --git a/tests/aws/services/events/test_events.py b/tests/aws/services/events/test_events.py index fb237772abc76..8007bc88829b5 100644 --- a/tests/aws/services/events/test_events.py +++ b/tests/aws/services/events/test_events.py @@ -45,7 +45,7 @@ TEST_EVENT_PATTERN_DETAIL_TOO_BIG = { "source": ["core.update-account-command"], "detail-type": ["core.update-account-command"], - "detail": {"payload": ["p"*(256*1024-17)]} + "detail": {"payload": ["p" * (256 * 1024 - 17)]}, } TEST_EVENT_PATTERN_NO_SOURCE = { From ddce04c90dedb21cf743294e0318a174b4127f8f Mon Sep 17 00:00:00 2001 From: maxhoheiser Date: Fri, 18 Oct 2024 09:36:46 +0200 Subject: [PATCH 3/7] feat: fix test too big --- tests/aws/services/events/test_events.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/aws/services/events/test_events.py b/tests/aws/services/events/test_events.py index 8007bc88829b5..54b9e970e5f4a 100644 --- a/tests/aws/services/events/test_events.py +++ b/tests/aws/services/events/test_events.py @@ -42,11 +42,6 @@ "source": ["core.update-account-command"], "detail-type": ["core.update-account-command"], } -TEST_EVENT_PATTERN_DETAIL_TOO_BIG = { - "source": ["core.update-account-command"], - "detail-type": ["core.update-account-command"], - "detail": {"payload": ["p" * (256 * 1024 - 17)]}, -} TEST_EVENT_PATTERN_NO_SOURCE = { "detail-type": ["core.update-account-command"], @@ -129,13 +124,15 @@ def test_put_event_without_detail(self, snapshot, aws_client): def test_put_event_with_too_big_detail(self, snapshot, aws_client): entries = [ { - "Source": TEST_EVENT_PATTERN_DETAIL_TOO_BIG["source"][0], - "DetailType": TEST_EVENT_PATTERN_DETAIL_TOO_BIG["detail-type"][0], - "Detail": TEST_EVENT_PATTERN_DETAIL_TOO_BIG["detail"][0], + "Source": TEST_EVENT_PATTERN_NO_DETAIL["source"][0], + "DetailType": TEST_EVENT_PATTERN_NO_DETAIL["detail-type"][0], + "Detail": json.dumps({"payload": ["p" * (256 * 1024 - 17)]}), }, ] - response = aws_client.events.put_events(Entries=entries) - snapshot.match("put-events", response) + + with pytest.raises(ClientError) as e: + aws_client.events.put_events(Entries=entries) + snapshot.match("put-events-too-big-detail-error", e.value.response) @markers.aws.validated def test_put_events_time(self, put_events_with_filter_to_sqs, snapshot): From bedf6e57393143af2b3a4378fd970d499ee63885 Mon Sep 17 00:00:00 2001 From: maxhoheiser Date: Fri, 18 Oct 2024 09:37:05 +0200 Subject: [PATCH 4/7] feat: add snapshots --- .../aws/services/events/test_events.snapshot.json | 15 +++++++++++++++ .../services/events/test_events.validation.json | 3 +++ 2 files changed, 18 insertions(+) diff --git a/tests/aws/services/events/test_events.snapshot.json b/tests/aws/services/events/test_events.snapshot.json index 436e8332d2fe5..bc9d3927a8304 100644 --- a/tests/aws/services/events/test_events.snapshot.json +++ b/tests/aws/services/events/test_events.snapshot.json @@ -1753,5 +1753,20 @@ } ] } + }, + "tests/aws/services/events/test_events.py::TestEvents::test_put_event_with_too_big_detail": { + "recorded-date": "18-10-2024, 07:36:18", + "recorded-content": { + "put-events-too-big-detail-error": { + "Error": { + "Code": "ValidationException", + "Message": "Total size of the entries in the request is over the limit." + }, + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 400 + } + } + } } } diff --git a/tests/aws/services/events/test_events.validation.json b/tests/aws/services/events/test_events.validation.json index 5a3d6c0efb76a..6312395bf8d86 100644 --- a/tests/aws/services/events/test_events.validation.json +++ b/tests/aws/services/events/test_events.validation.json @@ -113,6 +113,9 @@ "tests/aws/services/events/test_events.py::TestEvents::test_create_connection_validations": { "last_validated_date": "2024-06-19T10:41:01+00:00" }, + "tests/aws/services/events/test_events.py::TestEvents::test_put_event_with_too_big_detail": { + "last_validated_date": "2024-10-18T07:36:18+00:00" + }, "tests/aws/services/events/test_events.py::TestEvents::test_put_event_without_detail": { "last_validated_date": "2024-06-19T10:40:51+00:00" }, From 8168879bfe8c003caebf0f3d2e4050946dd4b0a8 Mon Sep 17 00:00:00 2001 From: maxhoheiser Date: Fri, 18 Oct 2024 09:40:41 +0200 Subject: [PATCH 5/7] feat: fix validation detail too big --- localstack-core/localstack/services/events/provider.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/localstack-core/localstack/services/events/provider.py b/localstack-core/localstack/services/events/provider.py index 633a7f1b14db0..56a582f3cbef5 100644 --- a/localstack-core/localstack/services/events/provider.py +++ b/localstack-core/localstack/services/events/provider.py @@ -172,10 +172,7 @@ def validate_event(event: PutEventsRequestEntry) -> None | PutEventsResultEntry: "ErrorMessage": "Parameter Detail is not valid. Reason: Detail is a required argument.", } elif event.get("Detail") and len(event["Detail"]) >= 262144: - return { - "ErrorCode": "InvalidArgument", - "ErrorMessage": "Parameter Detail is not valid. Reason: Detail length is too long. Max 262144 bytes.", - } + raise ValidationException("Total size of the entries in the request is over the limit.") def check_unique_tags(tags: TagsList) -> None: From f3c1bacd4e736a58a2e1a6c58ebb87650577a857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Wed, 20 Nov 2024 16:58:07 +0100 Subject: [PATCH 6/7] added the event again after dropping it in the merge --- .../aws/services/events/test_events.snapshot.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/aws/services/events/test_events.snapshot.json b/tests/aws/services/events/test_events.snapshot.json index 8a72b66b4f7a3..bc2852385bd88 100644 --- a/tests/aws/services/events/test_events.snapshot.json +++ b/tests/aws/services/events/test_events.snapshot.json @@ -1754,6 +1754,21 @@ ] } }, + "tests/aws/services/events/test_events.py::TestEvents::test_put_event_with_too_big_detail": { + "recorded-date": "18-10-2024, 07:36:18", + "recorded-content": { + "put-events-too-big-detail-error": { + "Error": { + "Code": "ValidationException", + "Message": "Total size of the entries in the request is over the limit." + }, + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 400 + } + } + } + }, "tests/aws/services/events/test_events.py::TestEventBridgeConnections::test_create_connection": { "recorded-date": "12-11-2024, 16:49:40", "recorded-content": { From d8c31953c8bff503c31b7ce8b7a93031bc181636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Wed, 20 Nov 2024 17:02:07 +0100 Subject: [PATCH 7/7] fixed lint --- tests/aws/services/events/test_events.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/aws/services/events/test_events.py b/tests/aws/services/events/test_events.py index d22d555d3b27c..937277e033bda 100644 --- a/tests/aws/services/events/test_events.py +++ b/tests/aws/services/events/test_events.py @@ -134,6 +134,7 @@ def test_put_event_with_too_big_detail(self, snapshot, aws_client): with pytest.raises(ClientError) as e: aws_client.events.put_events(Entries=entries) snapshot.match("put-events-too-big-detail-error", e.value.response) + @markers.aws.validated @pytest.mark.skipif( is_old_provider(),