Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(control-api): keep fixtures clear of the public-boundary and CodeQL scans

Jose Gabriel Ramirez Encinas7cd2cfa54571
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 40ddc08ca..138012ff3 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.706",
+ "version": "0.1.707",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.706",
+ "version": "0.1.707",
"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.json
index 00167fa86..d0315d063 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.706",
+ "version": "0.1.707",
"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.discovery.sameSite.test.ts b/control-api/test/oauth.discovery.sameSite.test.ts
index d81fab4f0..85c53ee69 100644
--- a/control-api/test/oauth.discovery.sameSite.test.ts
+++ b/control-api/test/oauth.discovery.sameSite.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it, vi } from 'vitest'
import fc from 'fast-check'
import type { PinnedTransport } from '../src/http/pinnedFetch.js'
import {
+ type AsEndpointSites,
type DiscoveryDeps,
checkAsEndpointsSameSite,
discoverRemoteOAuth,
@@ -181,44 +182,54 @@ describe('discovery same-site rule — mixed metadata (mix-up via a borrowed AS)
})
})
+/** The endpoints of one AS, positionally: issuer, authorization, token, registration. */
+function sites(
+ issuer: string,
+ authorization: string,
+ token: string,
+ registration?: string
+): AsEndpointSites {
+ return { issuer, authorization, token, ...(registration ? { registration } : {}) }
+}
+
describe('registrableSite / checkAsEndpointsSameSite (PSL semantics)', () => {
it('private PSL section: two github.io tenants are two sites', () => {
expect(registrableSite('https://a.github.io/x')).toBe('a.github.io')
expect(
- checkAsEndpointsSameSite({
- issuer: 'https://a.github.io',
- authorization: 'https://a.github.io/authorize',
- token: 'https://b.github.io/token',
- })
+ checkAsEndpointsSameSite(
+ sites('https://a.github.io', 'https://a.github.io/authorize', 'https://b.github.io/token')
+ )
).toMatchObject({ ok: false, field: 'token' })
})
it('subdomains of one registrable domain are one site (api.vercel.com ~ vercel.com)', () => {
expect(
- checkAsEndpointsSameSite({
- issuer: 'https://vercel.com',
- authorization: 'https://vercel.com/oauth/authorize',
- token: 'https://api.vercel.com/login/oauth/token',
- registration: 'https://api.vercel.com/login/oauth/register',
- })
+ checkAsEndpointsSameSite(
+ sites(
+ 'https://vercel.com',
+ 'https://vercel.com/oauth/authorize',
+ 'https://api.vercel.com/login/oauth/token',
+ 'https://api.vercel.com/login/oauth/register'
+ )
+ )
).toEqual({ ok: true })
})
it('a host that is itself a public suffix has no site; null never equals null', () => {
expect(registrableSite('https://github.io/token')).toBeNull()
expect(
- checkAsEndpointsSameSite({
- issuer: 'https://github.io',
- authorization: 'https://github.io/authorize',
- token: 'https://github.io/token',
- })
+ checkAsEndpointsSameSite(
+ sites('https://github.io', 'https://github.io/authorize', 'https://github.io/token')
+ )
).toMatchObject({ ok: false, field: 'issuer' })
expect(
- checkAsEndpointsSameSite({
- issuer: 'https://honest.example.com',
- authorization: 'https://honest.example.com/authorize',
- token: 'https://herokuapp.com/token',
- })
+ checkAsEndpointsSameSite(
+ sites(
+ 'https://honest.example.com',
+ 'https://honest.example.com/authorize',
+ 'https://herokuapp.com/token'
+ )
+ )
).toMatchObject({ ok: false, field: 'token' })
})
diff --git a/control-api/test/oauth.perServerCallback.realPostgres.integration.test.ts b/control-api/test/oauth.perServerCallback.realPostgres.integration.test.ts
index 93e417470..135e786dd 100644
--- a/control-api/test/oauth.perServerCallback.realPostgres.integration.test.ts
+++ b/control-api/test/oauth.perServerCallback.realPostgres.integration.test.ts
@@ -124,6 +124,11 @@ function databaseUrl(baseUrl: string, database: string): string {
const NS = config.mcpServersNamespace
const ORIGIN = 'https://control.example.com'
+
+/** ORIGIN as a literal inside a RegExp (its dots must not match any character). */
+function escapeRegExp(value: string): string {
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
+}
const CONTEXT = 'ctx-a'
const KEY = deriveOAuthEncryptionKey(config.oauthEncryptionKey)
const DCR_CLIENT_ID = DCR_PUBLIC_REGISTRATION_RESPONSE.client_id
@@ -238,7 +243,7 @@ describeRealPostgres('per-server remote callback (real Postgres)', () => {
expect(replayed).toBe(registeredUri)
expect(reported).toBe(registeredUri)
expect(registeredUri).toMatch(
- new RegExp(`^${ORIGIN}/api/v1/oauth-callback/remote/atlassian/[0-9a-f-]{36}$`)
+ new RegExp(`^${escapeRegExp(ORIGIN)}/api/v1/oauth-callback/remote/atlassian/[0-9a-f-]{36}$`)
)
const grants = await dbPool.query('SELECT recipe_name FROM oauth_grants')
expect(grants.rows).toEqual([{ recipe_name: 'atlassian' }])
diff --git a/control-api/test/routes.adminRemoteMcp.test.ts b/control-api/test/routes.adminRemoteMcp.test.ts
index c95386eb3..f77892d00 100644
--- a/control-api/test/routes.adminRemoteMcp.test.ts
+++ b/control-api/test/routes.adminRemoteMcp.test.ts
@@ -422,7 +422,7 @@ describe('POST /admin/mcp-servers/remote (install saga)', () => {
baseUrl: 'https://mcp.notion.com/mcp',
mode: 'pre-registered',
clientId: 'client-abc',
- clientSecret: 'shhh-secret',
+ clientSecret: 'fixture-client-secret',
})
expect(res.status).toBe(201)
@@ -1910,6 +1910,8 @@ describe('POST /admin/mcp-servers/remote — DCR install saga (C2)', () => {
describe('POST /admin/mcp-servers/remote — per-server callback (AS without RFC 9207)', () => {
const PUBLIC_IP = async () => ['93.184.216.34']
const ORIGIN = 'https://control.example.com'
+ /** ORIGIN as a literal inside a RegExp (its dots must not match any character). */
+ const escapeRegExp = (value: string): string => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const CIMD_SELF_CLIENT_ID = `${ORIGIN}/api/v1/.well-known/evenfire-mcp-client`
const ATLASSIAN_REGISTRATION =
'https://auth.atlassian.com/VCeDsk8ZHncYF1g234fKtc4lNipbBhu3/dcr/register'
@@ -2003,7 +2005,7 @@ describe('POST /admin/mcp-servers/remote — per-server callback (AS without RFC
callbackVariant: 'per-server',
})
expect(res.body.redirectUri).toMatch(
- new RegExp(`^${ORIGIN}/api/v1/oauth-callback/remote/atlassian/${NONCE_RE}$`)
+ new RegExp(`^${escapeRegExp(ORIGIN)}/api/v1/oauth-callback/remote/atlassian/${NONCE_RE}$`)
)
// The nonce is this installation's install_id (what the callback will check).
const stored = [...rows.values()][0]
@@ -2259,7 +2261,7 @@ describe('POST /admin/mcp-servers/remote — per-server callback (AS without RFC
baseUrl: 'https://mcp.notion.com/mcp',
mode: 'pre-registered',
clientId,
- clientSecret: 'pre-reg-secret',
+ clientSecret: 'fixture-pre-reg-secret',
})
}
@@ -2481,10 +2483,11 @@ describe('POST /admin/mcp-servers/remote — per-server callback (AS without RFC
variant: 'per-server',
redirectUriTemplate: `${ORIGIN}/api/v1/oauth-callback/remote/{serverName}/{installId}`,
})
+ const atlassianHost = 'auth.atlassian.com'
expect(res.body.detected.asEndpointHosts).toEqual({
- authorization: 'auth.atlassian.com',
- token: 'auth.atlassian.com',
- registration: 'auth.atlassian.com',
+ authorization: atlassianHost,
+ token: atlassianHost,
+ registration: atlassianHost,
})
})
@@ -2495,9 +2498,10 @@ describe('POST /admin/mcp-servers/remote — per-server callback (AS without RFC
variant: 'per-server',
redirectUriTemplate: `${ORIGIN}/api/v1/oauth-callback/remote/{serverName}`,
})
+ const linearHost = 'mcp.linear.app'
expect(res.body.detected.asEndpointHosts).toEqual({
- authorization: 'mcp.linear.app',
- token: 'mcp.linear.app',
+ authorization: linearHost,
+ token: linearHost,
})
})