Skip to content

Commit f8b4c59

Browse files
authored
fix: update net stubbing to not intercept requests sent to dev server (#27788)
1 parent 356edfc commit f8b4c59

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

cli/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ _Released 09/12/2023 (PENDING)_
1010
**Bugfixes:**
1111

1212
- Edge cases where `cy.intercept()` would not properly intercept and asset response bodies would not properly be captured for test replay have been addressed. Addressed in [#27771](https://github.com/cypress-io/cypress/pull/27771).
13-
- Fixed an issue where `enter`, `keyup`, and `space` events where not triggering `click` events properly in some versions of Firefox. Addressed in [#27715](https://github.com/cypress-io/cypress/pull/27715).
14-
- Fixed a regression in `13.0.0` where tests using Basic Authorization can potentially hang indefinitely on chromium browsers. Addressed in [#27781](https://github.com/cypress-io/cypress/pull/27781)
13+
- Fixed an issue where `enter`, `keyup`, and `space` events where not triggering `click` events properly in some versions of Firefox. Addressed in [#27715](https://github.com/cypress-io/cypress/pull/27715).
14+
- Fixed a regression in `13.0.0` where tests using Basic Authorization can potentially hang indefinitely on chromium browsers. Addressed in [#27781](https://github.com/cypress-io/cypress/pull/27781).
15+
- Fixed a regression in `13.0.0` where component tests using an intercept that matches all requests can potentially hang indefinitely. Addressed in [#27788](https://github.com/cypress-io/cypress/pull/27788).
1516

1617
**Dependency Updates:**
1718

packages/net-stubbing/lib/server/middleware/request.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ const debug = null
2828
export const SetMatchingRoutes: RequestMiddleware = async function () {
2929
const span = telemetry.startSpan({ name: 'set:matching:routes', parentSpan: this.reqMiddlewareSpan, isVerbose: true })
3030

31+
const url = new URL(this.req.proxiedUrl)
32+
33+
// if this is a request to the dev server, do not match any routes as
34+
// we do not want to allow the user to intercept requests to the dev server
35+
if (url.pathname.startsWith(this.config.devServerPublicPathRoute)) {
36+
span?.end()
37+
38+
return this.next()
39+
}
40+
3141
if (matchesRoutePreflight(this.netStubbingState.routes, this.req)) {
3242
// send positive CORS preflight response
3343
return sendStaticResponse(this, {

packages/proxy/test/integration/net-stubbing.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,43 @@ context('network stubbing', () => {
328328
expect(sendContentLength).to.eq(realContentLength)
329329
})
330330

331+
it('does not intercept requests to the dev server', async () => {
332+
destinationApp.get('/__cypress/src/main.js', (req, res) => res.send('it worked'))
333+
334+
// setup an intercept that matches all requests
335+
// and has a static response
336+
netStubbingState.routes.push({
337+
id: '1',
338+
routeMatcher: {
339+
url: '*',
340+
},
341+
hasInterceptor: false,
342+
staticResponse: {
343+
body: 'foo',
344+
},
345+
getFixture,
346+
matches: 1,
347+
})
348+
349+
config.devServerPublicPathRoute = '/__cypress/src'
350+
351+
// request to the dev server does NOT get intercepted
352+
await supertest(app)
353+
.get(`/http://localhost:${destinationPort}/__cypress/src/main.js`)
354+
.then((res) => {
355+
expect(res.status).to.eq(200)
356+
expect(res.text).to.eq('it worked')
357+
})
358+
359+
// request NOT to the dev server DOES get intercepted
360+
await supertest(app)
361+
.get(`/http://localhost:${destinationPort}/`)
362+
.then((res) => {
363+
expect(res.status).to.eq(200)
364+
expect(res.text).to.eq('foo')
365+
})
366+
})
367+
331368
describe('CSP Headers', () => {
332369
// Loop through valid CSP header names can verify that we handle them
333370
[

0 commit comments

Comments
 (0)