Skip to content

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Dec 3, 2024

Motivation

When implementing the EventRuleEngine with #11960, I've implemented different and new behaviors from SNS, and some felt like we just missed them in SNS and were better covered by the event test suite.

This PR implements the cidr operator, and a missed edge case where one of the field of the payload is an empty array. Also adds a bit of validation around empty list passed to operators.

Sorry @maxhoheiser and @joe4dev, I've sneaked in a new test case for the EventRuleEngine here as I wanted to verify a very edge case behavior in both engine when the value is an empty array, making the field not exists, which is an edge case we're also having, which is somewhat funny. I didn't want to open a new PR just for this tiny test case 😅 hope that's ok! no change in behavior as we were already right! For the anecdote, this is because I think exists can only be applied to "leaf" nodes, and an empty array will make the field not be a leaf anymore, as we're going "into" the array. Funny enough, we have the same edge case 😄

Changes

  • adds the cidr operator and validation
  • implements the empty array in payload edge case
  • implements empty array in operator validation
  • adds new test cases for SNS
  • add one test case for an edge case in events

@bentsku bentsku added aws:sns Amazon Simple Notification Service semver: patch Non-breaking changes which can be included in patch releases labels Dec 3, 2024
@bentsku bentsku requested a review from cloutierMat December 3, 2024 20:56
@bentsku bentsku self-assigned this Dec 3, 2024
@bentsku bentsku added this to the 4.1 milestone Dec 3, 2024
Copy link

github-actions bot commented Dec 3, 2024

LocalStack Community integration with Pro

    2 files  ±    0      2 suites  ±0   1h 11m 35s ⏱️ - 40m 27s
2 420 tests  - 1 396  2 315 ✅  - 1 183  105 💤  - 213  0 ❌ ±0 
2 422 runs   - 1 396  2 315 ✅  - 1 183  107 💤  - 213  0 ❌ ±0 

Results for commit 28652b1. ± Comparison against base commit 78fdf45.

This pull request removes 1399 and adds 3 tests. Note that renamed tests count towards both.
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_lambda_dynamodb
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_opensearch_crud
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_search_books
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_setup
tests.aws.scenario.kinesis_firehose.test_kinesis_firehose.TestKinesisFirehoseScenario ‑ test_kinesis_firehose_s3
tests.aws.scenario.lambda_destination.test_lambda_destination_scenario.TestLambdaDestinationScenario ‑ test_destination_sns
tests.aws.scenario.lambda_destination.test_lambda_destination_scenario.TestLambdaDestinationScenario ‑ test_infra
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_prefill_dynamodb_table
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input0-SUCCEEDED]
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input1-SUCCEEDED]
…
tests.aws.services.events.test_events_patterns.TestEventPattern ‑ test_event_pattern[exists_list_empty_NEG]
tests.aws.services.sns.test_sns_filter_policy.TestSNSFilterPolicyBody ‑ test_filter_policy_empty_array_payload
tests.aws.services.sns.test_sns_filter_policy.TestSNSFilterPolicyBody ‑ test_filter_policy_ip_address_condition

♻️ This comment has been updated with latest results.

Copy link
Contributor

@cloutierMat cloutierMat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find on the empty array edge case. I am glad our recursive implementation allowed you to fix in such an simple way. Love the new addition to the test and the reusable method to get the sqs message. It cleans up a lot.

I am not fond of creating an array with a gazillion items in it to be discarded right away? Do you know if IPv6 can be used?

Comment on lines 129 to 130
ips = [str(ip) for ip in ipaddress.IPv4Network(cidr)]
return value in ips
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems super inefficient. 🤔 If the mask is 10.0.0.0/8 that would create a huge list. 👀

If we are sure it will always be an ipv4 address we can maybe do that return ipaddress.IPv4Address(value) in ipaddress.IPv4Network(cidr) and something like return ipaddress.ip_address(value) in ipaddress.ip_network(cidr) would cover ipv6 also, I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, yes. Well, we can't be sure the value is a valid ipv4 or v6. Actually, looking at the docs, it seems it should work with ipv6, so this doesn't really work either. I'll update events as well to add IPv6 support.

I'll need to wrap this in a try/except block probably, and do what you proposed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time to port back the fix to events 😂 thanks, always pushing further! 💪 always thankful for your reviews!

Comment on lines +253 to +254
if not _object:
return array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat find!

@bentsku bentsku requested a review from cloutierMat December 3, 2024 22:19
Copy link
Contributor

@cloutierMat cloutierMat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for addressing the comment! Good new test additions as well! Super to get so much parity in the error messages as well

Comment on lines 427 to 430
try:
ipaddress.IPv4Network(value)
except ValueError:
raise InvalidParameterException(
f"{self.error_prefix}FilterPolicy: Malformed CIDR, one '/' required"
)
self._validate_cidr_condition(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beauty!

@bentsku bentsku merged commit 414a968 into master Dec 3, 2024
31 checks passed
@bentsku bentsku deleted the fix-sns-filter-policy-engine branch December 3, 2024 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:sns Amazon Simple Notification Service semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants