Skip to content

APIGW: add negative tests for IntegrationResponse and improve error handling in PutIntegrationResponse and GetIntegrationResponse #12773

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 5 commits into from
Jun 26, 2025

Conversation

ArthurAkh
Copy link
Contributor

@ArthurAkh ArthurAkh commented Jun 18, 2025

Motivation

Add negative test coverage for the IntegrationResponse operation in API Gateway v1, to ensure LocalStack properly mimics AWS behavior when invalid inputs are provided. This improves parity and robustness of the emulated service.

Changes

  • Added negative test coverage for PutIntegrationResponse and GetIntegrationResponse operations:

    • test_integration_response_wrong_api
    • test_integration_response_wrong_resource
    • test_integration_response_wrong_method
    • test_integration_response_wrong_invalid_statuscode
    • test_integration_response_invalid_responsetemplates (skipped for now due to LocalStack/AWS parity gap)
    • test_integration_response_invalid_integration
    • test_integration_response_wrong_status_code
  • Updated put_integration_response and get_integration_response in provider.py to:

    • Validate statusCode using regex ([1-5]\d\d), raise ValidationException for invalid values
    • Raise appropriate NotFoundException messages for missing resources, methods, or integration responses

TODO

What's left to do:

  • Implement validation logic for responseTemplates in put_integration_response to ensure LocalStack raises appropriate exceptions (e.g., SerializationException, BadRequestException) when invalid values are provided
  • Enable the currently skipped test test_integration_response_invalid_responsetemplates once LocalStack behavior matches AWS

@ArthurAkh ArthurAkh self-assigned this Jun 18, 2025
@ArthurAkh ArthurAkh added the semver: patch Non-breaking changes which can be included in patch releases label Jun 18, 2025
Copy link

github-actions bot commented Jun 18, 2025

Test Results - Preflight, Unit

21 727 tests  ±0   20 070 ✅ ±0   6m 33s ⏱️ +21s
     1 suites ±0    1 657 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit b4e4d0f. ± Comparison against base commit 21b3a06.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 18, 2025

LocalStack Community integration with Pro

    2 files  ±    0      2 suites  ±0   18m 53s ⏱️ - 1h 26m 13s
1 144 tests  - 3 752  1 078 ✅  - 3 044  66 💤  - 708  0 ❌ ±0 
1 146 runs   - 3 752  1 078 ✅  - 3 044  68 💤  - 708  0 ❌ ±0 

Results for commit b4e4d0f. ± Comparison against base commit 21b3a06.

This pull request removes 3759 and adds 7 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.apigateway.test_apigateway_api.TestApigatewayIntegration ‑ test_integration_response_invalid_integration
tests.aws.services.apigateway.test_apigateway_api.TestApigatewayIntegration ‑ test_integration_response_invalid_responsetemplates
tests.aws.services.apigateway.test_apigateway_api.TestApigatewayIntegration ‑ test_integration_response_invalid_statuscode
tests.aws.services.apigateway.test_apigateway_api.TestApigatewayIntegration ‑ test_integration_response_wrong_api
tests.aws.services.apigateway.test_apigateway_api.TestApigatewayIntegration ‑ test_integration_response_wrong_method
tests.aws.services.apigateway.test_apigateway_api.TestApigatewayIntegration ‑ test_integration_response_wrong_resource
tests.aws.services.apigateway.test_apigateway_api.TestApigatewayIntegration ‑ test_integration_response_wrong_status_code
This pull request removes 709 skipped tests and adds 1 skipped test. Note that renamed tests count towards both.
tests.aws.scenario.kinesis_firehose.test_kinesis_firehose.TestKinesisFirehoseScenario ‑ test_kinesis_firehose_s3
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input4-FAILED]
tests.aws.scenario.mythical_mysfits.test_mythical_misfits.TestMythicalMisfitsScenario ‑ test_deployed_infra_state
tests.aws.scenario.mythical_mysfits.test_mythical_misfits.TestMythicalMisfitsScenario ‑ test_populate_data
tests.aws.scenario.mythical_mysfits.test_mythical_misfits.TestMythicalMisfitsScenario ‑ test_user_clicks_are_stored
tests.aws.services.cloudcontrol.test_cloudcontrol_api.TestCloudControlResourceApi ‑ test_api_exceptions
tests.aws.services.cloudcontrol.test_cloudcontrol_api.TestCloudControlResourceApi ‑ test_create_exceptions
tests.aws.services.cloudcontrol.test_cloudcontrol_api.TestCloudControlResourceApi ‑ test_create_invalid_desiredstate
tests.aws.services.cloudcontrol.test_cloudcontrol_api.TestCloudControlResourceApi ‑ test_double_create_with_client_token
tests.aws.services.cloudcontrol.test_cloudcontrol_api.TestCloudControlResourceApi ‑ test_lifecycle
…
tests.aws.services.apigateway.test_apigateway_api.TestApigatewayIntegration ‑ test_integration_response_invalid_responsetemplates

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 18, 2025

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   3m 8s ⏱️ ±0s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit b4e4d0f. ± Comparison against base commit 21b3a06.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 18, 2025

Test Results (amd64) - Integration, Bootstrap

    5 files      5 suites   35m 48s ⏱️
1 168 tests 1 102 ✅ 66 💤 0 ❌
1 174 runs  1 102 ✅ 72 💤 0 ❌

Results for commit b4e4d0f.

♻️ This comment has been updated with latest results.

Copy link

Test Results - Alternative Providers

987 tests   589 ✅  30m 28s ⏱️
  4 suites  398 💤
  4 files      0 ❌

Results for commit e19873b.

@ArthurAkh ArthurAkh marked this pull request as draft June 18, 2025 15:21
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.

Awesome work! This is looking great! 🚀

I only have a few comments, the only blocking-one related to the modified auto-generated file, which is maybe lacking a disclaimer, as it's a common pitfall.

I also have a comment regarding the new changes required to make the other tests outside of this PR work, and maybe a suggestion or a follow-up we could do to write a test to trigger the scenario that was making your PR fail, but in a clear way and not with ImportAPI calls. It could help to avoid future regressions, and make the failing scenario clearer. See the comment related to that 😄

All in all, great work, this is looking really nice, and this was not an easy task as we're directly manipulating objects and the flow is not very clear. Congrats for navigating this! 🚀

@ArthurAkh ArthurAkh added this to the 4.6 milestone Jun 26, 2025
@ArthurAkh ArthurAkh marked this pull request as ready for review June 26, 2025 13:29
@ArthurAkh ArthurAkh force-pushed the apigw-integrationresponse-negative-tests branch from ab53b23 to b4e4d0f Compare June 26, 2025 14:23
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! Congrats, I know this was a very tricky one, wrangling moto internals and adding the validation in the right order! The CI is green and I've checked that our dependencies tests are also green, so this is good to merge! 🚀 awesome work!

response["selectionPattern"] = integration_response.selection_pattern
if (
"selectionPattern" not in response
and integration_response
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this line could probably be removed because we are failing early if it not true (in line 2082)
and integration_response

But let's not block the merge, we can remove it in a follow-up PR!

@ArthurAkh ArthurAkh merged commit 1860a54 into master Jun 26, 2025
39 checks passed
@ArthurAkh ArthurAkh deleted the apigw-integrationresponse-negative-tests branch June 26, 2025 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy