-
Notifications
You must be signed in to change notification settings - Fork 1.7k
v2 remove console warns on middleware #1776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d75a414
e44e301
d920205
9ee628f
28fd4ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2308,31 +2308,34 @@ | |
| expect(response.status).toBe(403); | ||
| }); | ||
|
|
||
| test('should warn when binding to 0.0.0.0', () => { | ||
| const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); | ||
| createMcpExpressApp({ host: '0.0.0.0' }); | ||
| expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('0.0.0.0')); | ||
| warnSpy.mockRestore(); | ||
| test('should not apply host validation for 0.0.0.0 without allowedHosts', async () => { | ||
| const app = createMcpExpressApp({ host: '0.0.0.0' }); | ||
| app.post('/test', (_req: Request, res: Response) => { | ||
| res.json({ success: true }); | ||
| }); | ||
|
|
||
| // No host validation applied, so any host should be accepted | ||
| const response = await supertest(app).post('/test').set('Host', 'anything.com:3000').send({}); | ||
| expect(response.status).toBe(200); | ||
| }); | ||
|
Check warning on line 2320 in test/integration/test/server.test.ts
|
||
|
Comment on lines
+2311
to
2320
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Nit: The new test at line 2311 ("should not apply host validation for 0.0.0.0 without allowedHosts") is functionally identical to the pre-existing test at line 2262 ("should not apply host validation when host is 0.0.0.0") — both create an app with Extended reasoning...The DuplicateThe test at line 2262 ("should not apply host validation when host is 0.0.0.0") and the new test at line 2311 ("should not apply host validation for 0.0.0.0 without allowedHosts") are functionally identical:
The only differences are the test name, the specific host header string used, and the older test also asserts How This HappenedBefore this PR, there were two console.warn tests — one for Step-by-Step Proof
Lost CoverageThe old test "should warn when binding to :: (IPv6 all interfaces)" was the only test exercising the ImpactThis is a minor issue — both tests pass fine and no incorrect behavior results. It is test redundancy and a missed opportunity to cover the Suggested FixChange the test at line 2311 to use |
||
|
|
||
| test('should warn when binding to :: (IPv6 all interfaces)', () => { | ||
| const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); | ||
| createMcpExpressApp({ host: '::' }); | ||
| expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('::')); | ||
| warnSpy.mockRestore(); | ||
| test('should skip host validation when skipHostHeaderValidation is true', async () => { | ||
| const app = createMcpExpressApp({ host: '127.0.0.1', skipHostHeaderValidation: true }); | ||
| app.post('/test', (_req: Request, res: Response) => { | ||
| res.json({ success: true }); | ||
| }); | ||
|
|
||
| // Localhost validation would normally block this, but skipHostHeaderValidation disables it | ||
| const response = await supertest(app).post('/test').set('Host', 'evil.com:3000').send({}); | ||
| expect(response.status).toBe(200); | ||
| }); | ||
|
|
||
| test('should use custom allowedHosts when provided', async () => { | ||
| const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); | ||
| const app = createMcpExpressApp({ host: '0.0.0.0', allowedHosts: ['myapp.local', 'localhost'] }); | ||
| app.post('/test', (_req: Request, res: Response) => { | ||
| res.json({ success: true }); | ||
| }); | ||
|
|
||
| // Should not warn when allowedHosts is provided | ||
| expect(warnSpy).not.toHaveBeenCalled(); | ||
| warnSpy.mockRestore(); | ||
|
|
||
| // Should allow myapp.local | ||
| const allowedResponse = await supertest(app).post('/test').set('Host', 'myapp.local:3000').send({}); | ||
| expect(allowedResponse.status).toBe(200); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.