Light, fluffy, and always free - The AWS Local Emulator alternative
fix(sqs): render Query-protocol errors as XML instead of leaking JSON (#1732)
Hector Ventura8893d2c51eb0
diff --git a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsQueryHandler.javaindex 54668ddd82..62d894dbcd 100644--- a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsQueryHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsQueryHandler.java@@ -35,6 +35,20 @@ public class SqsQueryHandler {public Response handle(String action, MultivaluedMap<String, String> params, String region) {LOG.debugv("SQS action: {0}", action);+ // Wrap like every other Query handler: without this, AwsExceptions escape to the+ // global JAX-RS mapper, which renders a JSON error body on this XML protocol.+ try {+ return dispatch(action, params, region);+ } catch (AwsException e) {+ return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.SQS, e.getHttpStatus());+ } catch (Exception e) {+ LOG.errorv(e, "Unexpected error in SQS {0}", action);+ return AwsQueryResponse.error("InternalError",+ "Unexpected error: " + e.getMessage(), AwsNamespaces.SQS, 500);+ }+ }++ private Response dispatch(String action, MultivaluedMap<String, String> params, String region) {return switch (action) {case "CreateQueue" -> handleCreateQueue(params, region);case "DeleteQueue" -> handleDeleteQueue(params, region);diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStackSetsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStackSetsIntegrationTest.javaindex 4c0ad7c5a5..c1086390d4 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStackSetsIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationStackSetsIntegrationTest.java@@ -53,7 +53,11 @@ class CloudFormationStackSetsIntegrationTest {.formParam("QueueName", queueName).header("Authorization", auth(account, "sqs")).when().post("/")- .then().body(containsString("QueueDoesNotExist"));+ .then()+ .statusCode(400)+ // Query protocol renders the XML ErrorResponse with the legacy Query code;+ // QueueDoesNotExist is its JSON-protocol __type equivalent (see AwsException).+ .body(containsString("AWS.SimpleQueueService.NonExistentQueue"));}@Testdiff --git a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsIntegrationTest.javaindex bd53f171a4..814bfc6db9 100644--- a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsIntegrationTest.java@@ -483,7 +483,10 @@ class SqsIntegrationTest {.post("/").then().statusCode(400)- .body(containsString("QueueNameExists"));+ // Query protocol renders the XML ErrorResponse with the legacy Query code;+ // QueueNameExists is its JSON-protocol __type equivalent (see AwsException).+ .contentType(containsString("xml"))+ .body("ErrorResponse.Error.Code", equalTo("QueueAlreadyExists"));given().contentType("application/x-www-form-urlencoded")@@ -612,6 +615,25 @@ class SqsIntegrationTest {}}+ @Test+ void queryProtocolErrorsAreXmlNotJson() {+ // Regression: AwsExceptions escaping SqsQueryHandler used to reach the global+ // JAX-RS mapper and render a JSON body on this XML protocol.+ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "GetQueueUrl")+ .formParam("QueueName", "does-not-exist-queue")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .contentType(containsString("xml"))+ .body("ErrorResponse.Error.Type", equalTo("Sender"))+ .body("ErrorResponse.Error.Code", equalTo("AWS.SimpleQueueService.NonExistentQueue"))+ .body("ErrorResponse.Error.Message",+ equalTo("The specified queue does not exist for this wsdl version."));+ }+@Testvoid sendMessageBatch_queryProtocol_persistsAwsTraceHeaderPerEntry() {String traceQueueName = "query-batch-trace-queue";