|
| 1 | +import type { Scenario, ConformanceCheck } from '../../../types.js'; |
| 2 | +import { ScenarioUrls } from '../../../types.js'; |
| 3 | +import { createAuthServer } from './helpers/createAuthServer.js'; |
| 4 | +import { createServer } from './helpers/createServer.js'; |
| 5 | +import { ServerLifecycle } from './helpers/serverLifecycle.js'; |
| 6 | +import { SpecReferences } from './spec-references.js'; |
| 7 | + |
| 8 | +/** |
| 9 | + * Fixed client metadata URL that clients should use for CIMD tests. |
| 10 | + * This URL doesn't need to resolve - the server will accept it as-is |
| 11 | + * and use hardcoded metadata. |
| 12 | + */ |
| 13 | +export const CIMD_CLIENT_METADATA_URL = |
| 14 | + 'https://conformance-test.local/client-metadata.json'; |
| 15 | + |
| 16 | +/** |
| 17 | + * Scenario: Client ID Metadata Documents (SEP-991/URL-based client IDs) |
| 18 | + * |
| 19 | + * Tests that when a server advertises client_id_metadata_document_supported=true, |
| 20 | + * clients SHOULD use a URL as their client_id instead of using dynamic client |
| 21 | + * registration. |
| 22 | + */ |
| 23 | +export class AuthBasicCIMDScenario implements Scenario { |
| 24 | + name = 'auth/basic-cimd'; |
| 25 | + description = |
| 26 | + 'Tests OAuth flow with Client ID Metadata Documents (SEP-991/URL-based client IDs). Server advertises client_id_metadata_document_supported=true and client should use URL as client_id instead of DCR.'; |
| 27 | + private authServer = new ServerLifecycle(); |
| 28 | + private server = new ServerLifecycle(); |
| 29 | + private checks: ConformanceCheck[] = []; |
| 30 | + |
| 31 | + async start(): Promise<ScenarioUrls> { |
| 32 | + this.checks = []; |
| 33 | + |
| 34 | + const authApp = createAuthServer(this.checks, this.authServer.getUrl, { |
| 35 | + clientIdMetadataDocumentSupported: true, |
| 36 | + onAuthorizationRequest: (data) => { |
| 37 | + // Check if client used URL-based client ID |
| 38 | + const usedUrlClientId = data.clientId === CIMD_CLIENT_METADATA_URL; |
| 39 | + this.checks.push({ |
| 40 | + id: 'cimd-client-id-used', |
| 41 | + name: 'Client ID Metadata Document Usage', |
| 42 | + description: usedUrlClientId |
| 43 | + ? 'Client correctly used URL-based client ID when server supports client_id_metadata_document_supported' |
| 44 | + : 'Client SHOULD use URL-based client ID when server advertises client_id_metadata_document_supported=true', |
| 45 | + status: usedUrlClientId ? 'SUCCESS' : 'WARNING', |
| 46 | + timestamp: data.timestamp, |
| 47 | + specReferences: [ |
| 48 | + SpecReferences.MCP_CLIENT_ID_METADATA_DOCUMENTS, |
| 49 | + SpecReferences.IETF_CIMD |
| 50 | + ], |
| 51 | + details: { |
| 52 | + expectedClientId: CIMD_CLIENT_METADATA_URL, |
| 53 | + actualClientId: data.clientId || 'none' |
| 54 | + } |
| 55 | + }); |
| 56 | + } |
| 57 | + }); |
| 58 | + |
| 59 | + await this.authServer.start(authApp); |
| 60 | + |
| 61 | + const app = createServer( |
| 62 | + this.checks, |
| 63 | + this.server.getUrl, |
| 64 | + this.authServer.getUrl |
| 65 | + ); |
| 66 | + |
| 67 | + await this.server.start(app); |
| 68 | + |
| 69 | + return { serverUrl: `${this.server.getUrl()}/mcp` }; |
| 70 | + } |
| 71 | + |
| 72 | + async stop() { |
| 73 | + await this.authServer.stop(); |
| 74 | + await this.server.stop(); |
| 75 | + } |
| 76 | + |
| 77 | + getChecks(): ConformanceCheck[] { |
| 78 | + // Ensure we have the CIMD check - if not, the client didn't make an auth request |
| 79 | + const hasCimdCheck = this.checks.some( |
| 80 | + (c) => c.id === 'cimd-client-id-used' |
| 81 | + ); |
| 82 | + if (!hasCimdCheck) { |
| 83 | + this.checks.push({ |
| 84 | + id: 'cimd-client-id-used', |
| 85 | + name: 'Client ID Metadata Document Usage', |
| 86 | + description: |
| 87 | + 'Client did not make an authorization request to test CIMD support', |
| 88 | + status: 'FAILURE', |
| 89 | + timestamp: new Date().toISOString(), |
| 90 | + specReferences: [ |
| 91 | + SpecReferences.MCP_CLIENT_ID_METADATA_DOCUMENTS, |
| 92 | + SpecReferences.IETF_CIMD |
| 93 | + ] |
| 94 | + }); |
| 95 | + } |
| 96 | + |
| 97 | + return this.checks; |
| 98 | + } |
| 99 | +} |
0 commit comments