Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix: SQS tags set at CreateQueue not returned by ListQueueTags (#747)

Dixit R Jain1ffe905271f9
diff --git a/compatibility-tests/sdk-test-awscli/test/sqs.bats b/compatibility-tests/sdk-test-awscli/test/sqs.bats
index 3ff9675dc1..666090ebbe 100644
--- a/compatibility-tests/sdk-test-awscli/test/sqs.bats
+++ b/compatibility-tests/sdk-test-awscli/test/sqs.bats
@@ -84,3 +84,18 @@ teardown() {
assert_success
QUEUE_URL=""
}
+
+@test "SQS: tags set at CreateQueue are returned by ListQueueTags" {
+ # Regression test for https://github.com/floci-io/floci/issues/699
+ run aws_cmd sqs create-queue --queue-name "$QUEUE_NAME" --tags "k1=v1,k2=v2"
+ assert_success
+ QUEUE_URL=$(json_get "$output" '.QueueUrl')
+ [ -n "$QUEUE_URL" ]
+
+ run aws_cmd sqs list-queue-tags --queue-url "$QUEUE_URL"
+ assert_success
+ v1=$(json_get "$output" '.Tags.k1')
+ v2=$(json_get "$output" '.Tags.k2')
+ [ "$v1" = "v1" ]
+ [ "$v2" = "v2" ]
+}
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 f00bde17af..f91d10346a 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,7 +66,11 @@ public class SqsJsonHandler {
private Response handleCreateQueue(JsonNode request, String region) {
String queueName = request.path("QueueName").asText(null);
Map<String, String> attributes = jsonNodeToMap(request.path("Attributes"));
- Queue queue = sqsService.createQueue(queueName, attributes, region);
+ // Botocore sends "tags" (lowercase) for CreateQueue but "Tags" (uppercase) for TagQueue.
+ // Merge both to handle any client regardless of casing.
+ Map<String, String> tags = new HashMap<>(jsonNodeToMap(request.path("Tags")));
+ tags.putAll(jsonNodeToMap(request.path("tags")));
+ Queue queue = sqsService.createQueue(queueName, attributes, tags, region);
ObjectNode response = objectMapper.createObjectNode();
response.put("QueueUrl", queue.getQueueUrl());
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 243fb5a8d8..f1a0a41582 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
@@ -64,7 +64,8 @@ public class SqsQueryHandler {
private Response handleCreateQueue(MultivaluedMap<String, String> params, String region) {
String queueName = getParam(params, "QueueName");
Map<String, String> attributes = extractAttributes(params);
- Queue queue = sqsService.createQueue(queueName, attributes, region);
+ Map<String, String> tags = extractTags(params);
+ Queue queue = sqsService.createQueue(queueName, attributes, tags, region);
String result = new XmlBuilder().elem("QueueUrl", queue.getQueueUrl()).build();
return Response.ok(AwsQueryResponse.envelope("CreateQueue", null, result)).build();
@@ -439,6 +440,17 @@ public class SqsQueryHandler {
return attributes;
}
+ private Map<String, String> extractTags(MultivaluedMap<String, String> params) {
+ Map<String, String> tags = new HashMap<>();
+ for (int i = 1; ; i++) {
+ String key = getParam(params, "Tag." + i + ".Key");
+ String value = getParam(params, "Tag." + i + ".Value");
+ if (key == null) break;
+ tags.put(key, value);
+ }
+ return tags;
+ }
+
Response xmlErrorResponse(String code, String message, int status) {
return AwsQueryResponse.error(code, message, AwsNamespaces.SQS, status);
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsService.java b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsService.java
index 0682b683fb..2f8d237fe2 100644
--- a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsService.java
@@ -153,10 +153,14 @@ public class SqsService {
}
public Queue createQueue(String queueName, Map<String, String> attributes) {
- return createQueue(queueName, attributes, regionResolver.getDefaultRegion());
+ return createQueue(queueName, attributes, null, regionResolver.getDefaultRegion());
}
public Queue createQueue(String queueName, Map<String, String> attributes, String region) {
+ return createQueue(queueName, attributes, null, region);
+ }
+
+ public Queue createQueue(String queueName, Map<String, String> attributes, Map<String, String> tags, String region) {
boolean fifoRequested = attributes != null && "true".equalsIgnoreCase(attributes.get("FifoQueue"));
boolean hasFifoSuffix = queueName != null && queueName.endsWith(".fifo");
@@ -199,6 +203,9 @@ public class SqsService {
if (attributes != null) {
queue.getAttributes().putAll(attributes);
}
+ if (tags != null) {
+ queue.getTags().putAll(tags);
+ }
// Set default attributes
queue.getAttributes().putIfAbsent("VisibilityTimeout", String.valueOf(defaultVisibilityTimeout));
queue.getAttributes().putIfAbsent("MaximumMessageSize", String.valueOf(maxMessageSize));
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 eed1ad1aef..d8a253f77a 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
@@ -250,6 +250,52 @@ class SqsIntegrationTest {
.statusCode(400);
}
+ @Test
+ void createQueue_withTags_tagsReturnedByListQueueTags() {
+ // Regression test for https://github.com/floci-io/floci/issues/699
+ // Tags supplied at CreateQueue time must be visible via ListQueueTags.
+ String taggedQueueName = "tagged-queue-integration-test";
+
+ // Extract the queue URL from the CreateQueue response — don't hard-code the port
+ String taggedQueueUrl = given()
+ .contentType("application/x-www-form-urlencoded")
+ .formParam("Action", "CreateQueue")
+ .formParam("QueueName", taggedQueueName)
+ .formParam("Tag.1.Key", "k1")
+ .formParam("Tag.1.Value", "v1")
+ .formParam("Tag.2.Key", "k2")
+ .formParam("Tag.2.Value", "v2")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body(containsString(taggedQueueName))
+ .extract().xmlPath().getString("CreateQueueResponse.CreateQueueResult.QueueUrl");
+
+ 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"));
+
+ // cleanup
+ given()
+ .contentType("application/x-www-form-urlencoded")
+ .formParam("Action", "DeleteQueue")
+ .formParam("QueueUrl", taggedQueueUrl)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+ }
+
@Test
void unsupportedAction() {
given()
diff --git a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsServiceTest.java
index bb3a2ec1c9..4fa70e297b 100644
--- a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsServiceTest.java
@@ -48,6 +48,20 @@ class SqsServiceTest {
assertEquals("60", queue.getAttributes().get("VisibilityTimeout"));
}
+ @Test
+ void createQueueWithTags_tagsReturnedByListQueueTags() {
+ // Regression test for https://github.com/floci-io/floci/issues/699
+ // Tags supplied at CreateQueue time must be visible via ListQueueTags.
+ Map<String, String> tags = Map.of("k1", "v1", "k2", "v2");
+ Queue queue = sqsService.createQueue("tagged-queue", null, tags, "us-east-1");
+ String queueUrl = queue.getQueueUrl();
+
+ Map<String, String> returned = sqsService.listQueueTags(queueUrl, "us-east-1");
+ assertEquals(2, returned.size(), "ListQueueTags must return all tags set during CreateQueue");
+ assertEquals("v1", returned.get("k1"));
+ assertEquals("v2", returned.get("k2"));
+ }
+
@Test
void deleteQueue() {
Queue queue = sqsService.createQueue("test-queue", null);