test(e2e): fix harness CUSTOM_JWT auth to validate allowedClients#1624
Conversation
The harness-custom-jwt E2E (added in #1609) deployed the authorizer with --allowed-audience, which validates the token's aud claim. But the test authenticates via Cognito client_credentials (M2M), whose tokens carry a client_id claim and no aud. Combined with the harness auto-fetch flow from the main+preview merge (#1598, #1611) — where a registered managed OAuth credential makes a default invoke auto-fetch a JWT instead of using SigV4 — the service rejected every fetched token with 403 'missing required audience claim', which didn't match the test's expected client-side rejection. Switch the authorizer to --allowed-clients (the claim Cognito M2M tokens actually carry), assert AllowedClients in the deploy template check, and reframe the invoke tests to the real post-merge behavior: a default invoke auto-fetches a JWT and is accepted, and the bearer-token invoke returns exitCode 0. Test-only change; no shippable CLI behavior changes. Closes #1623
|
Claude Security Review: no high-confidence findings. (run) |
Package TarballHow to installgh release download pr-1624-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
left a comment
There was a problem hiding this comment.
This is a well-scoped, well-explained test-only fix. The root-cause analysis in the description matches the code: canFetchHarnessToken() returns true when the managed OAuth credential is registered, so a default invoke auto-fetches a JWT — which means the old "rejects SigV4" expectation was no longer valid for this fixture. Switching to --allowed-clients (matching the client_id claim that Cognito M2M tokens actually carry) is the right fix, and asserting exitCode === 0 on the bearer-token path is a meaningful strengthening of the test.
A couple of small observations (not blocking, just noting for awareness):
- The new
auto-fetches a JWT for a default (non-bearer) invocationtest only asserts negative conditions (not.toMatch) and does not assertexitCode === 0, while its sibling bearer-token test was strengthened to do so. If the auto-fetch path silently regressed (e.g. fell back to SigV4 without producing a recognizable error string), this test could still pass. Consider adding anexitCode === 0assertion here too for symmetry — but I see why you may have left it off (the test name implies the auto-fetch is exercised, and thefetch access --type harnesstest below provides a direct positive on token minting). - As noted in the description,
byo-custom-jwt.test.tscarries the same latentallowedAudiencemisconfiguration hidden behind a weaknot.toMatch. Scoping that to a follow-up seems fine.
Nothing here that needs to change before merging.
Coverage Report
|
Description
The
harness-custom-jwtE2E test (added in #1609) fails on the full-suite run (shard 2/5) atrejects SigV4 invocation (auth method mismatch).Root cause — a test fixture bug, surfaced by the main+preview merge (#1598, #1611):
--allowed-audience <clientId>, so the service validates the token'saudclaim.client_idclaim and noaud.--client-id/--client-secret), so the post-merge auto-fetch path kicks in: a defaultinvoke(no--bearer-token) now auto-fetches a JWT instead of doing SigV4 (canFetchHarnessToken()→true).403 "*** missing required audience claim.", which doesn't match the test's expected client-sidecustomJWTRejectMsgRegex→ assertion fails.The sibling
byo-custom-jwt.test.tspasses only because it patchesagentcore.jsonwith no credential, so it hits the client-side SigV4 fast-fail the regex expects. The sameaudmisconfiguration is latent there, hidden by a weaknot.toMatchassertion.Fix (test-only — no shippable CLI behavior changes):
--allowed-clients(the claim Cognito M2M tokens actually carry) instead of--allowed-audience.AllowedClientsin the CFN template check.auto-fetches a JWT for a default (non-bearer) invocation), and the bearer-token invoke now assertsexitCode === 0(a real positive, replacing the weaknot.toMatch). Both also assert nomissing required audience claim403, so a futureallowedClientsregression is caught.Related Issue
Closes #1623
Documentation PR
N/A — test-only change.
Type of Change
Testing
How have you tested the change?
npm run test:unitandnpm run test:integnpm run typecheck(tsc --noEmit— clean)npm run lint(eslint + prettier--check— clean)src/assets/, I rannpm run test:update-snapshotsand committed the updated snapshotsAlso confirmed
vitest list --project e2ecollects all 5 cases including the renamed test. The E2E itself runs against real AWS (Cognito deploy) and will execute in CI on this PR.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.