feat(sns): support SMS account preferences (#4597)

* feat(sns): support SMS account preferences

* fix(sns): include result element in SetSMSAttributes response

* fix(sns): validate SMS sender IDs and cover JSON updates

* refactor(sns): centralize SMS preference storage key
This commit is contained in:
XuJian authored and GitHub committed 2026-09-29 14:20:34 -04:00
1 parent 18ef1f58e9
commit 78c06239be
7 files changed
+280

No files matched your search

@@ -1291,4 +1291,54 @@ class SnsIntegrationTest {
.then()
.statusCode(200);
}
@Test
@Order(150)
void smsAttributesRoundTripAcrossQueryAndJsonProtocols() {
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "SetSMSAttributes")
.formParam("attributes.entry.1.key", "DefaultSMSType")
.formParam("attributes.entry.1.value", "Transactional")
.formParam("attributes.entry.2.key", "MonthlySpendLimit")
.formParam("attributes.entry.2.value", "10")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("<SetSMSAttributesResult>"));
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "GetSMSAttributes")
.formParam("attributes.member.1", "DefaultSMSType")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("<key>DefaultSMSType</key>"))
.body(containsString("<value>Transactional</value>"))
.body(not(containsString("MonthlySpendLimit")));
given()
.contentType(SNS_CONTENT_TYPE)
.header("X-Amz-Target", "SNS_20100331.SetSMSAttributes")
.body("{\"attributes\":{\"DefaultSMSType\":\"Promotional\",\"DefaultSenderID\":\"Brand123\"}}")
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType(SNS_CONTENT_TYPE)
.header("X-Amz-Target", "SNS_20100331.GetSMSAttributes")
.body("{}")
.when()
.post("/")
.then()
.statusCode(200)
.body("attributes.DefaultSMSType", equalTo("Promotional"))
.body("attributes.DefaultSenderID", equalTo("Brand123"))
.body("attributes.MonthlySpendLimit", equalTo("10"));
}
}
@@ -34,6 +34,7 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class SnsServiceTest {
@@ -65,6 +66,57 @@ class SnsServiceTest {
assertEquals("arn:aws:sns:us-east-1:000000000000:my-topic", topic.getTopicArn());
}
@Test
void smsAttributesAreScopedToAccountAndRegion() {
RegionResolver regionResolver = mock(RegionResolver.class);
when(regionResolver.getAccountId()).thenReturn("111122223333", "444455556666", "111122223333");
SnsService service = new SnsService(new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), regionResolver, null, null, null, BASE_URL, new ObjectMapper());
service.setSmsAttributes(Map.of("DefaultSMSType", "Transactional", "MonthlySpendLimit", "10"), REGION);
assertTrue(service.getSmsAttributes(List.of(), REGION).isEmpty());
assertEquals(Map.of("DefaultSMSType", "Transactional", "MonthlySpendLimit", "10"),
service.getSmsAttributes(List.of(), REGION));
assertTrue(service.getSmsAttributes(List.of(), "us-west-2").isEmpty());
assertEquals(Map.of("DefaultSMSType", "Transactional"),
service.getSmsAttributes(List.of("DefaultSMSType"), REGION));
}
@Test
void smsAttributesRejectInvalidValuesWithoutChangingStoredSettings() {
snsService.setSmsAttributes(Map.of("DefaultSMSType", "Promotional"), REGION);
assertThrows(AwsException.class, () -> snsService.setSmsAttributes(
Map.of("DefaultSMSType", "Bulk"), REGION));
assertThrows(AwsException.class, () -> snsService.setSmsAttributes(
Map.of("DeliveryStatusSuccessSamplingRate", "101"), REGION));
assertThrows(AwsException.class, () -> snsService.setSmsAttributes(
Map.of("DefaultSenderID", "12345678901"), REGION));
assertThrows(AwsException.class, () -> snsService.setSmsAttributes(
Map.of("DefaultSenderID", "TooLongSender"), REGION));
assertThrows(AwsException.class, () -> snsService.setSmsAttributes(
Map.of("DefaultSenderID", "Brand-Name"), REGION));
assertEquals(Map.of("DefaultSMSType", "Promotional"),
snsService.getSmsAttributes(List.of(), REGION));
snsService.setSmsAttributes(Map.of("DefaultSenderID", "Brand123"), REGION);
assertEquals(Map.of("DefaultSMSType", "Promotional", "DefaultSenderID", "Brand123"),
snsService.getSmsAttributes(List.of(), REGION));
}
@Test
void emptySmsAttributeResetsOnlyThatPreference() {
snsService.setSmsAttributes(Map.of("DefaultSMSType", "Transactional",
"MonthlySpendLimit", "10"), REGION);
snsService.setSmsAttributes(Map.of("DefaultSMSType", ""), REGION);
assertEquals(Map.of("MonthlySpendLimit", "10"),
snsService.getSmsAttributes(List.of(), REGION));
}
@Test
void createTopic_fifoWithContentBasedDeduplication() {
Topic topic = snsService.createTopic("my-topic.fifo",