fix(sqs): compare CreateQueue attributes against effective values (#5780)

* fix(sqs): compare CreateQueue attributes against effective values

CreateQueue on an existing name compared requested attributes against the
raw stored map. SqsManagedSseEnabled is derived on read and never stored, so
re-creating a default queue with SqsManagedSseEnabled=false returned the
existing queue instead of QueueAlreadyExists.

Extract the read-time derivation from GetQueueAttributes into one helper
and use it for both the read path and the conflict check.

* fix(sqs): treat a padded MaximumMessageSize as equal to its canonical form on re-create

* fix(sqs): treat an empty MaximumMessageSize as its default on re-create

CreateQueue accepts an empty MaximumMessageSize and the effective value it
reports is the configured default, but the conflict check skipped
canonicalising empty requests, so an identical retry raised
QueueAlreadyExists instead of returning the existing queue.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-16 09:39:22 -04:00
1 parent cb378afd41
commit 068635b4a6
4 files changed
+149 -14

No files matched your search

@@ -590,6 +590,76 @@ class SqsIntegrationTest {
.post("/");
}
@Test
void createQueue_conflictOnDerivedSqsManagedSseEnabled_returns400() {
String queueName = "conflict-sse-queue";
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", queueName)
.when()
.post("/")
.then()
.statusCode(200);
// The queue reports SqsManagedSseEnabled=true without storing it.
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", queueName)
.formParam("Attribute.1.Name", "SqsManagedSseEnabled")
.formParam("Attribute.1.Value", "false")
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("QueueAlreadyExists"));
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", queueName)
.formParam("Attribute.1.Name", "SqsManagedSseEnabled")
.formParam("Attribute.1.Value", "true")
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DeleteQueue")
.formParam("QueueUrl", "http://localhost:4566/000000000000/" + queueName)
.when()
.post("/");
}
@Test
void createQueue_recreateWithSameEmptyMaximumMessageSize_returnsExistingQueue() {
String queueName = "empty-max-size-queue";
for (int i = 0; i < 2; i++) {
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", queueName)
.formParam("Attribute.1.Name", "MaximumMessageSize")
.formParam("Attribute.1.Value", "")
.when()
.post("/")
.then()
.statusCode(200)
.body("CreateQueueResponse.CreateQueueResult.QueueUrl", endsWith("/" + queueName));
}
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DeleteQueue")
.formParam("QueueUrl", "http://localhost:4566/000000000000/" + queueName)
.when()
.post("/");
}
@Test
void jsonProtocol_nonExistentQueue_returnsQueueDoesNotExist() {
given()
@@ -162,6 +162,51 @@ class SqsServiceTest {
assertEquals(Map.of("SqsManagedSseEnabled", "true"), attrs);
}
@Test
void createQueue_conflictsOnADerivedAttributeThatIsNeverStored() {
String region = "eu-west-1";
Queue queue = sqsService.createQueue("derived-conflict-queue", null, region);
// SqsManagedSseEnabled reads back as "true" but is not in the stored map, so a
// re-create asking for "false" must still see the difference.
AwsException ex = assertThrows(AwsException.class,
() -> sqsService.createQueue("derived-conflict-queue",
Map.of("SqsManagedSseEnabled", "false"), region));
assertEquals("QueueAlreadyExists", ex.getErrorCode());
Queue same = sqsService.createQueue("derived-conflict-queue",
Map.of("SqsManagedSseEnabled", "true", "VisibilityTimeout", "30"), region);
assertEquals(queue.getQueueUrl(), same.getQueueUrl());
assertEquals("true", sqsService.getQueueAttributes(queue.getQueueUrl(),
List.of("SqsManagedSseEnabled"), region).get("SqsManagedSseEnabled"));
}
@Test
void createQueue_recreateWithSameNonCanonicalMaximumMessageSizeIsNotAConflict() {
String region = "eu-west-1";
Queue queue = sqsService.createQueue("padded-size-queue", Map.of("MaximumMessageSize", "01024"), region);
Queue same = sqsService.createQueue("padded-size-queue", Map.of("MaximumMessageSize", "01024"), region);
assertEquals(queue.getQueueUrl(), same.getQueueUrl());
AwsException ex = assertThrows(AwsException.class,
() -> sqsService.createQueue("padded-size-queue", Map.of("MaximumMessageSize", "2048"), region));
assertEquals("QueueAlreadyExists", ex.getErrorCode());
}
@Test
void createQueue_recreateWithSameEmptyMaximumMessageSizeIsNotAConflict() {
String region = "eu-west-1";
Queue queue = sqsService.createQueue("empty-size-queue", Map.of("MaximumMessageSize", ""), region);
Queue same = sqsService.createQueue("empty-size-queue", Map.of("MaximumMessageSize", ""), region);
assertEquals(queue.getQueueUrl(), same.getQueueUrl());
AwsException ex = assertThrows(AwsException.class,
() -> sqsService.createQueue("empty-size-queue", Map.of("MaximumMessageSize", "2048"), region));
assertEquals("QueueAlreadyExists", ex.getErrorCode());
}
@Test
void createQueue_rejectsMaximumMessageSizeOutsideAwsRange() {
for (String invalid : List.of("1048577", "1023", "0", "-1", "abc")) {