mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(sns): enforce message size limits on Publish and PublishBatch (#783)
* fix(sns): enforce message size limits on Publish and PublishBatch Real AWS SNS rejects oversized publish payloads: - Publish: message + Subject + message attributes must not exceed 262144 bytes, otherwise InvalidParameterException with "Invalid parameter: Message too long". - PublishBatch: total bytes across all entries (message + Subject + attributes per entry) must not exceed 262144, otherwise BatchRequestTooLong. Floci was silently accepting both, which broke the .NET conformance tests asserting these limits. Size accounting matches AWS: UTF-8 bytes for message and subject, plus per-attribute (name + type + value) bytes, with the binary-value byte length used directly for Binary attributes. Refs #768. * fix(sns): address review — apply size limit to SMS, fix batch attr cast Move the Publish size check before the SMS short-circuit so oversized SMS payloads are also rejected. Normalize PublishBatch MessageAttributes in SnsJsonHandler to MessageAttributeValue objects so SnsService.publishBatch's cast no longer risks a ClassCastException.
This commit is contained in:
1 parent
02ab9dd1eb
commit
6f9782d093
3 files changed
+89
-4
No files matched your search
@@ -220,6 +220,41 @@ class SnsServiceTest {
|
||||
assertEquals("ops", tags.get("team"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void publish_messageExceedsSizeLimit_throwsInvalidParameterException() {
|
||||
Topic topic = snsService.createTopic("size-topic", null, null, REGION);
|
||||
String tooBig = "x".repeat(262_145);
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
snsService.publish(topic.getTopicArn(), null, tooBig, null, REGION));
|
||||
assertEquals("InvalidParameterException", ex.getErrorCode());
|
||||
assertTrue(ex.getMessage().toLowerCase().contains("too long"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void publish_messagePlusAttributesExceedsLimit_throws() {
|
||||
Topic topic = snsService.createTopic("size-topic", null, null, REGION);
|
||||
String body = "x".repeat(262_100);
|
||||
Map<String, io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue> attrs = Map.of(
|
||||
"longAttribute", new io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue(
|
||||
"y".repeat(200), "String"));
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
snsService.publish(topic.getTopicArn(), null, null, body, null, attrs, REGION));
|
||||
assertEquals("InvalidParameterException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void publishBatch_totalSizeExceedsLimit_throwsBatchRequestTooLong() {
|
||||
Topic topic = snsService.createTopic("size-topic", null, null, REGION);
|
||||
String halfMeg = "x".repeat(130_000);
|
||||
List<Map<String, Object>> entries = List.of(
|
||||
Map.of("Id", "1", "Message", halfMeg),
|
||||
Map.of("Id", "2", "Message", halfMeg),
|
||||
Map.of("Id", "3", "Message", halfMeg));
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
snsService.publishBatch(topic.getTopicArn(), entries, REGION));
|
||||
assertEquals("BatchRequestTooLong", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void subscriptionsConfirmed_countsCorrectly() {
|
||||
Topic topic = snsService.createTopic("my-topic", null, null, REGION);
|
||||
|
||||
Reference in new issue
Block a user