S3: Allow Bucket Creation without specifying Content-Length header (#6190)

This commit is contained in:
Bert Blommers 2023-04-09 10:05:43 +00:00 committed by GitHub
parent 1eb3479d08
commit 0e6d27bac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -740,7 +740,7 @@ class S3Response(BaseResponse):
return parsed_xml
def _bucket_response_put(self, request, region_name, bucket_name, querystring):
if not request.headers.get("Content-Length"):
if querystring and not request.headers.get("Content-Length"):
return 411, {}, "Content-Length required"
self._set_action("BUCKET", "PUT", querystring)

View File

@ -158,11 +158,30 @@ def test_s3_server_post_to_bucket_redirect():
def test_s3_server_post_without_content_length():
test_client = authenticated_client()
# You can create a bucket without specifying Content-Length
res = test_client.put(
"/", "http://tester.localhost:5000/", environ_overrides={"CONTENT_LENGTH": ""}
)
res.status_code.should.equal(200)
# You can specify a bucket in another region without specifying Content-Length
# (The body is just ignored..)
res = test_client.put(
"/",
"http://tester.localhost:5000/",
environ_overrides={"CONTENT_LENGTH": ""},
data="<CreateBucketConfiguration><LocationConstraint>us-west-2</LocationConstraint></CreateBucketConfiguration>",
)
res.status_code.should.equal(200)
# You cannot make any other bucket-related requests without specifying Content-Length
for path in ["/?versioning", "/?policy"]:
res = test_client.put(
path, "http://t.localhost:5000", environ_overrides={"CONTENT_LENGTH": ""}
)
res.status_code.should.equal(411)
# You cannot make any POST-request
res = test_client.post(
"/", "https://tester.localhost:5000/", environ_overrides={"CONTENT_LENGTH": ""}
)