From 8893d2c51eb0cc55ee820e2ee8f20e520408c2bd Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Sun, 5 Jul 2026 09:14:23 -0500 Subject: [PATCH] fix(sqs): render Query-protocol errors as XML instead of leaking JSON (#1732) * fix(sqs): render Query-protocol errors as XML instead of leaking JSON SqsQueryHandler was the only Query handler without top-level error wrapping, so AwsExceptions escaped to the global JAX-RS mapper and rendered a JSON body (application/json, __type) on the XML Query path. Wrap the dispatch like every other Query handler and emit the standard ErrorResponse envelope with the legacy Query error codes (QueueAlreadyExists, AWS.SimpleQueueService. NonExistentQueue). The existing conflicting-attributes test pinned the leaked JSON __type code and now asserts the XML shape; the JSON protocol path is unchanged. * test(cloudformation): assert legacy Query error code in assertQueueAbsent The StackSets helper probes queue absence over the SQS Query protocol but asserted QueueDoesNotExist, the JSON-protocol __type that only appeared there because Query errors leaked through the JSON mapper. With Query errors now rendered as XML, assert the legacy code AWS.SimpleQueueService.NonExistentQueue and the 400 status. --- .../floci/services/sqs/SqsQueryHandler.java | 14 +++++++++++ ...loudFormationStackSetsIntegrationTest.java | 6 ++++- .../services/sqs/SqsIntegrationTest.java | 24 ++++++++++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) 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.java index 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 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 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.java index 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")); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsIntegrationTest.java index 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.")); + } + @Test void sendMessageBatch_queryProtocol_persistsAwsTraceHeaderPerEntry() { String traceQueueName = "query-batch-trace-queue";