From 7a036fdf5998e87c28e6433930b6af54c4da7327 Mon Sep 17 00:00:00 2001 From: Kenshin Okinaka Date: Sat, 9 May 2026 14:32:49 +0900 Subject: [PATCH] fix(sqs): drop uppercase "Tags" read from CreateQueue JSON handler (#752) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(sqs): drop uppercase "Tags" read from CreateQueue JSON handler AWS SQS JSON 1.0 schema uses lowercase "tags" for CreateQueue (uppercase "Tags" is reserved for TagQueue). Real AWS treats unknown JSON fields as ignored, so a hand-crafted client sending uppercase "Tags" would lose its tags on AWS — but floci silently persisted them, diverging from AWS behavior and masking client bugs at migration time. Drop the defensive uppercase merge and add JSON-protocol integration tests for both the canonical lowercase path (tags persist) and the uppercase-as-unknown-field path (tags ignored). * test(sqs): wrap CreateQueue-with-tags tests in try/finally for cleanup Wrap CreateQueue + ListQueueTags + DeleteQueue test bodies so the cleanup DeleteQueue runs in a finally block. A failed assertion previously left an orphan queue, which could mask flake under re-runs since CreateQueue is idempotent and won't re-apply tags to an existing queue. --- .../floci/services/sqs/SqsJsonHandler.java | 5 +- .../services/sqs/SqsIntegrationTest.java | 103 +++++++++++++++--- 2 files changed, 90 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsJsonHandler.java index f91d10346a..38c67fec85 100644 --- a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsJsonHandler.java @@ -66,10 +66,7 @@ public class SqsJsonHandler { private Response handleCreateQueue(JsonNode request, String region) { String queueName = request.path("QueueName").asText(null); Map attributes = jsonNodeToMap(request.path("Attributes")); - // Botocore sends "tags" (lowercase) for CreateQueue but "Tags" (uppercase) for TagQueue. - // Merge both to handle any client regardless of casing. - Map tags = new HashMap<>(jsonNodeToMap(request.path("Tags"))); - tags.putAll(jsonNodeToMap(request.path("tags"))); + Map tags = jsonNodeToMap(request.path("tags")); Queue queue = sqsService.createQueue(queueName, attributes, tags, region); ObjectNode response = objectMapper.createObjectNode(); 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 d8a253f77a..8e73515fac 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 @@ -272,28 +272,103 @@ class SqsIntegrationTest { .body(containsString(taggedQueueName)) .extract().xmlPath().getString("CreateQueueResponse.CreateQueueResult.QueueUrl"); - given() - .contentType("application/x-www-form-urlencoded") - .formParam("Action", "ListQueueTags") - .formParam("QueueUrl", taggedQueueUrl) + try { + given() + .contentType("application/x-www-form-urlencoded") + .formParam("Action", "ListQueueTags") + .formParam("QueueUrl", taggedQueueUrl) + .when() + .post("/") + .then() + .statusCode(200) + .body(containsString("k1")) + .body(containsString("v1")) + .body(containsString("k2")) + .body(containsString("v2")); + } finally { + given() + .contentType("application/x-www-form-urlencoded") + .formParam("Action", "DeleteQueue") + .formParam("QueueUrl", taggedQueueUrl) + .when() + .post("/"); + } + } + + @Test + void createQueue_jsonProtocol_withLowercaseTags_tagsReturnedByListQueueTags() { + // SQS JSON 1.0 schema uses lowercase "tags" for CreateQueue (cf. uppercase "Tags" for TagQueue). + String taggedQueueName = "tagged-queue-json-integration-test"; + + String taggedQueueUrl = given() + .contentType("application/x-amz-json-1.0") + .header("X-Amz-Target", "AmazonSQS.CreateQueue") + .body("{\"QueueName\": \"" + taggedQueueName + "\", \"tags\": {\"k1\": \"v1\", \"k2\": \"v2\"}}") .when() .post("/") .then() .statusCode(200) - .body(containsString("k1")) - .body(containsString("v1")) - .body(containsString("k2")) - .body(containsString("v2")); + .extract().jsonPath().getString("QueueUrl"); - // cleanup - given() - .contentType("application/x-www-form-urlencoded") - .formParam("Action", "DeleteQueue") - .formParam("QueueUrl", taggedQueueUrl) + try { + given() + .contentType("application/x-www-form-urlencoded") + .formParam("Action", "ListQueueTags") + .formParam("QueueUrl", taggedQueueUrl) + .when() + .post("/") + .then() + .statusCode(200) + .body(containsString("k1")) + .body(containsString("v1")) + .body(containsString("k2")) + .body(containsString("v2")); + } finally { + given() + .contentType("application/x-www-form-urlencoded") + .formParam("Action", "DeleteQueue") + .formParam("QueueUrl", taggedQueueUrl) + .when() + .post("/"); + } + } + + @Test + void createQueue_jsonProtocol_withUppercaseTags_tagsAreIgnored() { + // SQS JSON 1.0 only defines lowercase "tags" for CreateQueue; uppercase "Tags" belongs to + // TagQueue and must be treated as an unknown field here, matching real AWS. + String taggedQueueName = "ignored-uppercase-tags-queue"; + + String taggedQueueUrl = given() + .contentType("application/x-amz-json-1.0") + .header("X-Amz-Target", "AmazonSQS.CreateQueue") + .body("{\"QueueName\": \"" + taggedQueueName + "\", \"Tags\": {\"k1\": \"v1\"}}") .when() .post("/") .then() - .statusCode(200); + .statusCode(200) + .extract().jsonPath().getString("QueueUrl"); + + try { + given() + .contentType("application/x-www-form-urlencoded") + .formParam("Action", "ListQueueTags") + .formParam("QueueUrl", taggedQueueUrl) + .when() + .post("/") + .then() + .statusCode(200) + .body(not(containsString(""))) + .body(not(containsString("k1"))) + .body(not(containsString("v1"))); + } finally { + given() + .contentType("application/x-www-form-urlencoded") + .formParam("Action", "DeleteQueue") + .formParam("QueueUrl", taggedQueueUrl) + .when() + .post("/"); + } } @Test