From ff40a2fc0a39ffd379453dc43cba58bf0be14225 Mon Sep 17 00:00:00 2001 From: dagrammy Date: Fri, 22 May 2026 03:35:12 +0200 Subject: [PATCH] fix(sqs): accept bare queue name in QueueUrl field (#980) AWS SQS resolves a plain queue name (e.g. "TestQueue") to the full queue URL transparently. Floci required the full URL, causing NonExistentQueue errors for clients that pass only the name - a pattern common in AWS SDK for Java v2 applications. Add normalizeQueueUrl() which expands bare names to the canonical {baseUrl}/{accountId}/{queueName} form before storage-key computation, covering all SQS operations that accept a QueueUrl parameter. --- .../floci/services/sqs/SqsService.java | 25 +++++++++++++++--- .../floci/services/sqs/SqsServiceTest.java | 26 +++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) 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 b6095c6e20..3f922f3919 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 @@ -1257,12 +1257,29 @@ public class SqsService { * default account. */ public String senderIdFor(String queueUrl) { - String fromUrl = accountFromQueueUrl(queueUrl); + String fromUrl = accountFromQueueUrl(normalizeQueueUrl(queueUrl)); return fromUrl != null ? fromUrl : regionResolver.getAccountId(); } - private static String regionKey(String region, String queueUrl) { - return region + "::" + extractQueuePath(queueUrl); + /** + * Accepts a full queue URL or a bare queue name and returns a canonical + * full URL. AWS SQS allows clients to pass either form in the QueueUrl + * field; this mirrors that behavior so lookups succeed regardless of what + * the caller supplied. + */ + private String normalizeQueueUrl(String queueUrl) { + if (queueUrl == null) { + return null; + } + if (queueUrl.contains("://")) { + return queueUrl; + } + // Bare queue name — construct the full URL the same way createQueue does. + return baseUrl + "/" + regionResolver.getAccountId() + "/" + queueUrl; + } + + private String regionKey(String region, String queueUrl) { + return region + "::" + extractQueuePath(normalizeQueueUrl(queueUrl)); } /** @@ -1299,7 +1316,7 @@ public class SqsService { */ private Optional getQueueByUrl(String storageKey, String queueUrl) { if (queueStore instanceof AccountAwareStorageBackend aware) { - String accountId = accountFromQueueUrl(queueUrl); + String accountId = accountFromQueueUrl(normalizeQueueUrl(queueUrl)); if (accountId != null) { return aware.getForAccount(accountId, storageKey); } 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 01e7260818..e38b44090e 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 @@ -829,4 +829,30 @@ class SqsServiceTest { verify(sns).clearFifoDeduplicationCacheForSqsQueueSubscriptions( queue.getQueueUrl(), "us-east-1"); } + + @Test + void sendAndReceiveMessage_bareQueueName() { + sqsService.createQueue("bare-name-queue", null); + + Message sent = sqsService.sendMessage("bare-name-queue", "hello", 0); + assertNotNull(sent.getMessageId()); + + List received = sqsService.receiveMessage("bare-name-queue", 1, 30, 0); + assertEquals(1, received.size()); + assertEquals("hello", received.get(0).getBody()); + } + + @Test + void deleteQueue_bareQueueName() { + sqsService.createQueue("delete-bare", null); + assertDoesNotThrow(() -> sqsService.deleteQueue("delete-bare")); + assertThrows(AwsException.class, () -> sqsService.deleteQueue("delete-bare")); + } + + @Test + void getQueueAttributes_bareQueueName() { + sqsService.createQueue("attrs-bare", Map.of("VisibilityTimeout", "45")); + Map attrs = sqsService.getQueueAttributes("attrs-bare", List.of("VisibilityTimeout")); + assertEquals("45", attrs.get("VisibilityTimeout")); + } }