Repository navigation
test(identitybroker): add the per-call harness, fault transport, gateway stand-in, and AS-2 trust test seam - #2784
Conversation
…way stand-in, and AS-2 trust test seam The identity harness's AS-1 issues per-call ID-JAGs, checking actor tokens through a test-supplied ActorValidator; FaultTransport fails, drops, or intercepts requests to any authorization server; and a minimal gateway stand-in needs a bearer token. ToolHiveConfig.AS2Trust, built only through mcpbrokertest, lets tests make the real AS-2 trust the harness's AS-1. Co-authored-by: Mecatl <noreply@mecatl.dev>
jhrozek
left a comment
There was a problem hiding this comment.
Approving. Two non-blocking comments inline.
| BrokerClient *ToolHiveBrokerClient | ||
| // AS2Trust, with AS-2 set up, makes AS-2 trust an ID-JAG issuer; see | ||
| // AS2Trust. | ||
| AS2Trust AS2Trust |
There was a problem hiding this comment.
ToolHiveConfig.AS2Trust is exported, so the test-only trust is now part of the production config API. The zero value is safe, but nothing stops production code from calling NewAS2Trust today. The only guard is convention and this comment. Could we add a fence production code can't reach, or at least record that this field is removed with #2533?
| // newTrustingAS2 is AS-2 configured to trust the harness's AS-1, for Alice | ||
| // and Bob, through the test-only seam. | ||
| // and Bob, through the test-only seam, ToolHiveConfig.AS2Trust. | ||
| func newTrustingAS2(t *testing.T) (*identityharness.Harness, as2BrokerClient, *Process) { |
There was a problem hiding this comment.
newTrustingAS2 repeats most of mcpbrokertest.StartAS2: the client secret env var, the ToolHiveConfig, NewToolHiveProcess, the nil check, and the cleanup. The two copies can drift. Could this call StartAS2 with the harness trust, or could StartAS2 take the broker config as a parameter?
There was a problem hiding this comment.
Addressed in #2794, partly: these tests are package mcpbroker, and mcpbrokertest imports mcpbroker, so they cannot call StartAS2 without an import cycle (moving them out would need shims for ~10 unexported helpers). Both setups now build the trust through as2trust.Trust.WithDefaults, and newTrustingAS2 documents why it exists alongside StartAS2.
Part 1 of 4 for #2535 (per-call grant and gateway token). Stack: this PR → #2785 → #2786 → #2783.
Test infrastructure only; no production behaviour changes.
internal/testutil/identityharness: the harness AS-1 issues ID-JAGs from a session's grant (step (7)), checking the agent through a harness-ownedActorValidator; a fault transport for the ID-JAG exchange and AS-2 redemption; a gateway (vMCP) stand-in for MCP broker authorizes gateway calls and sends them to the configured gateway #2536/Connect provider accounts at the embedded gateway #2537;JWKSURL()andHasJSONRPCResult. The harness imports nointernal/package (new depguard rule).internal/adapter/mcpbroker/internal/as2trust, the opaquemcpbroker.AS2Trust, andmcpbrokertest(StartAS2,TrustAS1), fenced from production code by depguard and Go's internal-package rule. Replaces the unexportedas2TrustForTest;as2_test.gomigrated.as1servertest.HarnessActorValidatormaps the broker's credential check to the harness validator.Shortcut (marked in code): AS-2 trusts AS-1 only in tests, removed by #2533. The harness AS-1's ID-JAG issuance is retired by #2654 once stacklok/toolhive#6898 (PR stacklok/toolhive#7130) and #6899 ship.
API compatibility
No wire or production change; test support and an unset test-only config field.