|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { HttpStandardHeadersScenario } from './http-standard-headers'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Negative test for SEP-2243 standard-header checks: a client that omits |
| 6 | + * Mcp-Method on a POST must produce a FAILURE row, and one that includes it |
| 7 | + * must produce SUCCESS. Pins the check id so coverage is tracked. |
| 8 | + */ |
| 9 | +describe('HttpStandardHeadersScenario (SEP-2243) — negative', () => { |
| 10 | + async function postInitialize( |
| 11 | + serverUrl: string, |
| 12 | + extraHeaders: Record<string, string> |
| 13 | + ): Promise<void> { |
| 14 | + await fetch(serverUrl, { |
| 15 | + method: 'POST', |
| 16 | + headers: { |
| 17 | + 'Content-Type': 'application/json', |
| 18 | + Accept: 'application/json, text/event-stream', |
| 19 | + ...extraHeaders |
| 20 | + }, |
| 21 | + body: JSON.stringify({ |
| 22 | + jsonrpc: '2.0', |
| 23 | + id: 1, |
| 24 | + method: 'initialize', |
| 25 | + params: { |
| 26 | + protocolVersion: 'DRAFT-2026-v1', |
| 27 | + clientInfo: { name: 'neg-test', version: '0' }, |
| 28 | + capabilities: {} |
| 29 | + } |
| 30 | + }) |
| 31 | + }); |
| 32 | + } |
| 33 | + |
| 34 | + it('FAILs client-mcp-method-header-initialize when Mcp-Method is missing', async () => { |
| 35 | + const scenario = new HttpStandardHeadersScenario(); |
| 36 | + const { serverUrl } = await scenario.start(); |
| 37 | + try { |
| 38 | + await postInitialize(serverUrl, {}); // no Mcp-Method header |
| 39 | + const checks = scenario.getChecks(); |
| 40 | + const check = checks.find( |
| 41 | + (c) => c.id === 'client-mcp-method-header-initialize' |
| 42 | + ); |
| 43 | + expect(check?.status).toBe('FAILURE'); |
| 44 | + } finally { |
| 45 | + await scenario.stop(); |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + it('SUCCEEDs client-mcp-method-header-initialize when Mcp-Method matches', async () => { |
| 50 | + const scenario = new HttpStandardHeadersScenario(); |
| 51 | + const { serverUrl } = await scenario.start(); |
| 52 | + try { |
| 53 | + await postInitialize(serverUrl, { 'Mcp-Method': 'initialize' }); |
| 54 | + const checks = scenario.getChecks(); |
| 55 | + const check = checks.find( |
| 56 | + (c) => c.id === 'client-mcp-method-header-initialize' |
| 57 | + ); |
| 58 | + expect(check?.status).toBe('SUCCESS'); |
| 59 | + } finally { |
| 60 | + await scenario.stop(); |
| 61 | + } |
| 62 | + }); |
| 63 | + |
| 64 | + it('getChecks() is idempotent', async () => { |
| 65 | + const scenario = new HttpStandardHeadersScenario(); |
| 66 | + const { serverUrl } = await scenario.start(); |
| 67 | + try { |
| 68 | + await postInitialize(serverUrl, { 'Mcp-Method': 'initialize' }); |
| 69 | + const first = scenario.getChecks(); |
| 70 | + const second = scenario.getChecks(); |
| 71 | + expect(second.length).toBe(first.length); |
| 72 | + } finally { |
| 73 | + await scenario.stop(); |
| 74 | + } |
| 75 | + }); |
| 76 | +}); |
0 commit comments