Skip to content

Commit 0ed6453

Browse files
committed
add multipart etag test
1 parent a879437 commit 0ed6453

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

tests/aws/services/s3/test_s3_api.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,3 +2122,61 @@ def test_put_object_if_match_and_if_none_match_validation(
21222122
with pytest.raises(ClientError) as e:
21232123
aws_client.s3.put_object(Bucket=s3_bucket, Key=key, IfNoneMatch="*", IfMatch="abcdef")
21242124
snapshot.match("put-obj-both-precondition", e.value.response)
2125+
2126+
@markers.aws.validated
2127+
def test_multipart_if_match_etag(self, s3_bucket, aws_client, snapshot):
2128+
key = "test-precondition"
2129+
put_obj = aws_client.s3.put_object(Bucket=s3_bucket, Key=key, Body="test")
2130+
snapshot.match("put-obj", put_obj)
2131+
put_obj_etag_1 = put_obj["ETag"]
2132+
2133+
create_multipart = aws_client.s3.create_multipart_upload(Bucket=s3_bucket, Key=key)
2134+
snapshot.match("create-multipart", create_multipart)
2135+
upload_id = create_multipart["UploadId"]
2136+
2137+
upload_part = aws_client.s3.upload_part(
2138+
Bucket=s3_bucket, Key=key, UploadId=upload_id, Body="test", PartNumber=1
2139+
)
2140+
parts = [{"ETag": upload_part["ETag"], "PartNumber": 1}]
2141+
2142+
complete_multipart_1 = aws_client.s3.complete_multipart_upload(
2143+
Bucket=s3_bucket,
2144+
Key=key,
2145+
MultipartUpload={"Parts": parts},
2146+
UploadId=upload_id,
2147+
IfMatch=put_obj_etag_1,
2148+
)
2149+
snapshot.match("complete-multipart-if-match", complete_multipart_1)
2150+
2151+
multipart_etag = complete_multipart_1["ETag"]
2152+
# those are different, because multipart etag contains the amount of parts and is the hash of the hashes of the
2153+
# part
2154+
assert put_obj_etag_1 != multipart_etag
2155+
2156+
create_multipart = aws_client.s3.create_multipart_upload(Bucket=s3_bucket, Key=key)
2157+
snapshot.match("create-multipart-overwrite", create_multipart)
2158+
upload_id = create_multipart["UploadId"]
2159+
2160+
upload_part = aws_client.s3.upload_part(
2161+
Bucket=s3_bucket, Key=key, UploadId=upload_id, Body="test", PartNumber=1
2162+
)
2163+
parts = [{"ETag": upload_part["ETag"], "PartNumber": 1}]
2164+
2165+
with pytest.raises(ClientError) as e:
2166+
aws_client.s3.complete_multipart_upload(
2167+
Bucket=s3_bucket,
2168+
Key=key,
2169+
MultipartUpload={"Parts": parts},
2170+
UploadId=upload_id,
2171+
IfMatch=put_obj_etag_1,
2172+
)
2173+
snapshot.match("complete-multipart-if-match-true-etag", e.value.response)
2174+
2175+
complete_multipart_1 = aws_client.s3.complete_multipart_upload(
2176+
Bucket=s3_bucket,
2177+
Key=key,
2178+
MultipartUpload={"Parts": parts},
2179+
UploadId=upload_id,
2180+
IfMatch=multipart_etag,
2181+
)
2182+
snapshot.match("complete-multipart-if-match-overwrite-multipart", complete_multipart_1)

tests/aws/services/s3/test_s3_api.snapshot.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,5 +4093,71 @@
40934093
}
40944094
}
40954095
}
4096+
},
4097+
"tests/aws/services/s3/test_s3_api.py::TestS3ObjectWritePrecondition::test_multipart_if_match_etag": {
4098+
"recorded-date": "27-11-2024, 10:35:20",
4099+
"recorded-content": {
4100+
"put-obj": {
4101+
"ETag": "\"098f6bcd4621d373cade4e832627b4f6\"",
4102+
"ServerSideEncryption": "AES256",
4103+
"ResponseMetadata": {
4104+
"HTTPHeaders": {},
4105+
"HTTPStatusCode": 200
4106+
}
4107+
},
4108+
"create-multipart": {
4109+
"Bucket": "<bucket:1>",
4110+
"Key": "test-precondition",
4111+
"ServerSideEncryption": "AES256",
4112+
"UploadId": "<upload-id:1>",
4113+
"ResponseMetadata": {
4114+
"HTTPHeaders": {},
4115+
"HTTPStatusCode": 200
4116+
}
4117+
},
4118+
"complete-multipart-if-match": {
4119+
"Bucket": "<bucket:1>",
4120+
"ETag": "\"60cd54a928cbbcbb6e7b5595bab46a9e-1\"",
4121+
"Key": "test-precondition",
4122+
"Location": "<location:1>",
4123+
"ServerSideEncryption": "AES256",
4124+
"ResponseMetadata": {
4125+
"HTTPHeaders": {},
4126+
"HTTPStatusCode": 200
4127+
}
4128+
},
4129+
"create-multipart-overwrite": {
4130+
"Bucket": "<bucket:1>",
4131+
"Key": "test-precondition",
4132+
"ServerSideEncryption": "AES256",
4133+
"UploadId": "<upload-id:2>",
4134+
"ResponseMetadata": {
4135+
"HTTPHeaders": {},
4136+
"HTTPStatusCode": 200
4137+
}
4138+
},
4139+
"complete-multipart-if-match-true-etag": {
4140+
"Error": {
4141+
"Code": "PreconditionFailed",
4142+
"Condition": "If-Match",
4143+
"Message": "At least one of the pre-conditions you specified did not hold"
4144+
},
4145+
"ResponseMetadata": {
4146+
"HTTPHeaders": {},
4147+
"HTTPStatusCode": 412
4148+
}
4149+
},
4150+
"complete-multipart-if-match-overwrite-multipart": {
4151+
"Bucket": "<bucket:1>",
4152+
"ETag": "\"60cd54a928cbbcbb6e7b5595bab46a9e-1\"",
4153+
"Key": "test-precondition",
4154+
"Location": "<location:1>",
4155+
"ServerSideEncryption": "AES256",
4156+
"ResponseMetadata": {
4157+
"HTTPHeaders": {},
4158+
"HTTPStatusCode": 200
4159+
}
4160+
}
4161+
}
40964162
}
40974163
}

tests/aws/services/s3/test_s3_api.validation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
"tests/aws/services/s3/test_s3_api.py::TestS3ObjectLock::test_put_object_lock_configuration_on_existing_bucket": {
120120
"last_validated_date": "2024-01-15T03:13:25+00:00"
121121
},
122+
"tests/aws/services/s3/test_s3_api.py::TestS3ObjectWritePrecondition::test_multipart_if_match_etag": {
123+
"last_validated_date": "2024-11-27T10:35:19+00:00"
124+
},
122125
"tests/aws/services/s3/test_s3_api.py::TestS3ObjectWritePrecondition::test_multipart_if_match_with_delete": {
123126
"last_validated_date": "2024-11-26T23:47:58+00:00"
124127
},

0 commit comments

Comments
 (0)