Repository navigation
test(identityharness): retire the fake AS-1; identity tests use the real AS-1 - #2867
Merged
Merged
Conversation
…eal AS-1 Every identity test that needs an AS-1 now runs against ToolHive's embedded authorization server hosted by as1server: mecak8s session ownership, TUI and clientauth sign-in, session-open checks, AS-2 redemption, and AS-1's own revoked answer. Forged tokens come from as1servertest.Forge, RFC 7009 client authentication is tested against a stub until AS-1 serves the route (stacklok/toolhive#6966), and a test-only RevokeGrant, which forbidigo keeps out of production, lets tests see AS-1 refuse a revoked grant. The fake AS-1, its self-tests, and the harness revocation fixture are deleted; the harness keeps the upstream IdP, the consent helper, the fault transport, the CA and key helpers, and the gateway stand-in. Closes #2858. Co-authored-by: Mecatl <noreply@mecatl.dev>
jhrozek
reviewed
Nov 18, 2026
jhrozek
left a comment
Contributor
There was a problem hiding this comment.
Thanks, this is a good swap. Several moved tests are stricter than before: the foreign resource is pinned to AS-1's invalid_target, the forgeries are real AS-1 tokens re-signed with one change, and the forgery table has a positive control.
The inline comments are things this PR introduced. Two more introduced here sit on lines outside the diff, so they go here:
TestLoginWithoutIdentityBrokerSignInOmitsResource(internal/adapter/clientauth/as1_signin_test.go:234-236) says AS-1 still issues tokens for the audience, but the test never checksaud. The fake setaudon every token, so that held by construction. The real AS-1 adds the default audience only on a code exchange withoutresourcewhen exactly one audience is allowed (ToolHivepkg/authserver/server/handlers/token.go:250-260). Everyas1servertest.SignInsendsresource, so nothing exercises that path now. Assertingaudon the issued and the refreshed token would cover it.IdP.AddUser(internal/testutil/identityharness/idp.go:88) has no callers left now thatOptions.Usersis gone.
Found along the way, not caused by this PR. The fake checked two design rules only on itself, and no test checks them against the real AS-1. Deleting the fake makes that visible. Follow-ups are fine:
- AS-1 refusing an ID-JAG for a resource that is not configured. In the design, AS-1 checks that
resourceis a vMCP configured for the requested AS-2 (docs/drafts/agent-identity/credentials-and-lifecycle.md, "(7) ID-JAG from AS-1", check 3). The fake's ID-JAG test had an unknown resource with a valid audience refused withinvalid_target. The real-AS-1 test (authserverclient/idjag_test.go:174) changes only the audience. This matters today because AS-2 does not yet check the redemption'sresourceagainst the ID-JAG claim (TestAS2RedeemsWhatTrackedShortcutsAllow, #2533), so AS-1's check is the one that actually limits the resource. - The session-grant lifetime cap above the maximum. The fake's
TestSessionOpenCapsExpiresAthad an "above the maximum: capped" case.TestExchangeConvertsAtAS1covers noexpires_atand half the maximum. Both would still pass if AS-1 applied the cap only when no expiry is requested.
- The alg none forgery copies the issued token's claims, so it is refused for its algorithm alone. - clientauth's no-resource sign-in checks AS-1 grants its sole audience on the issued and refreshed token. - The RFC 7009 stub checks the assertion's iss, sub, aud, exp, and jti again. - forbidigo no longer exempts as1servertest from the RevokeGrant ban. - IdP.AddUser, unused, is gone, and re-signing has one implementation, identityharness.ResignToken. - New real-AS-1 tests: an ID-JAG for a resource the target doesn't list is refused with invalid_target, and a session-open expiry above the maximum is capped. Co-authored-by: Mecatl <noreply@mecatl.dev>
Contributor
Author
|
Thanks. Everything is addressed in d707a5e:
|
jhrozek
approved these changes
Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Retires the offline identity harness's fake AS-1: every identity test that needs an AS-1 now uses the real one, ToolHive's embedded authorization server hosted by
as1server. Builds on #2856 (merged).What
Tests moved to the real AS-1:
TestIdentityBrokerAgainstOfflineHarnessbecomesTestIdentityBrokerOwnsSessionsAgainstRealAS1.TestIdentityBrokerAgainstRealAS1. The one case only it had, a fork's session expiring and reopening, moved there.clientauthsign-in tests (refresh rotation, stale refresh →SessionExpired, foreign resource now pinned to AS-1'sinvalid_target), and the session-open forged-token tests.mcpbrokerAS-2 redemption tests: AS-2 trusts the real AS-1.TestAuthorizeCallRevokedRulesAtAS1: AS-1's ownrevokedanswer, then the session closes or the call retries with the newer grant.jtidoes; the real gateway path is covered by feat(identitybroker): issue the gateway's ID-JAGs at the hosted AS-1 #2856's tests.RFC 7009 revocation (
authserverclient) is tested against a stub endpoint that checks the broker's client assertion, because the real AS-1 has no revocation route until stacklok/toolhive#6966.Test helpers:
as1servertest.(*AS1).Forgealters an AS-1 token (claims, JOSE header, foreign key) and re-signs it.identityharness.ReadSigningKeyis the one reader of the fixture's key file, used byForgeandResignAccessToken.as1server.(*Server).RevokeGrantrevokes a grant in AS-1's storage so tests can see AS-1 answerrevoked. It is test-only:forbidigorule forbids calling it outside tests andas1servertest;Deleted:
as1servertest.HarnessActorValidator, theharnessAS1fixture, and theremoved by #2568markers on it;identityharness.Newnow starts only the IdP. The harness keeps:Not shown against the real AS-1
parent_revoked: AS-1 answers it only for a child grant, and it derives child grants only from grants that issue refresh tokens. The broker's session-open grants issue only ID-JAGs, so the broker never holds one. The subtest still injects that answer in front of the real AS-1, and its comment says why.Assertions
Every moved test keeps its assertions or names the real-AS-1 test that covers them. Tests of the fake AS-1 itself are deleted with it. The IdP and fault-transport behaviours those tests exercised are now tested directly (
idp_test.go,faulttransport_test.go).Mutation-checked:
RevokeGrantas a no-op fails both revocation subtests.TestRevocationAuthenticates.forbidigorule fires on aRevokeGrantcall ininternal/appandcmd/.Checks
task lint: 0 issues.go test -raceforinternal/identitybroker/...,internal/testutil/identityharness/...,internal/adapter/{mcpbroker,mcp,clientauth}/..., and the identity, gateway and sign-in tests ininternal/appandcmd/mecak8s: pass.GOWORK=off -mod=readonly -race ./...): every package passes exceptdeploy/helm/mecatl-executionanddeploy/mecatl-execution-kind, whose six failing tests fail identically onmainin this environment (local Helm and shell tooling).Issue relationship
Closes #2858
API compatibility
None: internal packages and tests only, no wire or public API change.