8000 fix S3 checksum mode casing + SelectObjectContent signature (#8695) · codeperl/localstack@3c1c27d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c1c27d

Browse files
authored
fix S3 checksum mode casing + SelectObjectContent signature (localstack#8695)
1 parent 7f290f7 commit 3c1c27d

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

localstack/services/s3/provider.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
DeleteObjectTaggingRequest,
4444
ETag,
4545
Expiration,
46+
Expression,
47+
ExpressionType,
4648
GetBucketAclOutput,
4749
GetBucketAnalyticsConfigurationOutput,
4850
GetBucketCorsOutput,
@@ -65,6 +67,7 @@
6567
GetObjectTaggingRequest,
6668
HeadObjectOutput,
6769
HeadObjectRequest,
70+
InputSerialization,
6871
IntelligentTieringConfiguration,
6972
IntelligentTieringConfigurationList,
7073
IntelligentTieringId,
@@ -95,6 +98,7 @@
9598
ObjectKey,
9699
ObjectLockToken,
97100
ObjectVersionId,
101+
OutputSerialization,
98102
PostResponse,
99103
PreconditionFailed,
100104
PutBucketAclRequest,
@@ -111,10 +115,14 @@
111115
ReplicationConfiguration,
112116
ReplicationConfigurationNotFoundError,
113117
RequestPayer,
118+
RequestProgress,
114119
S3Api,
120+
ScanRange,
115121
SelectObjectContentOutput,
116-
SelectObjectContentRequest,
117122
SkipValidation,
123+
SSECustomerAlgorithm,
124+
SSECustomerKey,
125+
SSECustomerKeyMD5,
118126
StorageClass,
119127
Token,
120128
)
@@ -435,7 +443,7 @@ def head_object(
435443
# this is a bug in AWS: it sets the content encoding header to an empty string (parity tested)
436444
response["ContentEncoding"] = ""
437445

438-
if request.get("ChecksumMode") == "ENABLED" and checksum_algorithm:
446+
if (request.get("ChecksumMode") or "").upper() == "ENABLED" and checksum_algorithm:
439447
response[f"Checksum{checksum_algorithm.upper()}"] = key_object.checksum_value # noqa
440448

441449
if not request.get("VersionId"):
@@ -485,7 +493,7 @@ def get_object(self, context: RequestContext, request: GetObjectRequest) -> GetO
485493
# this is a bug in AWS: it sets the content encoding header to an empty string (parity tested)
486494
response["ContentEncoding"] = ""
487495

488-
if request.get("ChecksumMode") == "ENABLED" and checksum_algorithm:
496+
if (request.get("ChecksumMode") or "").upper() == "ENABLED" and checksum_algorithm:
489497
response[f"Checksum{checksum_algorithm.upper()}"] = key_object.checksum_value # noqa
490498

491499
if not version_id and (
@@ -1558,11 +1566,21 @@ def get_bucket_logging(
15581566

15591567
return GetBucketLoggingOutput(LoggingEnabled=moto_bucket.logging)
15601568

1561-
@handler("SelectObjectContent", expand=False)
15621569
def select_object_content(
15631570
self,
15641571
context: RequestContext,
1565-
request: SelectObjectContentRequest,
1572+
bucket: BucketName,
1573+
key: ObjectKey,
1574+
expression: Expression,
1575+
expression_type: ExpressionType,
1576+
input_serialization: InputSerialization,
1577+
output_serialization: OutputSerialization,
1578+
sse_customer_algorithm: SSECustomerAlgorithm = None,
1579+
sse_customer_key: SSECustomerKey = None,
1580+
sse_customer_key_md5: SSECustomerKeyMD5 = None,
1581+
request_progress: RequestProgress = None,
1582+
scan_range: ScanRange = None,
1583+
expected_bucket_owner: AccountId = None,
15661584
) -> SelectObjectContentOutput:
15671585
# this operation is currently implemented by moto, but raises a 500 error because of the format necessary,
15681586
# and streaming capability.

tests/integration/s3/test_s3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,8 +1180,9 @@ def test_s3_get_object_checksum(self, s3_bucket, snapshot, algorithm, aws_client
11801180
)
11811181
snapshot.match("get-object-with-checksum", get_object_with_checksum)
11821182

1183+
# test that the casing of ChecksumMode is not important, the spec indicate only ENABLED
11831184
head_object_with_checksum = aws_client.s3.get_object(
1184-
Bucket=s3_bucket, Key=key, ChecksumMode="ENABLED"
1185+
Bucket=s3_bucket, Key=key, ChecksumMode="enabled"
11851186
)
11861187
snapshot.match("head-object-with-checksum", head_object_with_checksum)
11871188

tests/integration/s3/test_s3.snapshot.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4544,7 +4544,7 @@
45444544
}
45454545
},
45464546
"tests/integration/s3/test_s3.py::TestS3::test_s3_get_object_checksum[SHA256]": {
4547-
"recorded-date": "11-07-2023, 16:50:49",
4547+
"recorded-date": "13-07-2023, 15:46:58",
45484548
"recorded-content": {
45494549
"put-object": {
45504550
"ChecksumSHA256": "1YQo81vx2VFUl0q5ccWISq8AkSBQQ0WO80S82TmfdIQ=",
@@ -4615,7 +4615,7 @@
46154615
}
46164616
},
46174617
"tests/integration/s3/test_s3.py::TestS3::test_s3_get_object_checksum[None]": {
4618-
"recorded-date": "11-07-2023, 16:50:53",
4618+
"recorded-date": "13-07-2023, 15:47:02",
46194619
"recorded-content": {
46204620
"put-object": {
46214621
"ETag": "\"f2081dd61dfa700a0fd5e29b9c3cc23d\"",
@@ -6628,7 +6628,7 @@
66286628
}
66296629
},
66306630
"tests/integration/s3/test_s3.py::TestS3::test_s3_get_object_checksum[CRC32]": {
6631-
"recorded-date": "11-07-2023, 16:50:37",
6631+
"recorded-date": "13-07-2023, 15:46:47",
66326632
"recorded-content": {
66336633
"put-object": {
66346634
"ChecksumCRC32": "lVk/nw==",
@@ -6699,7 +6699,7 @@
66996699
}
67006700
},
67016701
"tests/integration/s3/test_s3.py::TestS3::test_s3_get_object_checksum[CRC32C]": {
6702-
"recorded-date": "11-07-2023, 16:50:41",
6702+
"recorded-date": "13-07-2023, 15:46:50",
67036703
"recorded-content": {
67046704
"put-object": {
67056705
"ChecksumCRC32C": "Fz3epA==",
@@ -6770,7 +6770,7 @@
67706770
}
67716771
},
67726772
"tests/integration/s3/test_s3.py::TestS3::test_s3_get_object_checksum[SHA1]": {
6773-
"recorded-date": "11-07-2023, 16:50:45",
6773+
"recorded-date": "13-07-2023, 15:46:54",
67746774
"recorded-content": {
67756775
"put-object": {
67766776
"ChecksumSHA1": "jbXkHAsXUrubtL3dqDQ4w+7WXc0=",

0 commit comments

Comments
 (0)
0