Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(sqs): skip JSON null tag/attribute values instead of storing literal "null" (#905)

Stuart Langaec85f993a67
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 1a127929bf..4c9c2469b5 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
@@ -516,7 +516,14 @@ public class SqsJsonHandler {
private Map<String, String> jsonNodeToMap(JsonNode node) {
Map<String, String> map = new HashMap<>();
if (node != null && node.isObject()) {
- node.fields().forEachRemaining(entry -> map.put(entry.getKey(), entry.getValue().asText()));
+ node.fields().forEachRemaining(entry -> {
+ JsonNode value = entry.getValue();
+ if (value == null || value.isNull() || value.isMissingNode()) {
+ throw new AwsException("InvalidParameterValue",
+ "the parameter 'value' may not be null", 400);
+ }
+ map.put(entry.getKey(), value.asText());
+ });
}
return map;
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsJsonProtocolTest.java b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsJsonProtocolTest.java
index 526e498e5f..4e895f7cc4 100644
--- a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsJsonProtocolTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsJsonProtocolTest.java
@@ -289,6 +289,91 @@ class SqsJsonProtocolTest {
.body("Messages[0].Attributes.ApproximateFirstReceiveTimestamp", notNullValue());
}
+ @Test
+ @Order(7)
+ void tagQueueWithJsonNullValueIsRejected() {
+ String tagBody = "{\"QueueUrl\":\"" + queueUrl + "\","
+ + "\"Tags\":{\"NullTag\":null,\"RealTag\":\"value\"}}";
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AmazonSQS.TagQueue")
+ .body(tagBody)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterValue"))
+ .body("message", equalTo("the parameter 'value' may not be null"));
+
+ String listBody = "{\"QueueUrl\":\"" + queueUrl + "\"}";
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AmazonSQS.ListQueueTags")
+ .body(listBody)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("Tags.NullTag", nullValue())
+ .body("Tags.RealTag", nullValue());
+ }
+
+ @Test
+ @Order(7)
+ void createQueueWithJsonNullTagValueIsRejected() {
+ String body = "{\"QueueName\":\"" + QUEUE_NAME + "-null-tag\","
+ + "\"tags\":{\"NullTag\":null}}";
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AmazonSQS.CreateQueue")
+ .body(body)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterValue"))
+ .body("message", equalTo("the parameter 'value' may not be null"));
+ }
+
+ @Test
+ @Order(7)
+ void createQueueWithJsonNullAttributeValueIsRejected() {
+ String body = "{\"QueueName\":\"" + QUEUE_NAME + "-null-attr\","
+ + "\"Attributes\":{\"DelaySeconds\":null}}";
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AmazonSQS.CreateQueue")
+ .body(body)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterValue"))
+ .body("message", equalTo("the parameter 'value' may not be null"));
+ }
+
+ @Test
+ @Order(7)
+ void setQueueAttributesWithJsonNullValueIsRejected() {
+ String body = "{\"QueueUrl\":\"" + queueUrl + "\","
+ + "\"Attributes\":{\"DelaySeconds\":null}}";
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AmazonSQS.SetQueueAttributes")
+ .body(body)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterValue"))
+ .body("message", equalTo("the parameter 'value' may not be null"));
+ }
+
@Test
@Order(8)
void deleteQueueViaQueueUrlPath() {