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")); + } }