8000 APIGW: fix parsing invalid JSON template in MOCK integration by cloutierMat · Pull Request #11967 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

APIGW: fix parsing invalid JSON template in MOCK integration #11967

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 3 commits into from
Nov 29, 2024

Conversation

cloutierMat
Copy link
Contributor
@cloutierMat cloutierMat commented Nov 29, 2024

Motivation

When deploying a CDK stack with an APIGW REST API with "automatic" CORS management by APIGW, CDK will create an OPTIONS method with a MOCK integration. The problem is that this integration has a request template equal to "application/json": "{statusCode: 200}", which is invalid JSON.

From the documentation, nothing lets you think that invalid JSON would be accepted, as it needs the statusCode field.
But it does, they don't JSON parse but use a custom token parser that we're tried to test the limit off. We're settling now on this basic implementation which still has flaws, but cover quite some ground already, as shown by the unit tests. We also updated an integration test to specifically cover the request template CDK was using.

This custom parser will only be executed if the MOCK integration does not return valid JSON, meaning every existing use case will still work, and only people with very, very esoteric negative testing might be impacted by this new custom parser accepting data AWS wouldn't (but we already covered most of the bad negative cases).

Changes

  • create a small (bad) parser to try to get and validate the status code from MOCK integration
  • add a unit test with some weird cases
  • update an integration test for the CDK use-case

@bentsku bentsku changed the title Apigw fix invalid json APIGW: fix parsing invalid JSON template in MOCK integration Nov 29, 2024
@bentsku bentsku added aws:apigateway Amazon API Gateway semver: patch Non-breaking changes which can be included in patch releases labels Nov 29, 2024
@bentsku bentsku added this to the 4.0.3 milestone Nov 29, 2024
@bentsku bentsku self-assigned this Nov 29, 2024
@bentsku bentsku marked this pull request as ready for review November 29, 2024 19:58
@bentsku bentsku self-requested a review as a code owner November 29, 2024 19:58
Copy link
Contributor
@bentsku bentsku left a comment

Choose a reason for hiding this comment

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

LGTM! Let's unblock this for the demo!

Copy link

LocalStack Community integration with Pro

    2 files  ±    0    2 suites  ±0   30m 15s ⏱️ - 1h 18m 44s
1 001 tests  - 2 815  943 ✅  - 2 555  58 💤  - 260  0 ❌ ±0 
1 003 runs   - 2 815  943 ✅  - 2 555  60 💤  - 260  0 ❌ ±0 

Results for commit 9962e2e. ± Comparison against base commit 21210ce.

This pull request removes 2815 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]
…

@bentsku bentsku merged commit e0e3ec2 into master Nov 29, 2024
32 checks passed
@bentsku bentsku deleted the apigw-fix-invalid-json branch November 29, 2024 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:apigateway Amazon API Gateway 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
0