Skip to content

test(identityharness): retire the fake AS-1; identity tests use the real AS-1 - #2867

Merged
ChrisJBurns merged 2 commits into
mainfrom
test/identityharness-retire-fake-as1
Nov 18, 2026
Merged

ChrisJBurns merged 2 commits into
mainfrom
test/identityharness-retire-fake-as1

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Contributor

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:

  • mecak8s: TestIdentityBrokerAgainstOfflineHarness becomes TestIdentityBrokerOwnsSessionsAgainstRealAS1.
    • The second client is a real public client.
    • The 13 bad tokens are forged from AS-1's own tokens, with a positive control that an unchanged re-signed token is accepted.
    • Its hard-expiry block duplicated TestIdentityBrokerAgainstRealAS1. The one case only it had, a fork's session expiring and reopening, moved there.
  • The TUI sign-in test, the four clientauth sign-in tests (refresh rotation, stale refresh → SessionExpired, foreign resource now pinned to AS-1's invalid_target), and the session-open forged-token tests.
  • The four mcpbroker AS-2 redemption tests: AS-2 trusts the real AS-1.
  • The two revocation subtests in TestAuthorizeCallRevokedRulesAtAS1: AS-1's own revoked answer, then the session closes or the call retries with the newer grant.
  • The gateway-call tests no longer need an AS-1. The gateway stand-in never verified the token, so a local JWT with a jti does; 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).Forge alters an AS-1 token (claims, JOSE header, foreign key) and re-signs it.
  • identityharness.ReadSigningKey is the one reader of the fixture's key file, used by Forge and ResignAccessToken.

as1server.(*Server).RevokeGrant revokes a grant in AS-1's storage so tests can see AS-1 answer revoked. It is test-only:

  • it skips AS-1's handler, client authentication and ownership checks;
  • a forbidigo rule forbids calling it outside tests and as1servertest;
  • production revocation goes through AS-1's RFC 7009 route once RFC 7009 token revocation endpoint toolhive#6966 lands.

Deleted:

  • the fake AS-1: sign-in, session open, ID-JAG issuance, revocation, client authentication, scripted broker;
  • its self-tests;
  • as1servertest.HarnessActorValidator, the harnessAS1 fixture, and the removed by #2568 markers on it;
  • unused harness options and the IdP's fault queue.

identityharness.New now 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:

  • RevokeGrant as a no-op fails both revocation subtests.
  • An RFC 7009 stub that accepts any request fails TestRevocationAuthenticates.
  • The forbidigo rule fires on a RevokeGrant call in internal/app and cmd/.

Checks

  • task lint: 0 issues.
  • go test -race for internal/identitybroker/..., internal/testutil/identityharness/..., internal/adapter/{mcpbroker,mcp,clientauth}/..., and the identity, gateway and sign-in tests in internal/app and cmd/mecak8s: pass.
  • Root module (GOWORK=off -mod=readonly -race ./...): every package passes except deploy/helm/mecatl-execution and deploy/mecatl-execution-kind, whose six failing tests fail identically on main in 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.

…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 jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 checks aud. The fake set aud on every token, so that held by construction. The real AS-1 adds the default audience only on a code exchange without resource when exactly one audience is allowed (ToolHive pkg/authserver/server/handlers/token.go:250-260). Every as1servertest.SignIn sends resource, so nothing exercises that path now. Asserting aud on the issued and the refreshed token would cover it.
  • IdP.AddUser (internal/testutil/identityharness/idp.go:88) has no callers left now that Options.Users is 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:

  1. AS-1 refusing an ID-JAG for a resource that is not configured. In the design, AS-1 checks that resource is 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 with invalid_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's resource against the ID-JAG claim (TestAS2RedeemsWhatTrackedShortcutsAllow, #2533), so AS-1's check is the one that actually limits the resource.
  2. The session-grant lifetime cap above the maximum. The fake's TestSessionOpenCapsExpiresAt had an "above the maximum: capped" case. TestExchangeConvertsAtAS1 covers no expires_at and half the maximum. Both would still pass if AS-1 applied the cap only when no expiry is requested.

Comment thread .golangci.yml Resolved
- 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>
@ChrisJBurns

Copy link
Copy Markdown
Contributor Author

Thanks. Everything is addressed in d707a5e:

  • TestLoginWithoutIdentityBrokerSignInOmitsResource: asserts aud is exactly AS-1's audience on the issued and the refreshed token. Expecting another audience fails it.
  • IdP.AddUser: deleted. It had no callers.
  • AS-1 refusing an unconfigured resource: new TestIssueIDJAGAgainstRealAS1RefusesAnUnconfiguredResource. A configured target's audience with a resource it doesn't list gets 400 invalid_target, a configuration fault, and no ID-JAG is issued. Adding that resource to the target makes it fail.
  • Session-grant cap above the maximum: TestExchangeConvertsAtAS1 has an "expires_at above the maximum" case. The real AS-1 caps it at the maximum rather than refusing. Expecting the requested expiry back fails it.

@ChrisJBurns
ChrisJBurns enabled auto-merge (squash) November 18, 2026 21:29
@ChrisJBurns
ChrisJBurns merged commit e3ffbc4 into main Nov 18, 2026
50 checks passed
@ChrisJBurns
ChrisJBurns deleted the test/identityharness-retire-fake-as1 branch November 18, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Retire the harness's fake AS-1: identity tests use the real AS-1

2 participants