From 500ed1a90be59809efda6bf6410c89b8d1661460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristopher=20Pinz=C3=B3n?= Date: Sun, 6 Feb 2022 19:23:39 -0500 Subject: [PATCH] Addition of bucket name when creating a key object (#4824) --- moto/s3/models.py | 1 + tests/test_s3/test_s3.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/moto/s3/models.py b/moto/s3/models.py index 954bd4530..bf19c5a40 100644 --- a/moto/s3/models.py +++ b/moto/s3/models.py @@ -1614,6 +1614,7 @@ class S3Backend(BaseBackend, CloudWatchMetricProvider): new_key = FakeKey( name=key_name, + bucket_name=bucket_name, value=value, storage=storage, etag=etag, diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 950663ae8..2fecf195b 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -5315,3 +5315,31 @@ def test_head_versioned_key_in_not_versioned_bucket(): response = ex.value.response assert response["Error"]["Code"] == "400" + + +@mock_s3 +def test_objects_tagging_with_same_key_name(): + s3 = boto3.client("s3", region_name=DEFAULT_REGION_NAME) + key_name = "file.txt" + + bucket1 = "bucket-1" + s3.create_bucket(Bucket=bucket1) + tagging = "variable=one" + + s3.put_object(Bucket=bucket1, Body=b"test", Key=key_name, Tagging=tagging) + + bucket2 = "bucket-2" + s3.create_bucket(Bucket=bucket2) + tagging2 = "variable=two" + + s3.put_object(Bucket=bucket2, Body=b"test", Key=key_name, Tagging=tagging2) + + variable1 = s3.get_object_tagging(Bucket=bucket1, Key=key_name)["TagSet"][0][ + "Value" + ] + variable2 = s3.get_object_tagging(Bucket=bucket2, Key=key_name)["TagSet"][0][ + "Value" + ] + + assert variable1 == "one" + assert variable2 == "two"