Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(control-api): pin the per-server variant, cr_uid and client-id checks
Jose Gabriel Ramirez Encinas4ee6b27db4e3
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex e090d1720..3ad7459c2 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.701",+ "version": "0.1.702","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.701",+ "version": "0.1.702","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex 08ce33d99..4091ae6ff 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.701",+ "version": "0.1.702","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/oauth.callbackRemotePerServer.test.ts b/control-api/test/oauth.callbackRemotePerServer.test.tsindex 0561c36c7..c4f7212b1 100644--- a/control-api/test/oauth.callbackRemotePerServer.test.ts+++ b/control-api/test/oauth.callbackRemotePerServer.test.ts@@ -9,6 +9,7 @@ import {handleOAuthCallback,} from '../src/oauth/callback.js'import type { DiscoveryResult } from '../src/oauth/discovery.js'+import { getDynamicClientBinding } from '../src/oauth/dynamicClientStore.js'import { deriveOAuthEncryptionKey } from '../src/oauth/encryption.js'import {type McpServerOAuthSpecInput,@@ -363,6 +364,87 @@ describe('per-server callback — only the URI this installation registered', ()expect(h.tokenPosts).toHaveLength(0)})+ // I6 with the shared server's REAL bound nonce: the nonce and row checks pass, so only+ // the variant check stands between this request and an exchange with no `iss` at all.+ it('a shared (RFC 9207) server on its own bound nonce, no iss → binding_mismatch, no exchange', async () => {+ const srv = await installDcr('shared-dcr', sharedDcr, dcrPilot('public').mcpUrl)+ const row = await getDynamicClientBinding(db, { serverNamespace: NS, serverName: srv.name })+ expect(row?.installId).toMatch(/^[0-9a-f-]{36}$/)+ const h = harness()++ const result = await handleOAuthCallback(+ {+ target: perServer(srv.name, row?.installId),+ code: 'CODE',+ state: await stateFor(srv.name),+ },+ h.deps+ )++ expect(result).toEqual({ kind: 'invalid_state', reason: 'binding_mismatch' })+ expect(h.tokenPosts).toHaveLength(0)+ })++ // A CR deleted and recreated outside the uninstall (kubectl, GitOps) leaves the old+ // row behind with the same nonce and client id; only its cr_uid no longer matches.+ it('DCR: a CR recreated over a surviving row → binding_mismatch on the old nonce, no exchange', async () => {+ const srv = await installDcr('atlassian')+ const cr = (await gateway.getResource('mcpservers', srv.name, NS)) as {+ metadata: { name: string; uid: string; labels?: Record<string, string> }+ spec: Record<string, unknown>+ }+ await gateway.deleteResource('mcpservers', srv.name, NS)+ await gateway.createResource(+ 'mcpservers',+ { metadata: { name: cr.metadata.name, labels: cr.metadata.labels }, spec: cr.spec },+ NS+ )+ const recreated = (await gateway.getResource('mcpservers', srv.name, NS)) as {+ metadata: { uid: string }+ }+ expect(recreated.metadata.uid).not.toBe(cr.metadata.uid)+ const row = await getDynamicClientBinding(db, { serverNamespace: NS, serverName: srv.name })+ expect(row?.installId).toBe(srv.nonce)+ expect(row?.crUid).toBe(cr.metadata.uid)+ const h = harness()++ const result = await handleOAuthCallback(+ { target: perServer(srv.name, srv.nonce), code: 'CODE', state: await stateFor(srv.name) },+ h.deps+ )++ expect(result).toEqual({ kind: 'invalid_state', reason: 'binding_mismatch' })+ expect(h.tokenPosts).toHaveLength(0)+ })++ // The CR's client id rewritten in place (same uid): the row still belongs to this CR+ // but was registered for another client, so its nonce binds nothing.+ it('DCR: a bound row registered for another client id → binding_mismatch, no exchange', async () => {+ const srv = await installDcr('atlassian')+ const cr = (await gateway.getResource('mcpservers', srv.name, NS)) as {+ metadata: { uid: string; resourceVersion?: string }+ spec: { oauth: Record<string, unknown> } & Record<string, unknown>+ }+ await gateway.updateResource(+ 'mcpservers',+ srv.name,+ {+ metadata: { uid: cr.metadata.uid, resourceVersion: cr.metadata.resourceVersion },+ spec: { ...cr.spec, oauth: { ...cr.spec.oauth, id: 'rewritten-client-id' } },+ },+ NS+ )+ const h = harness()++ const result = await handleOAuthCallback(+ { target: perServer(srv.name, srv.nonce), code: 'CODE', state: await stateFor(srv.name) },+ h.deps+ )++ expect(result).toEqual({ kind: 'invalid_state', reason: 'binding_mismatch' })+ expect(h.tokenPosts).toHaveLength(0)+ })+it('a remote server on /oauth-callback/<oauthClientId> → binding_mismatch, no exchange', async () => {const srv = await installDcr('atlassian')const h = harness()