fix(s3): serve custom error document for missing keys in static websi… (#1334)

* fix(s3): serve custom error document for missing keys in static website hosting

When a bucket has a website configuration with an ErrorDocument, requests
to missing keys now return the error document with a 404 status instead
of the default XML NoSuchKey error.

* fix(test): handle null output in waitForExecution to prevent flaky CI failures

* fix(s3): address review feedback on static website hosting

* fix(s3): recognize s3-website hostnames in virtual host filter

* fix(s3): gate website error document on website endpoint host

* fix(s3): restore validateRawUri inside try block after rebase
This commit is contained in:
Eduardo Lugo Vela authored and GitHub committed 2026-06-25 01:09:34 -05:00
1 parent 398535ed55
commit 28a1427ea8
4 files changed
+132 -16

No files matched your search

@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.s3;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@@ -15,6 +16,10 @@ class S3WebsiteIntegrationTest {
private static final String BUCKET = "website-test-bucket";
private String websiteHost() {
return BUCKET + ".s3-website-us-east-1.localhost:" + RestAssured.port;
}
@Test
@Order(1)
void setupBucket() {
@@ -74,19 +79,33 @@ class S3WebsiteIntegrationTest {
@Test
@Order(5)
void indexRedirectionNotWorkingYetWithoutIndexFile() {
// Access root - should return XML list because index.html is missing
void uploadErrorFile() {
given()
.contentType("text/html")
.body("<html><body>Custom Error</body></html>")
.when()
.get("/" + BUCKET)
.put("/" + BUCKET + "/error.html")
.then()
.statusCode(200)
.contentType("application/xml")
.body(containsString("<ListBucketResult"));
.statusCode(200);
}
@Test
@Order(6)
void missingIndexServesErrorDocument() {
given()
.header("Host", websiteHost())
.when()
.get("/")
.then()
.statusCode(404)
.contentType("text/html")
.header("x-amz-error-code", "NoSuchKey")
.header("x-amz-error-message", "The specified key does not exist.")
.body(equalTo("<html><body>Custom Error</body></html>"));
}
@Test
@Order(7)
void uploadIndexFile() {
given()
.contentType("text/html")
@@ -98,12 +117,12 @@ class S3WebsiteIntegrationTest {
}
@Test
@Order(7)
@Order(8)
void indexRedirectionWorks() {
// Access root - should now return index.html content
given()
.header("Host", websiteHost())
.when()
.get("/" + BUCKET)
.get("/")
.then()
.statusCode(200)
.contentType("text/html")
@@ -111,7 +130,59 @@ class S3WebsiteIntegrationTest {
}
@Test
@Order(8)
@Order(9)
void missingKeyServesErrorDocument() {
given()
.header("Host", websiteHost())
.when()
.get("/missing-page")
.then()
.statusCode(404)
.contentType("text/html")
.header("x-amz-error-code", "NoSuchKey")
.header("x-amz-error-message", "The specified key does not exist.")
.body(equalTo("<html><body>Custom Error</body></html>"));
}
@Test
@Order(10)
void missingKeyReturnsXmlForRegularApiRequest() {
given()
.when()
.get("/" + BUCKET + "/missing-page")
.then()
.statusCode(404)
.body(containsString("NoSuchKey"));
}
@Test
@Order(11)
void missingErrorDocumentServesHtmlFallback() {
given().delete("/" + BUCKET + "/error.html");
given()
.header("Host", websiteHost())
.when()
.get("/missing-page")
.then()
.statusCode(404)
.contentType("text/html")
.header("x-amz-error-code", "NoSuchKey")
.header("x-amz-error-message", "The specified key does not exist.")
.body(containsString("404 Not Found"))
.body(containsString("NoSuchKey"));
given()
.contentType("text/html")
.body("<html><body>Custom Error</body></html>")
.when()
.put("/" + BUCKET + "/error.html")
.then()
.statusCode(200);
}
@Test
@Order(12)
void deleteWebsiteConfiguration() {
given()
.queryParam("website", "")
@@ -120,7 +191,6 @@ class S3WebsiteIntegrationTest {
.then()
.statusCode(204);
// Verify it's gone
given()
.queryParam("website", "")
.when()
@@ -130,9 +200,10 @@ class S3WebsiteIntegrationTest {
}
@Test
@Order(9)
@Order(13)
void cleanup() {
given().delete("/" + BUCKET + "/index.html");
given().delete("/" + BUCKET + "/error.html");
given().delete("/" + BUCKET);
}
}
@@ -645,7 +645,10 @@ class StepFunctionsDynamoDbIntegrationTest {
.post("/");
String status = resp.jsonPath().getString("status");
if ("SUCCEEDED".equals(status)) {
return resp.jsonPath().getString("output");
String output = resp.jsonPath().getString("output");
if (output != null) {
return output;
}
}
if ("FAILED".equals(status) || "ABORTED".equals(status)) {
fail("Execution " + status + ": " + resp.body().asString());