Skip to content

Commit 2ca5d19

Browse files
authored
fix CopyObject not copying tag of current object (#11403)
1 parent f27739f commit 2ca5d19

File tree

4 files changed

+548
-1
lines changed

4 files changed

+548
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ def copy_object(
14171417
if (request.get("TaggingDirective")) == "REPLACE":
14181418
store.TAGS.tags[dest_key_id] = tagging or {}
14191419
else:
1420-
src_key_id = get_unique_key_id(src_bucket, src_key, src_version_id)
1420+
src_key_id = get_unique_key_id(src_bucket, src_key, src_s3_object.version_id)
14211421
src_tags = store.TAGS.tags.get(src_key_id, {})
14221422
store.TAGS.tags[dest_key_id] = copy.copy(src_tags)
14231423

tests/aws/services/s3/test_s3.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,95 @@ def test_s3_copy_tagging_directive(self, s3_bucket, snapshot, aws_client, taggin
15121512
)
15131513
snapshot.match("get-copy-object-tag-empty", get_object_tags)
15141514

1515+
@markers.aws.validated
1516+
@markers.snapshot.skip_snapshot_verify(
1517+
condition=is_v2_provider,
1518+
paths=["$..ServerSideEncryption"],
1519+
)
1520+
@pytest.mark.parametrize("tagging_directive", ["COPY", "REPLACE", None])
1521+
def test_s3_copy_tagging_directive_versioned(
1522+
self, s3_bucket, snapshot, aws_client, tagging_directive
1523+
):
1524+
snapshot.add_transformer(snapshot.transform.s3_api())
1525+
aws_client.s3.put_bucket_versioning(
1526+
Bucket=s3_bucket, VersioningConfiguration={"Status": "Enabled"}
1527+
)
1528+
object_key = "source-object"
1529+
resp = aws_client.s3.put_object(
1530+
Bucket=s3_bucket, Key=object_key, Body="test", Tagging="key1=value1"
1531+
)
1532+
snapshot.match("put-object", resp)
1533+
version_1 = resp["VersionId"]
1534+
1535+
resp = aws_client.s3.put_object(
1536+
Bucket=s3_bucket, Key=object_key, Body="test-v2", Tagging="key1=value1-v2"
1537+
)
1538+
snapshot.match("put-object-v2", resp)
1539+
1540+
get_object_tags = aws_client.s3.get_object_tagging(Bucket=s3_bucket, Key=object_key)
1541+
snapshot.match("get-object-tag", get_object_tags)
1542+
1543+
get_object_tags_v1 = aws_client.s3.get_object_tagging(
1544+
Bucket=s3_bucket, Key=object_key, VersionId=version_1
1545+
)
1546+
snapshot.match("get-object-tag-v1", get_object_tags_v1)
1547+
1548+
kwargs = {"TaggingDirective": tagging_directive} if tagging_directive else {}
1549+
1550+
object_key_copy = f"{object_key}-copy"
1551+
resp = aws_client.s3.copy_object(
1552+
Bucket=s3_bucket,
1553+
CopySource=f"{s3_bucket}/{object_key}",
1554+
Key=object_key_copy,
1555+
Tagging="key2=value2",
1556+
**kwargs,
1557+
)
1558+
snapshot.match("copy-object", resp)
1559+
1560+
get_object_tags = aws_client.s3.get_object_tagging(Bucket=s3_bucket, Key=object_key_copy)
1561+
snapshot.match("get-copy-object-tag", get_object_tags)
1562+
1563+
object_key_copy_tag_empty = f"{object_key}-copy-tag-empty"
1564+
resp = aws_client.s3.copy_object(
1565+
Bucket=s3_bucket,
1566+
CopySource=f"{s3_bucket}/{object_key}",
1567+
Key=object_key_copy_tag_empty,
1568+
**kwargs,
1569+
)
1570+
snapshot.match("copy-object-tag-empty", resp)
1571+
1572+
get_object_tags = aws_client.s3.get_object_tagging(
1573+
Bucket=s3_bucket, Key=object_key_copy_tag_empty
1574+
)
1575+
snapshot.match("get-copy-object-tag-empty", get_object_tags)
1576+
1577+
object_key_copy_v1 = f"{object_key}-copy-v1"
1578+
resp = aws_client.s3.copy_object(
1579+
Bucket=s3_bucket,
1580+
CopySource=f"{s3_bucket}/{object_key}?versionId={version_1}",
1581+
Key=object_key_copy_v1,
1582+
Tagging="key2=value2",
1583+
**kwargs,
1584+
)
1585+
snapshot.match("copy-object-v1", resp)
1586+
1587+
get_object_tags = aws_client.s3.get_object_tagging(Bucket=s3_bucket, Key=object_key_copy_v1)
1588+
snapshot.match("get-copy-object-tag-v1", get_object_tags)
1589+
1590+
object_key_copy_tag_empty_v1 = f"{object_key}-copy-tag-empty-v1"
1591+
resp = aws_client.s3.copy_object(
1592+
Bucket=s3_bucket,
1593+
CopySource=f"{s3_bucket}/{object_key}?versionId={version_1}",
1594+
Key=object_key_copy_tag_empty_v1,
1595+
**kwargs,
1596+
)
1597+
snapshot.match("copy-object-tag-empty-v1", resp)
1598+
1599+
get_object_tags = aws_client.s3.get_object_tagging(
1600+
Bucket=s3_bucket, Key=object_key_copy_tag_empty_v1
1601+
)
1602+
snapshot.match("get-copy-object-tag-empty-v1", get_object_tags)
1603+
15151604
@markers.aws.validated
15161605
@markers.snapshot.skip_snapshot_verify(
15171606
condition=is_v2_provider,

0 commit comments

Comments
 (0)