Skip to content

Commit d920205

Browse files
committed
test fixes
1 parent d75a414 commit d920205

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

packages/middleware/express/test/express.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,13 @@ describe('@modelcontextprotocol/express', () => {
141141
});
142142

143143
test('should skip host header validation when skipHostHeaderValidation is true', () => {
144+
// HTTP-level verification is in integration tests (test/integration/test/server.test.ts)
144145
const app = createMcpExpressApp({ host: '127.0.0.1', skipHostHeaderValidation: true });
145-
146146
expect(app).toBeDefined();
147-
// Localhost validation would normally be applied, but skipHostHeaderValidation disables it
148147
});
149148

150149
test('should skip host header validation for 0.0.0.0 when skipHostHeaderValidation is true', () => {
151150
const app = createMcpExpressApp({ host: '0.0.0.0', skipHostHeaderValidation: true });
152-
153151
expect(app).toBeDefined();
154152
});
155153

test/integration/test/server.test.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,31 +2308,34 @@ describe('createMcpExpressApp', () => {
23082308
expect(response.status).toBe(403);
23092309
});
23102310

2311-
test('should warn when binding to 0.0.0.0', () => {
2312-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
2313-
createMcpExpressApp({ host: '0.0.0.0' });
2314-
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('0.0.0.0'));
2315-
warnSpy.mockRestore();
2311+
test('should not apply host validation for 0.0.0.0 without allowedHosts', async () => {
2312+
const app = createMcpExpressApp({ host: '0.0.0.0' });
2313+
app.post('/test', (_req: Request, res: Response) => {
2314+
res.json({ success: true });
2315+
});
2316+
2317+
// No host validation applied, so any host should be accepted
2318+
const response = await supertest(app).post('/test').set('Host', 'anything.com:3000').send({});
2319+
expect(response.status).toBe(200);
23162320
});
23172321

2318-
test('should warn when binding to :: (IPv6 all interfaces)', () => {
2319-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
2320-
createMcpExpressApp({ host: '::' });
2321-
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('::'));
2322-
warnSpy.mockRestore();
2322+
test('should skip host validation when skipHostHeaderValidation is true', async () => {
2323+
const app = createMcpExpressApp({ host: '127.0.0.1', skipHostHeaderValidation: true });
2324+
app.post('/test', (_req: Request, res: Response) => {
2325+
res.json({ success: true });
2326+
});
2327+
2328+
// Localhost validation would normally block this, but skipHostHeaderValidation disables it
2329+
const response = await supertest(app).post('/test').set('Host', 'evil.com:3000').send({});
2330+
expect(response.status).toBe(200);
23232331
});
23242332

23252333
test('should use custom allowedHosts when provided', async () => {
2326-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
23272334
const app = createMcpExpressApp({ host: '0.0.0.0', allowedHosts: ['myapp.local', 'localhost'] });
23282335
app.post('/test', (_req: Request, res: Response) => {
23292336
res.json({ success: true });
23302337
});
23312338

2332-
// Should not warn when allowedHosts is provided
2333-
expect(warnSpy).not.toHaveBeenCalled();
2334-
warnSpy.mockRestore();
2335-
23362339
// Should allow myapp.local
23372340
const allowedResponse = await supertest(app).post('/test').set('Host', 'myapp.local:3000').send({});
23382341
expect(allowedResponse.status).toBe(200);

0 commit comments

Comments
 (0)