fix(sqs): reject DelaySeconds outside 0-900 (#6852)

* fix(sqs): reject DelaySeconds outside 0-900

* fix(sqs): don't let a json DelaySeconds outside the int range wrap around

* docs(sqs): document the DelaySeconds range
This commit is contained in:
berce authored and GitHub committed 2026-10-28 16:57:56 -04:00
1 parent 52eb4b9a9c
commit 6abd9d7ffb
6 files changed
+162 -1

No files matched your search

@@ -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 &gt;= 0 and &lt;= 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("/");
}
}
@Test
void receiveMessageReturnsPerMessageSenderId() {
String testQueueUrl = given()
@@ -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"));
}
@Test
void redrivePolicyReadsBackAsCompactJson() {
String dlqUrl = given()
@@ -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) {