Light, fluffy, and always free - The AWS Local Emulator alternative
fix(sqs): accept bare queue name in QueueUrl field (#980)
dagrammyff40a2fc0a39
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 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<Queue> getQueueByUrl(String storageKey, String queueUrl) {if (queueStore instanceof AccountAwareStorageBackend<Queue> 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.javaindex 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<Message> 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<String, String> attrs = sqsService.getQueueAttributes("attrs-bare", List.of("VisibilityTimeout"));+ assertEquals("45", attrs.get("VisibilityTimeout"));+ }}