S3: get_object() should not return VersionId for non-versioned buckets (#6240)
This commit is contained in:
parent
28f3f84644
commit
a08174405f
@ -95,7 +95,7 @@ class FakeKey(BaseModel, ManagedState):
|
|||||||
storage: Optional[str] = "STANDARD",
|
storage: Optional[str] = "STANDARD",
|
||||||
etag: Optional[str] = None,
|
etag: Optional[str] = None,
|
||||||
is_versioned: bool = False,
|
is_versioned: bool = False,
|
||||||
version_id: int = 0,
|
version_id: str = "null",
|
||||||
max_buffer_size: Optional[int] = None,
|
max_buffer_size: Optional[int] = None,
|
||||||
multipart: Optional["FakeMultipart"] = None,
|
multipart: Optional["FakeMultipart"] = None,
|
||||||
bucket_name: Optional[str] = None,
|
bucket_name: Optional[str] = None,
|
||||||
@ -156,7 +156,7 @@ class FakeKey(BaseModel, ManagedState):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def version_id(self) -> int:
|
def version_id(self) -> str:
|
||||||
return self._version_id
|
return self._version_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -1856,6 +1856,7 @@ class S3Backend(BaseBackend, CloudWatchMetricProvider):
|
|||||||
storage=storage,
|
storage=storage,
|
||||||
etag=etag,
|
etag=etag,
|
||||||
is_versioned=bucket.is_versioned,
|
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
|
version_id=str(random.uuid4()) if bucket.is_versioned else "null", # type: ignore
|
||||||
multipart=multipart,
|
multipart=multipart,
|
||||||
encryption=encryption,
|
encryption=encryption,
|
||||||
|
@ -1348,7 +1348,7 @@ class S3Response(BaseResponse):
|
|||||||
elif key is None:
|
elif key is None:
|
||||||
raise MissingVersion()
|
raise MissingVersion()
|
||||||
|
|
||||||
if key.version_id:
|
if key.version_id != "null":
|
||||||
response_headers["x-amz-version-id"] = key.version_id
|
response_headers["x-amz-version-id"] = key.version_id
|
||||||
|
|
||||||
if key.storage_class in ARCHIVE_STORAGE_CLASSES:
|
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(",")
|
attributes_to_get = headers.get("x-amz-object-attributes", "").split(",")
|
||||||
response_keys = self.backend.get_object_attributes(key, attributes_to_get)
|
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
|
response_headers["Last-Modified"] = key.last_modified_ISO8601
|
||||||
|
|
||||||
template = self.response_template(S3_OBJECT_ATTRIBUTES_RESPONSE)
|
template = self.response_template(S3_OBJECT_ATTRIBUTES_RESPONSE)
|
||||||
|
@ -2476,6 +2476,7 @@ def test_list_object_versions_with_versioning_disabled():
|
|||||||
|
|
||||||
# Test latest object version is returned
|
# Test latest object version is returned
|
||||||
response = s3.get_object(Bucket=bucket_name, Key=key)
|
response = s3.get_object(Bucket=bucket_name, Key=key)
|
||||||
|
assert "VersionId" not in response["ResponseMetadata"]["HTTPHeaders"]
|
||||||
response["Body"].read().should.equal(items[-1])
|
response["Body"].read().should.equal(items[-1])
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user