diff --git a/src/scenarios/index.ts b/src/scenarios/index.ts index ff377f54..b40d8d30 100644 --- a/src/scenarios/index.ts +++ b/src/scenarios/index.ts @@ -2,6 +2,7 @@ import { Scenario, ClientScenario, ClientScenarioForAuthorizationServer, + ScenarioForResourceAuthorizationServer, ScenarioSource, SpecVersion, DatedSpecVersion, @@ -315,6 +316,21 @@ export const clientScenariosForAuthorizationServer = new Map< ]) ); +// All scenarios for the EMA Resource Authorization Server (ISSUE-470) +const allScenariosListForResourceAuthorizationServer: ScenarioForResourceAuthorizationServer[] = + []; + +// Scenarios map for the EMA Resource Authorization Server - built from list +export const resourceAuthorizationServerScenarios = new Map< + string, + ScenarioForResourceAuthorizationServer +>( + allScenariosListForResourceAuthorizationServer.map((scenario) => [ + scenario.name, + scenario + ]) +); + // All client test scenarios (core + backcompat + extensions) const scenariosList: Scenario[] = [ new InitializeScenario(), @@ -418,6 +434,16 @@ export function listClientScenariosForAuthorizationServer(): string[] { return Array.from(clientScenariosForAuthorizationServer.keys()); } +export function getScenarioForResourceAuthorizationServer( + name: string +): ScenarioForResourceAuthorizationServer | undefined { + return resourceAuthorizationServerScenarios.get(name); +} + +export function listScenariosForResourceAuthorizationServer(): string[] { + return Array.from(resourceAuthorizationServerScenarios.keys()); +} + // All client-testing scenarios that target the draft spec, derived from the // declared `source.introducedIn` rather than a hand-maintained list (covers // both the auth draft scenarios and the non-auth ones, e.g. SEP-2243/2575). @@ -514,7 +540,8 @@ export function getScenarioSpecVersions( const s = scenarios.get(name) ?? clientScenarios.get(name) ?? - clientScenariosForAuthorizationServer.get(name); + clientScenariosForAuthorizationServer.get(name) ?? + resourceAuthorizationServerScenarios.get(name); if (!s) return undefined; if ('extensionId' in s.source) return ['extension']; const result: ScenarioSpecTag[] = []; diff --git a/src/schemas.ts b/src/schemas.ts index b8f67831..94d91ac4 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -2,7 +2,8 @@ import { z } from 'zod'; import { getScenario, getClientScenario, - getClientScenarioForAuthorizationServer + getClientScenarioForAuthorizationServer, + getScenarioForResourceAuthorizationServer } from './scenarios'; // Client command options schema @@ -78,6 +79,70 @@ export type AuthorizationServerOptions = z.infer< typeof AuthorizationServerOptionsSchema >; +// Resource authorization server (EMA / ID-JAG) command options schema. +// +// Settings a human tester provides to point a scenario at a *real* target +// Resource AS they have pre-provisioned. `url` is the only field every scenario +// needs (it discovers the token/introspection endpoints from the issuer's +// server metadata); each scenario validates the additional fields it requires +// and skips when they are absent, so the remaining fields are schema-optional. +export const ResourceAuthorizationServerOptionsSchema = z.object({ + // [1] Issuer URL of the target Resource AS. The runner GETs its server + // metadata (well-known URL derived from the issuer) to learn the token and + // introspection endpoints. Required by every scenario. + url: z.string().url('Invalid resource authorization server URL'), + scenario: z + .string() + .min(1, 'Scenario cannot be empty') + .refine( + (scenario) => + getScenarioForResourceAuthorizationServer(scenario) !== undefined, + { + error: (iss) => `Unknown scenario '${iss.input}'` + } + ) + .optional(), + // [2] client_id of the MCP Client the tester registered with the Resource AS. + clientId: z.string().min(1, 'Client id cannot be empty').optional(), + // [3] Client secret for that MCP Client (client_secret_post authentication). + clientSecret: z.string().min(1, 'Client secret cannot be empty').optional(), + // [4] Issuer URL of an IdP AS the target Resource AS trusts (accepts ID-JAGs + // whose `iss` matches). + trustedIdpIssuer: z.string().url('Invalid trusted IdP issuer URL').optional(), + // [5] Issuer URL of an IdP AS the target Resource AS does not trust (rejects + // ID-JAGs whose `iss` matches). + untrustedIdpIssuer: z + .string() + .url('Invalid untrusted IdP issuer URL') + .optional(), + // [6] URL of an MCP Server the Resource AS trusts; used as the ID-JAG + // `resource`. Optional — only needed for scenarios exercising `resource`. + trustedMcpServer: z.string().url('Invalid trusted MCP server URL').optional(), + // [7] URL of an MCP Server the Resource AS does not trust; used as the ID-JAG + // `resource`. Optional — only needed for scenarios exercising `resource`. + untrustedMcpServer: z + .string() + .url('Invalid untrusted MCP server URL') + .optional(), + // [8] OAuth 2.0 scope the Resource AS recognises; used as the ID-JAG `scope`. + // Optional — only needed for scenarios exercising `scope`. + scope: z.string().min(1, 'Scope cannot be empty').optional(), + // [9] User id registered with the target Resource AS; the Resource AS is + // expected to place this value in the `sub` claim of the access token it + // issues for the linked IdP-registered user (see `idpSub`). Optional — + // only needed for scenarios exercising `sub`. + sub: z.string().min(1, 'Subject cannot be empty').optional(), + // [10] User id registered with the trusted IdP AS for that same person; + // used as the ID-JAG `sub` claim. The IdP and the Resource AS may assign the + // same human different ids, so this is intentionally distinct from `sub` + // above. Optional — only needed for scenarios exercising `sub`. + idpSub: z.string().min(1, 'Subject cannot be empty').optional() +}); + +export type ResourceAuthorizationServerOptions = z.infer< + typeof ResourceAuthorizationServerOptionsSchema +>; + // Interactive command options schema export const InteractiveOptionsSchema = z.object({ scenario: z diff --git a/src/types.ts b/src/types.ts index ebe75a27..7f725eec 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,9 @@ import type { RunContext } from './connection'; import type { ScenarioContext } from './mock-server'; -import type { AuthorizationServerOptions } from './schemas'; +import type { + AuthorizationServerOptions, + ResourceAuthorizationServerOptions +} from './schemas'; export type CheckStatus = | 'SUCCESS' @@ -159,3 +162,13 @@ export interface ClientScenarioForAuthorizationServer { details: Record ): Promise; } + +export interface ScenarioForResourceAuthorizationServer { + name: string; + description: string; + source: ScenarioSource; + run( + options: ResourceAuthorizationServerOptions, + details: Record + ): Promise; +}