fix(sns): validate Publish Subject (#4172)

* fix(sns): validate Publish Subject

* fix(sns): validate Subject for SMS publishes too

* fix(sns): accept 100-character subjects and leading spaces
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-09-23 10:52:50 -04:00
1 parent 625bcb80d7
commit b6d5d51bde
2 files changed
+68

No files matched your search

@@ -215,6 +215,12 @@ class SnsServiceTest {
assertNotNull(messageId);
}
@Test
void publish_smsWithInvalidSubject_throwsInvalidParameter() {
assertThrows(AwsException.class, () ->
snsService.publish(null, null, "+819012345678", "Hello phone!", "x".repeat(150), null, REGION));
}
@Test
void publish_requiresTopicArn() {
assertThrows(AwsException.class,
@@ -235,6 +241,48 @@ class SnsServiceTest {
assertNotNull(messageId);
}
@Test
void publish_subjectWithinLimits_succeeds() {
Topic topic = snsService.createTopic("my-topic", null, null, REGION);
String messageId = snsService.publish(topic.getTopicArn(), null, "Hello!", "a".repeat(100), REGION);
assertNotNull(messageId);
}
@Test
void publish_subjectTooLong_throwsInvalidParameter() {
Topic topic = snsService.createTopic("my-topic", null, null, REGION);
AwsException ex = assertThrows(AwsException.class, () ->
snsService.publish(topic.getTopicArn(), null, "Hello!", "a".repeat(101), REGION));
assertEquals("InvalidParameter", ex.getErrorCode());
}
@Test
void publish_subjectWithLineBreak_throwsInvalidParameter() {
Topic topic = snsService.createTopic("my-topic", null, null, REGION);
AwsException ex = assertThrows(AwsException.class, () ->
snsService.publish(topic.getTopicArn(), null, "Hello!", "line one\nline two", REGION));
assertEquals("InvalidParameter", ex.getErrorCode());
}
@Test
void publish_subjectStartingWithSpace_succeeds() {
Topic topic = snsService.createTopic("my-topic", null, null, REGION);
String messageId = snsService.publish(topic.getTopicArn(), null, "Hello!", " leading space", REGION);
assertNotNull(messageId);
}
@Test
void publishBatch_subjectTooLong_marksEntryFailed() {
Topic topic = snsService.createTopic("my-topic", null, null, REGION);
List<Map<String, Object>> entries = List.of(
Map.of("Id", "1", "Message", "Hello!", "Subject", "b".repeat(150)));
SnsService.BatchPublishResult result =
snsService.publishBatch(topic.getTopicArn(), entries, REGION);
assertTrue(result.successful().isEmpty());
assertEquals(1, result.failed().size());
assertEquals("InvalidParameter", result.failed().get(0)[1]);
}
@Test
void tagResource_and_listTags() {
Topic topic = snsService.createTopic("my-topic", null, null, REGION);