fix(sns): honor RawMessageDelivery attribute for SQS subscriptions (#54)

* fix(sns): honor RawMessageDelivery attribute for SQS subscriptions
* fix(sns): address PR review feedback on RawMessageDelivery

- Preserve original SNS attribute DataType (Number, Binary, etc.) by
  changing the internal messageAttributes type from Map<String,String>
  to Map<String,MessageAttributeValue> throughout the publish pipeline
- Update SnsQueryHandler and SnsJsonHandler to parse DataType from
  incoming requests and construct typed MessageAttributeValue objects
- Return Collections.emptyMap() from toSqsMessageAttributes instead
  of null for safety on non-raw delivery paths
- Use UUID-based queue names in raw delivery tests for isolation
- Add test asserting message attributes (including Number type) are
  forwarded correctly to SQS in raw delivery mode
This commit is contained in:
Roberto Perez Alcolea authored and GitHub committed 2026-03-31 23:18:06 -05:00
1 parent a4af506c15
commit b762becaea
4 files changed
+232 -21

No files matched your search

@@ -10,6 +10,8 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
@@ -32,6 +34,10 @@ class SnsIntegrationTest {
private static String topicArn;
private static String subscriptionArn;
private static String sqsQueueUrl;
private static String rawDeliveryQueueUrl;
private static String rawDeliverySubArn;
private static String envelopeQueueUrl;
private static String envelopeSubArn;
@Test
@Order(1)
@@ -587,6 +593,187 @@ class SnsIntegrationTest {
.when().post("/");
}
@Test
@Order(50)
void rawDelivery_createQueuesAndSubscribe() {
String suffix = UUID.randomUUID().toString().substring(0, 8);
rawDeliveryQueueUrl = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", "sns-raw-delivery-" + suffix)
.when()
.post("/")
.then()
.statusCode(200)
.extract().xmlPath().getString("CreateQueueResponse.CreateQueueResult.QueueUrl");
envelopeQueueUrl = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", "sns-envelope-delivery-" + suffix)
.when()
.post("/")
.then()
.statusCode(200)
.extract().xmlPath().getString("CreateQueueResponse.CreateQueueResult.QueueUrl");
rawDeliverySubArn = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "Subscribe")
.formParam("TopicArn", topicArn)
.formParam("Protocol", "sqs")
.formParam("Endpoint", rawDeliveryQueueUrl)
.when()
.post("/")
.then()
.statusCode(200)
.extract().xmlPath().getString("SubscribeResponse.SubscribeResult.SubscriptionArn");
envelopeSubArn = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "Subscribe")
.formParam("TopicArn", topicArn)
.formParam("Protocol", "sqs")
.formParam("Endpoint", envelopeQueueUrl)
.when()
.post("/")
.then()
.statusCode(200)
.extract().xmlPath().getString("SubscribeResponse.SubscribeResult.SubscriptionArn");
}
@Test
@Order(51)
void rawDelivery_setSubscriptionAttribute() {
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "SetSubscriptionAttributes")
.formParam("SubscriptionArn", rawDeliverySubArn)
.formParam("AttributeName", "RawMessageDelivery")
.formParam("AttributeValue", "true")
.when()
.post("/")
.then()
.statusCode(200);
}
@Test
@Order(52)
void rawDelivery_publishAndVerifyRawMessage() {
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "Publish")
.formParam("TopicArn", topicArn)
.formParam("Message", "Raw delivery test message")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("<MessageId>"));
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "ReceiveMessage")
.formParam("QueueUrl", rawDeliveryQueueUrl)
.formParam("MaxNumberOfMessages", "1")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("Raw delivery test message"))
.body(not(containsString("Notification")));
}
@Test
@Order(53)
void rawDelivery_defaultSubscriptionWrapsInEnvelope() {
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "ReceiveMessage")
.formParam("QueueUrl", envelopeQueueUrl)
.formParam("MaxNumberOfMessages", "1")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("Raw delivery test message"))
.body(containsString("Notification"));
}
@Test
@Order(54)
void rawDelivery_messageAttributesForwardedOnRawDelivery() {
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "Publish")
.formParam("TopicArn", topicArn)
.formParam("Message", "Attribute forwarding test")
.formParam("MessageAttributes.entry.1.Name", "color")
.formParam("MessageAttributes.entry.1.Value.DataType", "String")
.formParam("MessageAttributes.entry.1.Value.StringValue", "blue")
.formParam("MessageAttributes.entry.2.Name", "count")
.formParam("MessageAttributes.entry.2.Value.DataType", "Number")
.formParam("MessageAttributes.entry.2.Value.StringValue", "42")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("<MessageId>"));
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "ReceiveMessage")
.formParam("QueueUrl", rawDeliveryQueueUrl)
.formParam("MaxNumberOfMessages", "1")
.formParam("MessageAttributeNames.member.1", "All")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("Attribute forwarding test"))
.body(containsString("color"))
.body(containsString("blue"))
.body(containsString("count"))
.body(containsString("Number"));
}
@Test
@Order(55)
void rawDelivery_cleanup() {
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "Unsubscribe")
.formParam("SubscriptionArn", rawDeliverySubArn)
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "Unsubscribe")
.formParam("SubscriptionArn", envelopeSubArn)
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DeleteQueue")
.formParam("QueueUrl", rawDeliveryQueueUrl)
.when()
.post("/");
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DeleteQueue")
.formParam("QueueUrl", envelopeQueueUrl)
.when()
.post("/");
}
@Test
@Order(100)
void unsubscribe() {