Skip to content

Retry transient 403s in custom authorizer missing-context integration tests - #2628

Merged
dscpinheiro merged 1 commit into
masterfrom
normj/custom-authorizer-403-retry
Dec 1, 2026
Merged

dscpinheiro merged 1 commit into
masterfrom
normj/custom-authorizer-403-retry

Conversation

@normj

@normj normj commented Nov 30, 2026

Copy link
Copy Markdown
Member

Description of changes:

RestApiTests.RestUserInfo_WithMissingAuthorizerContextKey_ReturnsUnauthorized fails intermittently in AWS CI with Expected: Unauthorized, Actual: Forbidden. It failed on runs for PRs that only changed docs (for example run 46496486705), and passed on re-run.

The REST authorizer always returns an Allow policy for the partial-context token, and every authorizer has AuthorizerResultTtlInSeconds: 0, so the 403 does not come from the authorizer or a cached result. The likely cause is the same one the suite already handles for the valid-token tests: a freshly deployed API Gateway stage can briefly return 403 on the authorizer path. The warm-up and GetWithValidTokenAsync retry only cover the valid-token requests. The five missing-context-key tests sent a single partial-context request with no retry, and only the REST variant (the slower stage to settle) failed.

Changes:

  • Add GetWithTokenAsync(url, token) to the fixture. GetWithValidTokenAsync now delegates to it. The five *_WithMissingAuthorizerContextKey_ReturnsUnauthorized tests use it, so their requests get the same 403 retry. A 403 is never the expected result for these tests, so the retry can't hide a regression: if the authorizer really denied the request, the retry times out and the test still fails.
  • Add ResponseAssert.StatusCodeAsync. On a status mismatch, the failure message includes the response body and the x-amzn-ErrorType, x-amzn-RequestId and x-amz-apigw-id headers. If the test fails again, this shows whether the 403 came from the authorizer (an explicit-deny body) or from API Gateway before the authorizer ran.

Test-only change, so no change file.

Validation: the integration test project builds with no new warnings. The tests need a deployed stack, so they will be exercised by AWS CI on this PR.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The five *_WithMissingAuthorizerContextKey_ReturnsUnauthorized tests sent a
single request with the partial-context token. A freshly deployed API Gateway
stage can briefly return 403 on the authorizer path, which the valid-token
tests already retry. The REST API variant failed intermittently in AWS CI
with 403 instead of the expected 401.

- Add GetWithTokenAsync to the fixture and use it for the partial-context
  requests, so they get the same 403 retry as the valid-token requests.
- Add ResponseAssert.StatusCodeAsync, which includes the response body and
  the API Gateway error type and request ID headers when the status code
  does not match.
@normj normj added the Release Not Needed Add this label if a PR does not need to be released. label Nov 30, 2026
@normj
normj marked this pull request as ready for review December 1, 2026 20:28
@normj
normj requested review from a team as code owners December 1, 2026 20:28
@dscpinheiro
dscpinheiro merged commit 95d71da into master Dec 1, 2026
12 of 17 checks passed
@dscpinheiro
dscpinheiro deleted the normj/custom-authorizer-403-retry branch December 1, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Release Not Needed Add this label if a PR does not need to be released.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants