fix(sns): match nested message-body policies in arrays (#4234)

This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-09-23 11:03:10 -04:00
1 parent aba5f4e919
commit de50859273
4 files changed
+98

No files matched your search

@@ -681,6 +681,66 @@ class SnsIntegrationTest {
.when().post("/");
}
@Test
@Order(19)
void filterPolicy_messageBodyMatchesS3RecordsArray() {
String queueUrl = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", "sns-records-filter-" + UUID.randomUUID())
.when()
.post("/")
.then()
.statusCode(200)
.extract().xmlPath().getString("CreateQueueResponse.CreateQueueResult.QueueUrl");
String subscription = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "Subscribe")
.formParam("TopicArn", topicArn)
.formParam("Protocol", "sqs")
.formParam("Endpoint", queueUrl)
.formParam("Attributes.entry.1.key", "FilterPolicyScope")
.formParam("Attributes.entry.1.value", "MessageBody")
.formParam("Attributes.entry.2.key", "FilterPolicy")
.formParam("Attributes.entry.2.value",
"{\"Records\":{\"s3\":{\"bucket\":{\"name\":[\"mybucket\"]}}}}")
.when()
.post("/")
.then()
.statusCode(200)
.extract().xmlPath().getString("SubscribeResponse.SubscribeResult.SubscriptionArn");
try {
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "Publish")
.formParam("TopicArn", topicArn)
.formParam("Message", "{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"mybucket\"}}}]}")
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "ReceiveMessage")
.formParam("QueueUrl", queueUrl)
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("mybucket"));
} finally {
given().contentType("application/x-www-form-urlencoded")
.formParam("Action", "Unsubscribe").formParam("SubscriptionArn", subscription)
.when().post("/");
given().contentType("application/x-www-form-urlencoded")
.formParam("Action", "DeleteQueue").formParam("QueueUrl", queueUrl)
.when().post("/");
}
}
@Test
@Order(50)
void rawDelivery_createQueuesAndSubscribe() {
@@ -469,6 +469,33 @@ class SnsServiceTest {
body("{\"store\":{\"region\":\"west\"}}"), null));
}
@Test
void filterPolicy_messageBody_nestedObjectsInsideArray() {
Subscription sub = subscriptionWithPolicy(
"{\"Records\":{\"s3\":{\"bucket\":{\"name\":[\"mybucket\"]}}}}", "MessageBody");
assertTrue(snsService.matchesFilterPolicy(sub, body("""
{"Records":[{"s3":{"bucket":{"name":"other"}}},
{"s3":{"bucket":{"name":"mybucket"}}}]}
"""), null));
assertFalse(snsService.matchesFilterPolicy(sub, body("""
{"Records":[{"s3":{"bucket":{"name":"other"}}}]}
"""), null));
assertFalse(snsService.matchesFilterPolicy(sub, body("{\"Records\":[]}"), null));
}
@Test
void filterPolicy_messageBody_nestedArrayRequiresOneElementToMatchWholePolicy() {
Subscription sub = subscriptionWithPolicy(
"{\"Records\":{\"name\":[\"mybucket\"],\"region\":[\"us-east-1\"]}}", "MessageBody");
assertFalse(snsService.matchesFilterPolicy(sub, body("""
{"Records":[{"name":"mybucket","region":"us-west-2"},
{"name":"other","region":"us-east-1"}]}
"""), null));
assertTrue(snsService.matchesFilterPolicy(sub, body("""
{"Records":[{"name":"mybucket","region":"us-east-1"}]}
"""), null));
}
@Test
void filterPolicy_messageBody_numericRule() {
Subscription sub = subscriptionWithPolicy(