mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(sns): preserve binary message attributes through publish and fan-out (#989)
* fix(sns): preserve binary message attributes through publish and fan-out Parse BinaryValue on Publish/PublishBatch in both JSON and Query handlers, and base64-encode binary attributes in the SNS-to-SQS and Lambda JSON envelopes so binary attributes survive fan-out instead of being dropped. Closes #988 * fix(sns): return AWS-style 400 for invalid base64 and align DataType default Address Copilot PR feedback: - Catch IllegalArgumentException from Base64 decoding in both Publish and PublishBatch attribute parsing (JSON + Query handlers) and surface an InvalidParameterValue / HTTP 400 error consistent with other SNS errors. - Default DataType to "Binary" in SnsJsonHandler when only BinaryValue is provided, matching SnsQueryHandler behavior. - Extract a shared parseMessageAttributes helper in each handler to remove duplication between Publish and PublishBatch. * fix(sns): give new tests distinct @Order values and drop Base64 FQN Address maintainer review feedback: - Move new binary-attribute tests off @Order(9) (already used by publish_fanOutToSqsSubscriber) to @Order(18)/@Order(19) so their drainQueue calls don't race with other order-9 tests. - Import java.util.Base64 in SnsQueryHandler, SnsJsonHandler, and SnsService and drop the fully-qualified references.
This commit is contained in:
1 parent
ba04ec4eee
commit
27d72f119c
4 files changed
+143
-34
No files matched your search
@@ -211,6 +211,68 @@ class SnsIntegrationTest {
|
||||
assertTrue(jsonBodyInResponse.contains("\"Timestamp\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void publish_fanOutPreservesBinaryMessageAttribute() {
|
||||
drainQueue(sqsQueueUrl);
|
||||
|
||||
// "somebinarydata" base64-encoded -> c29tZWJpbmFyeWRhdGE=
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "Publish")
|
||||
.formParam("TopicArn", topicArn)
|
||||
.formParam("Message", "hello")
|
||||
.formParam("MessageAttributes.entry.1.Name", "content")
|
||||
.formParam("MessageAttributes.entry.1.Value.DataType", "String")
|
||||
.formParam("MessageAttributes.entry.1.Value.StringValue", "somecontent")
|
||||
.formParam("MessageAttributes.entry.2.Name", "binarycontent")
|
||||
.formParam("MessageAttributes.entry.2.Value.DataType", "Binary")
|
||||
.formParam("MessageAttributes.entry.2.Value.BinaryValue", "c29tZWJpbmFyeWRhdGE=")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<MessageId>"));
|
||||
|
||||
String jsonBodyInResponse = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ReceiveMessage")
|
||||
.formParam("QueueUrl", sqsQueueUrl)
|
||||
.formParam("MaxNumberOfMessages", "1")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("hello"))
|
||||
.extract().xmlPath().getString(
|
||||
"ReceiveMessageResponse.ReceiveMessageResult.Message.Body");
|
||||
|
||||
assertTrue(jsonBodyInResponse.contains("\"binarycontent\""),
|
||||
"Binary attribute should be present in delivered envelope: " + jsonBodyInResponse);
|
||||
assertTrue(jsonBodyInResponse.contains("\"Binary\""),
|
||||
"Binary attribute Type should be present: " + jsonBodyInResponse);
|
||||
assertTrue(jsonBodyInResponse.contains("c29tZWJpbmFyeWRhdGE="),
|
||||
"Binary attribute Value should be base64-encoded: " + jsonBodyInResponse);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
void publish_invalidBinaryAttributeReturns400() {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "Publish")
|
||||
.formParam("TopicArn", topicArn)
|
||||
.formParam("Message", "hello")
|
||||
.formParam("MessageAttributes.entry.1.Name", "binarycontent")
|
||||
.formParam("MessageAttributes.entry.1.Value.DataType", "Binary")
|
||||
.formParam("MessageAttributes.entry.1.Value.BinaryValue", "not valid base64!!!")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("InvalidParameterValue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void publishBatch() {
|
||||
|
||||
Reference in new issue
Block a user