mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(sns): match nested message-body policies in arrays (#4234)
This commit is contained in:
1 parent
aba5f4e919
commit
de50859273
4 files changed
+98
No files matched your search
@@ -90,6 +90,9 @@ Supported subscription protocols:
|
||||
- `http` / `https`: posts to an HTTP endpoint
|
||||
- `application`: fans out to a mobile push platform endpoint (see [Mobile push](#mobile-push-mock))
|
||||
|
||||
For `FilterPolicyScope=MessageBody`, nested policy objects descend into JSON objects and arrays.
|
||||
An object inside an array matches when one array element satisfies the complete nested policy.
|
||||
|
||||
## Message size
|
||||
|
||||
`MaximumMessageSize` is the per-topic limit, in bytes, on a published payload. It accepts `1024`
|
||||
|
||||
@@ -1236,6 +1236,14 @@ public class SnsService implements Resettable, ResourceProvider {
|
||||
if (!policy.isObject()) {
|
||||
return false;
|
||||
}
|
||||
if (body != null && body.isArray()) {
|
||||
for (JsonNode element : body) {
|
||||
if (matchesBodyPolicy(policy, element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
var fields = policy.fields();
|
||||
while (fields.hasNext()) {
|
||||
var entry = fields.next();
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user