Skip to content

Test session open against the real AS-1, not the harness's #2677

Closed

Description

@ChrisJBurns

Depends on: none. Since #2607 (ToolHive v0.61.0), the real AS-1 converts sign-ins at session open. Lands after #2534 (PR #2733) and before #2535.

Problem

The identity broker's session-open tests run against the offline harness's AS-1 (internal/testutil/identityharness). That was needed before the real AS-1 (ToolHive's authorization server, hosted in mecak8s) could convert a sign-in. It now can, and the harness already answers differently:

  • Refused subject tokens. The harness answers subject_token_invalid for every refused subject token (sessionopen.go, check 4). The real AS-1 answers subject_token_audience, subject_token_source_client or subject_token_offline_access for a token with another audience, from an unlisted client, or without offline_access. The broker treats subject_token_invalid as "refresh the access token and retry", and the other three as a configuration fault, so a harness test can pass while production does something else.
  • Undetected drift. subject_token_offline_access was found only by probing the real server, while implementing Register the broker client at AS-1 and point the broker at it #2607.

Slice 3's result test, TestIdentityBrokerAgainstOfflineHarness (cmd/mecak8s/identity_broker_harness_test.go), proves session close and hard-expiry reopen against the harness only.

Some of this is already covered: TestHostedAS1SignsTheTUIIn (cmd/mecak8s/as1_sign_in_harness_test.go) proves mecak8s session open converts at the hosted AS-1, and the TestDelegate* tests (internal/identitybroker/adapter/as1server/delegate_test.go) cover conversion, token_used, bad assertions, audience, source client, and offline_access through authserverclient, but not through the broker.

Design

No design change. Tests, test helpers, and the test-only seams listed below; no production wiring changes.

Requirements

  • Use the real AS-1 for everything it can do. Run the broker's session-open tests against the real AS-1 in process (internal/identitybroker/adapter/as1server, with the broker's delegate client, as the TestDelegate* tests already do):
    • conversion;
    • reused access tokens;
    • refused subject tokens (another audience, an unlisted client, no offline_access, expired);
    • failed client assertions;
    • slice 3's session close and hard-expiry reopen (see Clocks).
  • Clocks. The real AS-1 has no clock; it stamps expiries with wall time. The broker counts hard expiry 30 seconds early (credentialClockSkew), so any id_jag_max_lifetime of 30 seconds or less opens an already-expired session.
    • The broker's clock is wall time plus a test-controlled offset; the authserverclient assertion clock stays wall time. The fixed-epoch openClock in sessionopen_test.go goes.
    • Hard expiry: advance the offset past the grant's SessionGrant(...).ExpiresAt, observe the close through a call that does not reach AS-1 (FindSession, RegisterAgent, AuthorizeCall), reset the offset to zero, then reopen. Expected expiries come from SessionGrant, not harness constants.
    • In mecak8s, the real-AS-1 close and reopen test passes an explicit IdentityBrokerAS1 backed by a test-built as1server; buildBrokerWithHostedAS1 stays covered by TestHostedAS1SignsTheTUIIn.
  • Inject faults in front of the real AS-1. A test wrapper around its handler or its in-process transport (Server.InProcessClient()) replaces all of the harness's fault injection:
    • 429 and 5xx answers;
    • a request dropped before AS-1 processes it;
    • a lost response after AS-1 has converted;
    • an altered or missing echoed grant;
    • arbitrary OAuth error and reason bodies, so the broker's mapping of every reason in the error-reasons table (including signed_out, upstream_revoked, owner_action_required, grant_invalid) stays tested.
    • The wrapper also records requests and client assertions, replacing ReceivedClientAssertions, ExchangeRefusals and the "AS-1 not called" counters.
  • Shared fixture. One helper starts the real AS-1 with the harness IdP upstream and signs a user in, shared by the broker, authserverclient, internal/app and mecak8s tests, in a test-support package with a narrow depguard exception. The another-audience case runs in as1server's in-package tests, where the unexported extraAudiences option is reachable, so no audience option is exported.
  • Choose the signed-in user. Add a one-shot user selector to the harness IdP (ToolHive v0.61.0 does not forward login_hint), so one AS-1 can convert for two users.
  • Keep the harness's AS-1 only for ID-JAG issuance (ID-JAG issuance through token exchange toolhive#6898, Pluggable actor-token validation at ID-JAG issuance toolhive#6899), which slice 4's grant tests need. Its session-open conversion stays too (decided), as the grant fixture for those tests: the harness's ID-JAG exchange can only redeem refresh tokens the harness issued, and a real AS-1 refresh token is opaque and stored hashed. Every slice 4 grant test (Configure the embedded gateway's authorization server as AS-2 #2533, Per-call grant and gateway token #2535, MCP broker authorizes gateway calls and sends them to the configured gateway #2536, Connect provider accounts at the embedded gateway #2537, Wire the embedded gateway's authorization server into startup as AS-2 #2738) keeps using it until ID-JAG issuance through token exchange toolhive#6898. Revocation tests (TestRevocationAuthenticates and similar) stay on the harness until RFC 7009 token revocation endpoint toolhive#6966 and Per-user revocation time for grants issued by token exchange toolhive#6972 (Sign-out and revocation #2568). Each test that still uses the harness's AS-1 says in a code comment which ToolHive issue retires it, and the PR description lists them.
  • Keep the harness end-to-end test. TestIdentityBrokerAgainstOfflineHarness stays on the harness's AS-1, since MCP broker authorizes gateway calls and sends them to the configured gateway #2536 and Connect provider accounts at the embedded gateway #2537 extend it with gateway calls; it names ID-JAG issuance through token exchange toolhive#6898. The real-AS-1 close and hard-expiry reopen is a new sibling test.
  • Delete what is left unused: the harness's subject-token refusal cases and all its fault injection (FailNextExchange, DropNextExchange and the rest). Per-call grant and gateway token #2535 adds any grant-path fault injection fresh.
  • Crafted tokens stay where AS-1 is never reached. Checks that fail before AS-1 is called (mecak8s step (1) rejections such as a foreign key, alg none, wrong typ; the broker's check 1) keep using crafted tokens.
  • Grant-state assertions. Assertions that read harness grant state (AS1.Grant(...), GrantsIssued) are rewritten against the broker's SessionGrant or a wrapper counter, or dropped where the real AS-1 cannot expose the state yet.
  • An expired subject token: sign one with a test-owned AS-1 signing key (SigningKeyFile), so no production configuration changes.
  • Other harness users move to the real AS-1 where they test session open, and stay on the harness otherwise: authserverclient/client_test.go, authserverclient/exchange_test.go, internal/app/identitybroker_test.go. Assertion replay moves to the real AS-1 with a reused assertion; the "replay inside the skew" variant needs a server clock that no ToolHive issue tracks, so it is dropped.
  • Carry over feat(identitybroker): verify an agent credential for a grant's owner #2733's case. Keep the VerifyCredentialForOwner case PR feat(identitybroker): verify an agent credential for a grant's owner #2733 adds to TestSessionHardExpiryClosesTheSession.
  • Keep it all in the normal offline suite.

One PR, opened after PR #2733 merges.

How it fits

Slice 4 builds the grant path while ToolHive cannot yet issue ID-JAGs. This ticket limits the harness to that gap, so everything the real AS-1 already does is tested against it. As ToolHive adds ID-JAG issuance and revocation, the remaining harness tests move over (#2654, #2533, #2568). The full flow against real ToolHive in a deployment remains #2542.

Done when

  • Every session-open case the real AS-1 can produce runs against it, including slice 3's close and hard-expiry reopen in a new real-AS-1 test.
  • Transport faults and reasoned refusals are injected in front of the real AS-1.
  • The harness's AS-1 is used only for ID-JAG issuance (with its conversion as the grant fixture, including TestIdentityBrokerAgainstOfflineHarness) and revocation, each test naming in a code comment the ToolHive issue that retires it; its refusal cases and fault injection are removed.

Activity

  1. added 3 commits that reference this issue on Nov 6, 2026
    2085a4e
    33de0d1
    1919890
  2. self-assigned this
    on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions