fix(s3): validate CreateBucketConfiguration before creating the bucket (#4113)

This commit is contained in:
Daniël van Ziel authored and GitHub committed 2026-09-23 18:07:46 -04:00
1 parent 75dd057b5c
commit fab5130ebb
2 files changed
+162 -16

No files matched your search

@@ -511,6 +511,117 @@ class S3IntegrationTest {
.body(containsString("MalformedXML"));
}
@Test
@Order(208)
void createBucketRejectsMalformedCreateBucketConfigurationAndCreatesNoBucket() {
String bucket = "malformed-config-bucket";
given()
.contentType("application/xml")
.body("<CreateBucketConfiguration><LocationConstraint>eu-central-1</LocationConstraint>")
.when()
.put("/" + bucket)
.then()
.statusCode(400)
.body(containsString("MalformedXML"));
assertBucketDoesNotExist(bucket);
}
@Test
@Order(209)
void createBucketRejectsUnknownCreateBucketConfigurationFieldAndCreatesNoBucket() {
String bucket = "unknown-config-field-bucket";
given()
.contentType("application/xml")
.body("""
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Foo>bar</Foo>
</CreateBucketConfiguration>
""")
.when()
.put("/" + bucket)
.then()
.statusCode(400)
.body(containsString("MalformedXML"));
assertBucketDoesNotExist(bucket);
}
@Test
@Order(210)
void createBucketRejectsWrongCreateBucketConfigurationRootAndCreatesNoBucket() {
String bucket = "wrong-config-root-bucket";
given()
.contentType("application/xml")
.body("""
<CreateBucketConfigurationFoo xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<LocationConstraint>eu-central-1</LocationConstraint>
</CreateBucketConfigurationFoo>
""")
.when()
.put("/" + bucket)
.then()
.statusCode(400)
.body(containsString("MalformedXML"));
assertBucketDoesNotExist(bucket);
}
@Test
@Order(211)
void createBucketRejectsInvalidLocationConstraintAndCreatesNoBucket() {
String bucket = "invalid-constraint-bucket";
given()
.contentType("application/xml")
.body("""
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<LocationConstraint>not-a-region</LocationConstraint>
</CreateBucketConfiguration>
""")
.when()
.put("/" + bucket)
.then()
.statusCode(400)
.body(containsString("InvalidLocationConstraint"));
assertBucketDoesNotExist(bucket);
}
@Test
@Order(212)
void createBucketAcceptsDirectoryBucketConfiguration() {
String bucket = "directory-config-bucket";
given()
.contentType("application/xml")
.body("""
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Location>us-west-2</Location>
<Bucket>
<Type>Directory</Type>
</Bucket>
</CreateBucketConfiguration>
""")
.when()
.put("/" + bucket)
.then()
.statusCode(200);
given()
.when()
.get("/" + bucket)
.then()
.statusCode(200);
}
private static void assertBucketDoesNotExist(String bucket) {
given()
.when()
.get("/" + bucket)
.then()
.statusCode(404)
.body(containsString("NoSuchBucket"));
}
@Test
void createBucketReroutesMisplacedVirtualHostedPutObject() {
String targetBucket = "reroute-target-bucket";