mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): return XML error responses for presigned POST failures (#327)
Presigned POST errors were returned as JSON via AwsExceptionMapper. Real AWS S3 returns XML for these. Wrap handlePresignedPost to convert AwsException to XML via xmlErrorResponse(). Adds integration test asserting the exact XML wire format.
This commit is contained in:
1 parent
3b6b5fb687
commit
51bde88f2f
2 files changed
+52
No files matched your search
+42
@@ -13,6 +13,7 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.Base64;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
@@ -376,6 +377,47 @@ class S3PresignedPostIntegrationTest {
|
||||
+ "[\"starts-with\", \"$key\", \"uploads/\"]")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(94)
|
||||
void presignedPostReturnsXmlErrorResponseBody() {
|
||||
// Verify the raw XML wire format matches what AWS S3 and LocalStack return.
|
||||
// This ensures clients that parse the raw response body (e.g. seadn) see the
|
||||
// expected XML structure with "-encoded quotes, not JSON.
|
||||
String key = "uploads/xml-error-check.png";
|
||||
String fileContent = "not a real png";
|
||||
|
||||
String policy = buildPolicy(BUCKET, key, "image/png", 0, 10485760);
|
||||
String policyBase64 = Base64.getEncoder().encodeToString(policy.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
String responseBody =
|
||||
given()
|
||||
.multiPart("key", key)
|
||||
.multiPart("Content-Type", "image/gif")
|
||||
.multiPart("policy", policyBase64)
|
||||
.multiPart("x-amz-algorithm", "AWS4-HMAC-SHA256")
|
||||
.multiPart("x-amz-credential", "AKIAIOSFODNN7EXAMPLE/20260330/us-east-1/s3/aws4_request")
|
||||
.multiPart("x-amz-date", AMZ_DATE_FORMAT.format(Instant.now()))
|
||||
.multiPart("x-amz-signature", "dummysignature")
|
||||
.multiPart("file", "xml-error-check.png", fileContent.getBytes(StandardCharsets.UTF_8), "image/gif")
|
||||
.when()
|
||||
.post("/" + BUCKET)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.contentType("application/xml")
|
||||
.extract().body().asString();
|
||||
|
||||
// Assert the exact XML structure, matching what AWS S3 and LocalStack return.
|
||||
// The RequestId is a random UUID, so we match it with a regex.
|
||||
assertThat(responseBody, matchesRegex(
|
||||
"\\Q<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\E"
|
||||
+ "\\Q<Error>\\E"
|
||||
+ "\\Q<Code>AccessDenied</Code>\\E"
|
||||
+ "\\Q<Message>Invalid according to Policy: Policy Condition failed: \\E"
|
||||
+ "\\Q["eq", "$Content-Type", "image/png"]</Message>\\E"
|
||||
+ "<RequestId>[0-9a-f\\-]+</RequestId>"
|
||||
+ "\\Q</Error>\\E"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(95)
|
||||
void presignedPostEnforcesPolicyWithCapitalPFieldName() {
|
||||
|
||||
Reference in new issue
Block a user