S3: fix validation parity of `PutBucketNotificationConfiguration` by bentsku · Pull Request #13091 · localstack/localstack · GitHub
Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
67 changes: 36 additions & 31 deletions localstack-core/localstack/services/s3/notifications.py
23 changes: 10 additions & 13 deletions localstack-core/localstack/services/s3/presigned_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
)
from localstack.services.s3.utils import (
S3_VIRTUAL_HOST_FORWARDED_HEADER,
_create_invalid_argument_exc,
capitalize_header_name_from_snake_case,
extract_bucket_name_and_key_from_headers_and_path,
forwarded_from_virtual_host_addressed_request,
Expand Down Expand Up @@ -772,13 +771,12 @@ def validate_post_policy(
:return: None
"""
if not request_form.get("key"):
ex: InvalidArgument = _create_invalid_argument_exc(
message="Bucket POST must contain a field named 'key'. If it is specified, please check the order of the fields.",
name="key",
value="",
host_id=FAKE_HOST_ID,
raise InvalidArgument(
"Bucket POST must contain a field named 'key'. If it is specified, please check the order of the fields.",
ArgumentName="key",
ArgumentValue="",
HostId=FAKE_HOST_ID,
)
raise ex

form_dict = {k.lower(): v for k, v in request_form.items()}

Expand Down Expand Up @@ -932,13 +930,12 @@ def _is_match_with_signature_fields(
if argument_name == "Awsaccesskeyid":
argument_name = "AWSAccessKeyId"

ex: InvalidArgument = _create_invalid_argument_exc(
message=f"Bucket POST must contain a field named '{argument_name}'. If it is specified, please check the order of the fields.",
name=argument_name,
value="",
host_id=FAKE_HOST_ID,
raise InvalidArgument(
f"Bucket POST must contain a field named '{argument_name}'. If it is specified, please check the order of the fields.",
ArgumentName=argument_name,
ArgumentValue="",
HostId=FAKE_HOST_ID,
)
raise ex

return True
return False
11 changes: 0 additions & 11 deletions localstack-core/localstack/services/s3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,17 +574,6 @@ def get_bucket_and_key_from_presign_url(presign_url: str) -> tuple[str, str]:
return bucket, key


def _create_invalid_argument_exc(
message: str | None, name: str, value: str, host_id: str = None
) -> InvalidArgument:
ex = InvalidArgument(message)
ex.ArgumentName = name
ex.ArgumentValue = value
if host_id:
ex.HostId = host_id
return ex


def capitalize_header_name_from_snake_case(header_name: str) -> str:
return "-".join([part.capitalize() for part in header_name.split("-")])

Expand Down
78 changes: 46 additions & 32 deletions localstack-core/localstack/services/s3/validation.py
Loading
Loading