|
| 1 | +import { describe, it, expect } from '@jest/globals'; |
| 2 | +import { DEFAULT_CORS_CONFIG } from '../../../src/transports/sse/types.js'; |
| 3 | + |
| 4 | +describe('CORS header consistency between transports', () => { |
| 5 | + it('DEFAULT_CORS_CONFIG should include all necessary headers', () => { |
| 6 | + expect(DEFAULT_CORS_CONFIG.allowHeaders).toContain('Content-Type'); |
| 7 | + expect(DEFAULT_CORS_CONFIG.allowHeaders).toContain('Authorization'); |
| 8 | + expect(DEFAULT_CORS_CONFIG.allowHeaders).toContain('Mcp-Session-Id'); |
| 9 | + expect(DEFAULT_CORS_CONFIG.allowHeaders).toContain('Last-Event-ID'); |
| 10 | + expect(DEFAULT_CORS_CONFIG.allowHeaders).toContain('x-api-key'); |
| 11 | + expect(DEFAULT_CORS_CONFIG.allowHeaders).toContain('Accept'); |
| 12 | + }); |
| 13 | + |
| 14 | + it('DEFAULT_CORS_CONFIG should expose necessary headers', () => { |
| 15 | + expect(DEFAULT_CORS_CONFIG.exposeHeaders).toContain('Content-Type'); |
| 16 | + expect(DEFAULT_CORS_CONFIG.exposeHeaders).toContain('Authorization'); |
| 17 | + expect(DEFAULT_CORS_CONFIG.exposeHeaders).toContain('Mcp-Session-Id'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('DEFAULT_CORS_CONFIG should allow DELETE method for session termination', () => { |
| 21 | + expect(DEFAULT_CORS_CONFIG.allowMethods).toContain('DELETE'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('HTTP stream transport should use DEFAULT_CORS_CONFIG as fallback', async () => { |
| 25 | + const { readFileSync } = await import('fs'); |
| 26 | + const httpSource = readFileSync('src/transports/http/server.ts', 'utf-8'); |
| 27 | + |
| 28 | + // Should import DEFAULT_CORS_CONFIG |
| 29 | + expect(httpSource).toContain('DEFAULT_CORS_CONFIG'); |
| 30 | + |
| 31 | + // Should NOT contain hardcoded restrictive headers |
| 32 | + expect(httpSource).not.toContain("'Content-Type, Authorization, Mcp-Session-Id'"); |
| 33 | + }); |
| 34 | + |
| 35 | + it('DEFAULT_CORS_CONFIG should have maxAge set', () => { |
| 36 | + expect(DEFAULT_CORS_CONFIG.maxAge).toBeDefined(); |
| 37 | + expect(DEFAULT_CORS_CONFIG.maxAge).toBe('86400'); |
| 38 | + }); |
| 39 | +}); |
0 commit comments