From fc1ef55adc7e0c886602149cfe9c1dc04645952b Mon Sep 17 00:00:00 2001 From: Roman Rader Date: Thu, 27 Jan 2022 01:24:51 +0200 Subject: [PATCH] Missing VersionID for versioned buckets in API (#4796) --- AUTHORS.md | 1 + moto/s3/responses.py | 3 +++ tests/test_s3/test_s3.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 5f7d047ce..06037aa53 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -60,3 +60,4 @@ Moto is written by Steve Pulec with contributions from: * [Kyle Jones](https://github.com/Kerl1310) * [Mickaƫl Schoentgen](https://github.com/BoboTiG) * [Ariel Beck](https://github.com/arielb135) +* [Roman Rader](https://github.com/rrader/) diff --git a/moto/s3/responses.py b/moto/s3/responses.py index 07b36c4b2..7df1f5b45 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -1272,6 +1272,9 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): elif key is None: raise MissingVersion() + if key.version_id: + response_headers["x-amz-version-id"] = key.version_id + if key.storage_class == "GLACIER": raise InvalidObjectState(storage_class="GLACIER") if if_unmodified_since: diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 4bb3b111b..950663ae8 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -3562,6 +3562,7 @@ def test_boto3_put_object_tagging_on_earliest_version(): # Older version has tags while the most recent does not resp = s3.get_object_tagging(Bucket=bucket_name, Key=key, VersionId=first_object.id) + resp["VersionId"].should.equal(first_object.id) resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) sorted_tagset = sorted(resp["TagSet"], key=lambda t: t["Key"]) sorted_tagset.should.equal( @@ -3571,6 +3572,7 @@ def test_boto3_put_object_tagging_on_earliest_version(): resp = s3.get_object_tagging( Bucket=bucket_name, Key=key, VersionId=second_object.id ) + resp["VersionId"].should.equal(second_object.id) resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) resp["TagSet"].should.equal([])