Light, fluffy, and always free - The AWS Local Emulator alternative
fix(sqs): reject DelaySeconds outside 0-900 (#6852)
berce6abd9d7ffb50
diff --git a/docs/services/sqs.md b/docs/services/sqs.mdindex 3e667fc439..44304fc995 100644--- a/docs/services/sqs.md+++ b/docs/services/sqs.md@@ -103,6 +103,8 @@ aws sqs set-queue-attributes \`MaximumMessageSize` defaults to `1048576` bytes, the AWS default and maximum since August 2025, when AWS raised both from `262144`. `CreateQueue` and `SetQueueAttributes` reject values outside 1024 to 1048576 with `InvalidAttributeValue`; raising `FLOCI_SERVICES_SQS_MAX_MESSAGE_SIZE` above the AWS maximum raises that accepted ceiling with it. Lowering the variable below 1048576 only changes the default a new queue receives: the accepted ceiling stays at the AWS maximum, so a queue can still be set to `1048576` explicitly.+`DelaySeconds` must be 0 to 900, both on a message and as a queue attribute: `SendMessage` rejects other values with `InvalidParameterValue` (in `SendMessageBatch` only that entry fails), and `CreateQueue` and `SetQueueAttributes` reject them with `InvalidAttributeValue`.+`SqsManagedSseEnabled` is `true` for a queue with no `KmsMasterKeyId`, matching AWS, and `false` once a KMS key is set. It is derived on read rather than stored, so clearing `KmsMasterKeyId` returns the queue to `true`, unless you set `SqsManagedSseEnabled` yourself, in which case your value stands. AWS does not document the cleared-key case crisply, so that behaviour is Floci's choice rather than a copied one. `CreateQueue` on an existing name compares requested attributes against these reported values, so asking for `SqsManagedSseEnabled=false` on a queue that reports `true` fails with `QueueAlreadyExists` (`QueueNameExists` over JSON).## Message Retentiondiff --git a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsJsonHandler.javaindex 0617be8676..0838b53e1c 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@@ -613,7 +613,8 @@ public class SqsJsonHandler {if (node.isMissingNode() || node.isNull()) {return null;}- if (!node.isIntegralNumber()) {+ // asInt() wraps a value outside the int range, so 4294967296 would read as 0.+ if (!node.isIntegralNumber() || !node.canConvertToInt()) {throw new AwsException("InvalidParameterValue","Value for parameter " + paramName + " is invalid. Reason: Must be an integer.", 400);}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.javaindex 77f8def344..2959b94747 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@@ -70,6 +70,7 @@ public class SqsService implements Resettable, ResourceProvider {private static final int DEDUP_WINDOW_SECONDS = 300; // 5 minutesprivate static final int DEDUP_LOCK_STRIPES = 256;private static final int MAX_RECEIVE_WAIT_TIME_SECONDS = 20;+ private static final int MAX_DELAY_SECONDS = 900;private static final int MAX_BATCH_ENTRIES = 10;private static final int MAX_LIST_QUEUES_RESULTS = 1000;private static final String LIST_QUEUES_TOKEN_NAMESPACE = "sqs-list-queues";@@ -742,6 +743,7 @@ public class SqsService implements Resettable, ResourceProvider {validateMaximumMessageSize(attributes);attributes = validateMessageRetentionPeriod(attributes);+ validateDelaySeconds(attributes);attributes = compactRedrivePolicies(attributes);String accountId = regionResolver.getAccountId();@@ -1036,6 +1038,12 @@ public class SqsService implements Resettable, ResourceProvider {"Reason: Message must be shorter than " + queueMaxMessageSize + " bytes.", 400);}+ if (delaySeconds != null && (delaySeconds < 0 || delaySeconds > MAX_DELAY_SECONDS)) {+ throw new AwsException("InvalidParameterValue",+ "Value " + delaySeconds + " for parameter DelaySeconds is invalid. "+ + "Reason: Must be >= 0 and <= " + MAX_DELAY_SECONDS + ".", 400);+ }+int queueDelaySeconds = parseNonNegativeSecondsAttribute(queue.getAttributes().get("DelaySeconds"));String effectiveSenderId = senderId != null ? senderId : senderIdFor(queueUrl);@@ -1296,6 +1304,24 @@ public class SqsService implements Resettable, ResourceProvider {return compacted;}+ private static void validateDelaySeconds(Map<String, String> attributes) {+ String value = attributes == null ? null : attributes.get("DelaySeconds");+ // An empty value is how a CloudFormation update resets the attribute.+ if (value == null || value.isEmpty()) {+ return;+ }+ int parsed;+ try {+ parsed = Integer.parseInt(value);+ } catch (NumberFormatException ignored) {+ parsed = -1;+ }+ if (parsed < 0 || MAX_DELAY_SECONDS < parsed) {+ throw new AwsException("InvalidAttributeValue",+ "Invalid value for the parameter DelaySeconds.", 400);+ }+ }+private static AwsException invalidMessageRetentionPeriod() {return new AwsException("InvalidAttributeValue","Invalid value for the parameter MessageRetentionPeriod.", 400);@@ -1715,6 +1741,7 @@ public class SqsService implements Resettable, ResourceProvider {"The specified queue does not exist.", 400));validateMaximumMessageSize(attributes);attributes = validateMessageRetentionPeriod(attributes);+ validateDelaySeconds(attributes);attributes = compactRedrivePolicies(attributes);if (attributes != null) {for (Map.Entry<String, String> entry : attributes.entrySet()) {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.javaindex cede28626a..4253120c4b 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@@ -1019,6 +1019,63 @@ class SqsIntegrationTest {}}+ @Test+ void delaySecondsAboveTheAwsMaximumIsRejected() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "CreateQueue")+ .formParam("QueueName", "query-delay-range-queue")+ .formParam("Attribute.1.Name", "DelaySeconds")+ .formParam("Attribute.1.Value", "901")+ .when().post("/").then()+ .statusCode(400)+ .body(containsString("<Code>InvalidAttributeValue</Code>"))+ .body(containsString("<Message>Invalid value for the parameter DelaySeconds.</Message>"));++ String delayQueueUrl = given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "CreateQueue")+ .formParam("QueueName", "query-delay-range-queue")+ .when().post("/").then().statusCode(200)+ .extract().xmlPath().getString("CreateQueueResponse.CreateQueueResult.QueueUrl");++ try {+ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "SendMessage")+ .formParam("QueueUrl", delayQueueUrl)+ .formParam("MessageBody", "x")+ .formParam("DelaySeconds", "901")+ .when().post("/").then()+ .statusCode(400)+ .body(containsString("<Code>InvalidParameterValue</Code>"))+ .body(containsString("Value 901 for parameter DelaySeconds is invalid. Reason: Must be >= 0 and <= 900."));++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "SendMessageBatch")+ .formParam("QueueUrl", delayQueueUrl)+ .formParam("SendMessageBatchRequestEntry.1.Id", "ok")+ .formParam("SendMessageBatchRequestEntry.1.MessageBody", "x")+ .formParam("SendMessageBatchRequestEntry.1.DelaySeconds", "900")+ .formParam("SendMessageBatchRequestEntry.2.Id", "late")+ .formParam("SendMessageBatchRequestEntry.2.MessageBody", "x")+ .formParam("SendMessageBatchRequestEntry.2.DelaySeconds", "901")+ .when().post("/").then()+ .statusCode(200)+ .body("SendMessageBatchResponse.SendMessageBatchResult.SendMessageBatchResultEntry.Id", equalTo("ok"))+ .body("SendMessageBatchResponse.SendMessageBatchResult.BatchResultErrorEntry.Id", equalTo("late"))+ .body("SendMessageBatchResponse.SendMessageBatchResult.BatchResultErrorEntry.Code",+ equalTo("InvalidParameterValue"));+ } finally {+ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "DeleteQueue")+ .formParam("QueueUrl", delayQueueUrl)+ .when().post("/");+ }+ }+@Testvoid receiveMessageReturnsPerMessageSenderId() {String testQueueUrl = given()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.javaindex e2956df140..d87e430708 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@@ -1048,6 +1048,43 @@ class SqsJsonProtocolTest {return "{\"QueueUrl\":\"" + url + "\",\"Entries\":[" + entries + "]}";}+ @Test+ void delaySecondsOutsideTheAwsRangeIsRejected() {+ String delayQueueUrl = given()+ .contentType(CONTENT_TYPE)+ .header("X-Amz-Target", "AmazonSQS.CreateQueue")+ .body("{\"QueueName\":\"json-delay-range-queue\"}")+ .when().post("/").then().statusCode(200)+ .extract().jsonPath().getString("QueueUrl");++ given()+ .contentType(CONTENT_TYPE)+ .header("X-Amz-Target", "AmazonSQS.SendMessage")+ .body("{\"QueueUrl\":\"" + delayQueueUrl + "\",\"MessageBody\":\"x\",\"DelaySeconds\":901}")+ .when().post("/").then()+ .statusCode(400)+ .body("__type", equalTo("InvalidParameterValue"))+ .body("message", equalTo("Value 901 for parameter DelaySeconds is invalid. Reason: Must be >= 0 and <= 900."));++ // Larger than an int: must not wrap around to a valid delay.+ given()+ .contentType(CONTENT_TYPE)+ .header("X-Amz-Target", "AmazonSQS.SendMessage")+ .body("{\"QueueUrl\":\"" + delayQueueUrl + "\",\"MessageBody\":\"x\",\"DelaySeconds\":4294967296}")+ .when().post("/").then()+ .statusCode(400)+ .body("__type", equalTo("InvalidParameterValue"));++ given()+ .contentType(CONTENT_TYPE)+ .header("X-Amz-Target", "AmazonSQS.SendMessageBatch")+ .body("{\"QueueUrl\":\"" + delayQueueUrl + "\",\"Entries\":["+ + "{\"Id\":\"late\",\"MessageBody\":\"x\",\"DelaySeconds\":4294967296}]}")+ .when().post("/").then()+ .statusCode(400)+ .body("__type", equalTo("InvalidParameterValue"));+ }+@Testvoid redrivePolicyReadsBackAsCompactJson() {String dlqUrl = 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.javaindex 60b9d8a86b..fa0749dbc1 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@@ -254,6 +254,43 @@ class SqsServiceTest {List.of("MessageRetentionPeriod"), region).get("MessageRetentionPeriod"));}+ @ParameterizedTest+ @ValueSource(strings = {"901", "-1", "abc", " 5"})+ void delaySecondsAttributeOutsideAwsRangeIsRejected(String invalid) {+ String region = "eu-west-1";+ AwsException onCreate = assertThrows(AwsException.class,+ () -> sqsService.createQueue("delay-range", Map.of("DelaySeconds", invalid), region));+ assertEquals("InvalidAttributeValue", onCreate.getErrorCode());+ assertEquals("Invalid value for the parameter DelaySeconds.", onCreate.getMessage());++ Queue queue = sqsService.createQueue("delay-range", null, region);+ AwsException onSet = assertThrows(AwsException.class,+ () -> sqsService.setQueueAttributes(queue.getQueueUrl(), Map.of("DelaySeconds", invalid), region));+ assertEquals("InvalidAttributeValue", onSet.getErrorCode());+ assertEquals("Invalid value for the parameter DelaySeconds.", onSet.getMessage());+ }++ @ParameterizedTest+ @ValueSource(ints = {901, -1})+ void sendMessageRejectsDelaySecondsOutsideAwsRange(int delay) {+ String region = "eu-west-1";+ Queue queue = sqsService.createQueue("delay-send", null, region);+ AwsException e = assertThrows(AwsException.class,+ () -> sqsService.sendMessage(queue.getQueueUrl(), "x", delay, region));+ assertEquals("InvalidParameterValue", e.getErrorCode());+ assertEquals("Value " + delay + " for parameter DelaySeconds is invalid. Reason: Must be >= 0 and <= 900.",+ e.getMessage());+ }++ @Test+ void delaySecondsAcceptsAwsRangeBounds() {+ String region = "eu-west-1";+ Queue queue = sqsService.createQueue("delay-bounds", Map.of("DelaySeconds", "900"), region);+ sqsService.setQueueAttributes(queue.getQueueUrl(), Map.of("DelaySeconds", "0"), region);+ sqsService.sendMessage(queue.getQueueUrl(), "x", 0, region);+ sqsService.sendMessage(queue.getQueueUrl(), "x", 900, region);+ }+@ParameterizedTest@CsvSource({"60, 60", "1209600, 1209600", "060, 60", "+60, 60"})void messageRetentionPeriodIsStoredInCanonicalForm(String value, String stored) {