8000 fix SNS empty MessageAttributes validation by bentsku · Pull Request #11857 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

fix SNS empty MessageAttributes validation #11857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2024
Merged

fix SNS empty MessageAttributes validation #11857

merged 1 commit into from
Nov 15, 2024

Conversation

bentsku
Copy link
Contributor
@bentsku bentsku commented Nov 15, 2024

Motivation

As reported with #11817, we've had an issue in our validation of SNS attributes, with the order of the validation, and that directly accessed the DataType field.

Validation is now updated with more test cases.

Changes

  • add few test cases for Publish and PublishBatch
  • fix the behavior and change validation order

fixes #11817

@bentsku bentsku added aws:sns Amazon Simple Notification Service semver: patch Non-breaking changes which can be included in patch releases labels Nov 15, 2024
@bentsku bentsku requested a review from cloutierMat November 15, 2024 19:20
@bentsku bentsku self-assigned this Nov 15, 2024
@bentsku bentsku requested a review from baermat as a code owner November 15, 2024 19:20
Copy link

LocalStack Community integration with Pro

    2 files  ±    0      2 suites  ±0   1h 6m 13s ⏱️ - 36m 34s
2 129 tests  - 1 397  1 948 ✅  - 1 185  181 💤  - 212  0 ❌ ±0 
2 131 runs   - 1 397  1 948 ✅  - 1 185  183 💤  - 212  0 ❌ ±0 

Results for commit e2f12ac. ± Comparison against base commit ee959cf.

This pull request removes 1397 tests.
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]
…

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.

Good fix and nice upgrade to validation and tests!

I only left one question, not blocking, but curious to know why the validation appears so cryptic! 🤣

Comment on lines +961 to +964
if not any(attr_value.endswith("Value") for attr_value in attr):
raise InvalidParameterValueException(
f"The message attribute '{attr_name}' must contain non-empty message attribute value for message attribute type '{data_type}'."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: It appears that only StringValue and BinaryValue are supported in the message attributes. Is there a reason to allow <Any>Value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point... I've tried to run a test with BadValue but I get a serialization error from the client 😭

prefix = 'MessageAttributes.entry.1.Value'

    def _serialize_type_structure(self, serialized, value, shape, prefix=''):
        members = shape.members
        for key, value in value.items():
>           member_shape = members[key]
E           KeyError: 'BadValue'

I'd need to get the raw request to validate...

I guess then it will be a matter of raising the right exception. I think if I accept <Any>Value, then it will raise InvalidParameterValueException(f"The message attribute '{attr_name}' with type '{data_type}' must use field '{value_key_data_type}'."). Not sure if it's the right behavior but at least we raise something. I guess I won't fight it too much, but it's very good point... 🤔

@bentsku bentsku merged commit 75436ef into master Nov 15, 2024
38 checks passed
@bentsku bentsku deleted the fix-sns-attrs branch November 15, 2024 22:28
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.

bug: Malformed attributes to SNS publish-batch call produce 500 response
2 participants
0