Skip to content

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

TypeScript
1.8 KB
Raw Blame
import { describe, expect, it } from 'vitest'

// NOTE (2026-04-09 refactor): The in-memory `wrcToMcpHostTokenStore` was
// removed because it was an unnecessary attack surface. V1 wiring tests
// that asserted Map-style store behaviour are no longer relevant — tokens
// are now signed fresh per request by the JwtTokenFactory with a 60s TTL
// for artifact scopes and a 1h TTL for configure scopes. See the
// jwtTokenFactory and restEndpoints tests for the new coverage.

// ─── V9: JWT claim validation (contract tests) ────────────────────────
// These verify the type contract — verifyWrcToken throws on missing claims.
// Full integration requires RSA key pair; tested in smoke tests.

describe('V9: JWT claims rejection contract', () => {
  it('AuthenticatedRequest.tokenClaims requires non-empty sub', () => {
    // The fix ensures verifyWrcToken throws "JWT missing required claim: sub"
    // when payload.sub is undefined. We verify the contract:
    const claims = { sub: '', aud: 'clerum-wrc', recipeName: 'r', scopes: [] }
    // Empty sub should be treated as invalid by handlers
    expect(claims.sub).toBeFalsy()
  })

  it('AuthenticatedRequest.tokenClaims requires non-empty recipeName', () => {
    const claims = { sub: 'coordinator', aud: 'clerum-wrc', recipeName: '', scopes: [] }
    expect(claims.recipeName).toBeFalsy()
  })

  it('recipeName mismatch returns 403 (defense against empty recipeName bypass)', () => {
    // If somehow a token had recipeName="" and the URL had name="",
    // they would match "" === "" — but K8s CRD names cannot be empty,
    // so this is safe at the Kubernetes layer.
    const urlRecipeName: string = 'my-recipe'
    const tokenRecipeName: string = ''
    expect(tokenRecipeName).not.toBe(urlRecipeName)
  })
})