fix(s3): handle PutBucketRequestPayment instead of falling through to CreateBucket (#994)

PUT /{bucket}?requestPayment was not recognised as a sub-resource by
S3Controller, so the request fell through to the bucket-creation
handler. For any pre-existing bucket that returned
BucketAlreadyOwnedByYou (HTTP 409) — which broke real workloads such as
Terraform's aws_s3_bucket_request_payment_configuration on every
re-apply.

Add explicit handling for the requestPayment sub-resource, mirroring
the existing OwnershipControls / Acl flow:

- Bucket model gains a requestPaymentPayer field.
- S3Service.putBucketRequestPayment validates the bucket exists
  (NoSuchBucket / 404) and the payer value (BucketOwner | Requester);
  invalid payers return MalformedXML / 400 to match real S3.
- S3Service.getBucketRequestPayment returns the canonical
  RequestPaymentConfiguration XML, defaulting to BucketOwner when never
  set — real S3 never returns 404 for GetBucketRequestPayment.
- Controller dispatches PUT and GET ?requestPayment to the new methods.
  No DELETE handler is added; AWS does not expose one.

Regression test asserts the original Terraform-breaking case (a second
PUT on an existing bucket must return 200, not 409) along with default
GET, MalformedXML on invalid payer, and NoSuchBucket on missing bucket.
This commit is contained in:
ram-sarf authored and GitHub committed 2026-05-22 17:51:15 -05:00
1 parent 9286dd7602
commit f4a534c943
4 files changed
+171

No files matched your search

@@ -0,0 +1,119 @@
package io.github.hectorvent.floci.services.s3;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class S3RequestPaymentIntegrationTest {
private static final String BUCKET = "request-payment-int-test";
private static final String REQUESTER_PAYS_XML = """
<RequestPaymentConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Payer>Requester</Payer>
</RequestPaymentConfiguration>
""";
private static final String BUCKET_OWNER_PAYS_XML = """
<RequestPaymentConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Payer>BucketOwner</Payer>
</RequestPaymentConfiguration>
""";
@Test
@Order(1)
void createBucket() {
given()
.when()
.put("/" + BUCKET)
.then()
.statusCode(200);
}
@Test
@Order(2)
void getRequestPaymentBeforePutReturnsBucketOwnerDefault() {
given()
.when()
.get("/" + BUCKET + "?requestPayment")
.then()
.statusCode(200)
.body(containsString("<RequestPaymentConfiguration"))
.body(containsString("<Payer>BucketOwner</Payer>"));
}
@Test
@Order(3)
void putRequestPaymentReturns200() {
given()
.body(REQUESTER_PAYS_XML)
.when()
.put("/" + BUCKET + "?requestPayment")
.then()
.statusCode(200);
}
@Test
@Order(4)
void getRequestPaymentReturnsStoredPayer() {
given()
.when()
.get("/" + BUCKET + "?requestPayment")
.then()
.statusCode(200)
.body(containsString("<Payer>Requester</Payer>"));
}
/**
* Regression test for the Terraform-breaking bug where {@code PUT /{bucket}?requestPayment}
* fell through to the bucket-creation handler and returned {@code 409 BucketAlreadyOwnedByYou}.
* Real S3 allows {@code PutBucketRequestPayment} to be called repeatedly on an existing
* bucket — and Terraform's {@code aws_s3_bucket_request_payment_configuration} resource
* relies on this idempotency.
*/
@Test
@Order(5)
void putRequestPaymentIsIdempotentOnExistingBucket() {
given()
.body(BUCKET_OWNER_PAYS_XML)
.when()
.put("/" + BUCKET + "?requestPayment")
.then()
.statusCode(200)
.body(not(containsString("BucketAlreadyOwnedByYou")));
}
@Test
@Order(6)
void putRequestPaymentRejectsInvalidPayer() {
given()
.body("""
<RequestPaymentConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Payer>SomeoneElse</Payer>
</RequestPaymentConfiguration>
""")
.when()
.put("/" + BUCKET + "?requestPayment")
.then()
.statusCode(400)
.body(containsString("MalformedXML"));
}
@Test
@Order(7)
void putRequestPaymentOnMissingBucketReturns404() {
given()
.body(BUCKET_OWNER_PAYS_XML)
.when()
.put("/this-bucket-does-not-exist-rp?requestPayment")
.then()
.statusCode(404)
.body(containsString("NoSuchBucket"));
}
}