S3: get_object() should not return VersionId for non-versioned buckets (#6240)

This commit is contained in:
Bert Blommers 2023-04-21 10:57:39 +00:00 committed by GitHub
parent 28f3f84644
commit a08174405f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View File

@ -95,7 +95,7 @@ class FakeKey(BaseModel, ManagedState):
storage: Optional[str] = "STANDARD",
etag: Optional[str] = None,
is_versioned: bool = False,
version_id: int = 0,
version_id: str = "null",
max_buffer_size: Optional[int] = None,
multipart: Optional["FakeMultipart"] = None,
bucket_name: Optional[str] = None,
@ -156,7 +156,7 @@ class FakeKey(BaseModel, ManagedState):
return self.name
@property
def version_id(self) -> int:
def version_id(self) -> str:
return self._version_id
@property
@ -1856,6 +1856,7 @@ class S3Backend(BaseBackend, CloudWatchMetricProvider):
storage=storage,
etag=etag,
is_versioned=bucket.is_versioned,
# AWS uses VersionId=null in both requests and responses
version_id=str(random.uuid4()) if bucket.is_versioned else "null", # type: ignore
multipart=multipart,
encryption=encryption,

View File

@ -1348,7 +1348,7 @@ class S3Response(BaseResponse):
elif key is None:
raise MissingVersion()
if key.version_id:
if key.version_id != "null":
response_headers["x-amz-version-id"] = key.version_id
if key.storage_class in ARCHIVE_STORAGE_CLASSES:
@ -1386,8 +1386,6 @@ class S3Response(BaseResponse):
attributes_to_get = headers.get("x-amz-object-attributes", "").split(",")
response_keys = self.backend.get_object_attributes(key, attributes_to_get)
if key.version_id == "null": # type: ignore
response_headers.pop("x-amz-version-id")
response_headers["Last-Modified"] = key.last_modified_ISO8601
template = self.response_template(S3_OBJECT_ATTRIBUTES_RESPONSE)

View File

@ -2476,6 +2476,7 @@ def test_list_object_versions_with_versioning_disabled():
# Test latest object version is returned
response = s3.get_object(Bucket=bucket_name, Key=key)
assert "VersionId" not in response["ResponseMetadata"]["HTTPHeaders"]
response["Body"].read().should.equal(items[-1])