mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): wrap S3 Control XML errors in ErrorResponse wrapper (#560)
* fix(s3): wrap S3 Control XML errors in ErrorResponse wrapper (#557) * fix(s3): align S3 Control error request ids - reuse the XML body request id in S3 Control error response headers - strengthen regression tests to assert the top-level RequestId and header/body alignment Addresses Copilot review feedback on PR #560. --------- Co-authored-by: MestreY0d4-Uninter <241404605+MestreY0d4-Uninter@users.noreply.github.com>
This commit is contained in:
1 parent
ce60457392
commit
bdc13f894e
2 files changed
+54
-19
No files matched your search
+36
-16
@@ -1,5 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.XmlParser;
|
||||
import io.restassured.response.Response;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
@@ -7,9 +9,14 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Integration tests for S3 Control API handling of URL-encoded ARN path
|
||||
@@ -33,6 +40,25 @@ class S3ControlUrlEncodedArnIntegrationTest {
|
||||
private static final String ENCODED_ARN =
|
||||
"arn%3Aaws%3As3%3A" + REGION + "%3A" + ACCOUNT + "%3Abucket%2F" + BUCKET;
|
||||
|
||||
private void assertS3ControlErrorResponse(Response response) {
|
||||
String body = response.getBody().asString();
|
||||
List<String> requestIds = XmlParser.extractAll(body, "RequestId");
|
||||
|
||||
assertEquals(400, response.statusCode());
|
||||
assertThat(response.getContentType(), containsString("xml"));
|
||||
assertThat(body, containsString("<ErrorResponse xmlns=\"http://awss3control.amazonaws.com/doc/2018-08-20/\">"));
|
||||
assertThat(body, containsString("<Error>"));
|
||||
assertThat(body, containsString("<Code>InvalidRequest</Code>"));
|
||||
assertTrue(body.contains("</Error><RequestId>"),
|
||||
"expected top-level RequestId sibling after the Error block");
|
||||
assertEquals(2, requestIds.size(), "expected inner and top-level RequestId elements");
|
||||
assertEquals(requestIds.get(0), requestIds.get(1),
|
||||
"expected inner and top-level RequestId values to match");
|
||||
assertEquals(requestIds.get(0), response.getHeader("x-amz-request-id"));
|
||||
assertEquals(requestIds.get(0), response.getHeader("x-amzn-RequestId"));
|
||||
assertEquals(requestIds.get(0), response.getHeader("x-amz-id-2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@DisplayName("setup: create bucket and tag it via the standard S3 tagging API")
|
||||
@@ -131,33 +157,27 @@ class S3ControlUrlEncodedArnIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@DisplayName("Malformed ARN returns valid S3-style XML error body (#435)")
|
||||
@DisplayName("Malformed ARN returns S3 Control ErrorResponse wrapper (#435, #557)")
|
||||
void malformedArnReturnsXmlError() {
|
||||
// Path param must not contain a literal ':bucket/' segment after decoding.
|
||||
given()
|
||||
Response response = given()
|
||||
.header("x-amz-account-id", ACCOUNT)
|
||||
.when()
|
||||
.get("/v20180820/tags/arn%3Aaws%3As3%3A%3A%3Abogus%2F" + BUCKET)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.contentType(containsString("xml"))
|
||||
.body(containsString("<Error>"))
|
||||
.body(containsString("<Code>InvalidRequest</Code>"));
|
||||
.get("/v20180820/tags/arn%3Aaws%3As3%3A%3A%3Abogus%2F" + BUCKET);
|
||||
|
||||
assertS3ControlErrorResponse(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
@DisplayName("Malformed percent-encoding returns XML error, not JSON 500 (#435)")
|
||||
@DisplayName("Malformed percent-encoding returns S3 Control ErrorResponse wrapper (#435, #557)")
|
||||
void malformedPercentEncodingReturnsXmlError() {
|
||||
// %ZZ is not a valid percent-encoding sequence; URLDecoder throws IAE.
|
||||
given()
|
||||
Response response = given()
|
||||
.header("x-amz-account-id", ACCOUNT)
|
||||
.when()
|
||||
.get("/v20180820/tags/arn%3Aaws%ZZbucket%2F" + BUCKET)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.contentType(containsString("xml"))
|
||||
.body(containsString("<Error>"))
|
||||
.body(containsString("<Code>InvalidRequest</Code>"));
|
||||
.get("/v20180820/tags/arn%3Aaws%ZZbucket%2F" + BUCKET);
|
||||
|
||||
assertS3ControlErrorResponse(response);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user