Skip to content

fix(e2e): broaden CUSTOM_JWT rejection regex to match service response#1622

Closed
notgitika wants to merge 1 commit into
aws:mainfrom
notgitika:fix/e2e-custom-jwt-regex
Closed

fix(e2e): broaden CUSTOM_JWT rejection regex to match service response#1622
notgitika wants to merge 1 commit into
aws:mainfrom
notgitika:fix/e2e-custom-jwt-regex

Conversation

@notgitika

Copy link
Copy Markdown
Contributor

What

Fixes the harness-custom-jwt.test.ts e2e test that has been failing on mainline since the harness flows were brought into the standard build (PR #1598).

Root Cause

The test deploys a harness with a CUSTOM_JWT authorizer (Cognito), then invokes without an explicit --bearer-token. The CLI auto-attaches a bearer token via the managed OAuth credential. The Cognito access_token lacks a standard aud claim (Cognito uses client_id instead), so the service's HarnessAuthValidator.validateTokenAudience() in YggdrasillDataPlaneService rejects it with:

AgentCore API error (403): {"message":"*** missing required audience claim."}

The test's regex only matched configured for CUSTOM_JWT, authoriz(ation|er).*mismatch, or different.*authorization — none of which match the actual service response.

Fix

Broaden the regex to also accept missing required audience claim. The test's intent (SigV4/invalid-auth is rejected with 403) is unchanged — the exitCode !== 0 assertion still validates the rejection. The negative assertion on line 262 (not.toMatch) remains safe because a successful bearer-token invoke will never contain this message.

Testing

  • Verified the regex matches the actual error from the CI logs
  • The negative assertion (expect(output).not.toMatch(...)) on the bearer-token success path is unaffected since a successful invoke returns the agent response, not an auth error

The harness-custom-jwt e2e test asserts that SigV4 invocations against a
CUSTOM_JWT harness are rejected. The assertion regex did not account for
the actual 403 message returned by the AgentCore service:
"missing required audience claim."

This occurs because the CLI auto-attaches a bearer token (via the
managed OAuth credential) which lacks a standard JWT aud claim — the
Cognito access_token uses client_id instead. The harness's
HarnessAuthValidator.validateTokenAudience() rejects it with this
message rather than the auth-type-mismatch message the regex expected.

Broaden the regex to accept this valid rejection variant. The test's
intent (SigV4/invalid-auth is rejected with 403) remains unchanged.
@notgitika notgitika requested a review from a team June 23, 2026 20:14
@github-actions github-actions Bot added the size/xs PR size: XS label Jun 23, 2026
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 23, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Jun 23, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Jun 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Package Tarball

aws-agentcore-0.20.2.tgz

How to install

gh release download pr-1622-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.20.2.tgz

@agentcore-cli-automation agentcore-cli-automation left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. Targeted one-line regex fix to an e2e test; the root-cause analysis in the PR description matches what I see in the code:

  • The harness test exercises the managed-OAuth path (--client-id/--client-secret on add harness), which causes the CLI to auto-attach a bearer token on the "SigV4-only" invoke. That request reaches the service, which rejects on the audience claim — the existing regex didn't cover that response.
  • The sibling byo-custom-jwt.test.ts patches agentcore.json directly without registering a managed credential, so no token is auto-attached and the rejection happens via a different path that the existing regex already matches. No update needed there.
  • The negative assertion on line 263 (not.toMatch) remains safe — a successful invoke response won't contain "missing required audience claim".

No source/telemetry impact, e2e-test-only change.

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 23, 2026
@notgitika

Copy link
Copy Markdown
Contributor Author

this one makes more sense #1624

@notgitika notgitika closed this Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/xs PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants