Skip to content

Commit

Permalink
fix: hanging on basic auth requests in chromium browsers (#27781)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthemanuel committed Sep 11, 2023
1 parent 70248ab commit a1161c9
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 7 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _Released 09/12/2023 (PENDING)_

- 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/issues/27771).
- 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).
- 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)

**Dependency Updates:**

Expand Down
31 changes: 24 additions & 7 deletions packages/socket/lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ import type { SocketShape } from './types'

export type { Socket } from 'socket.io-client'

const sockets: {[key: string]: CDPBrowserSocket} = {}
declare global {
interface Window {
cypressSockets: {[key: string]: CDPBrowserSocket}
}
}

let chromium = false

export function client (uri: string, opts?: Partial<ManagerOptions & SocketOptions>): SocketShape {
if (chromium) {
const fullNamespace = `${opts?.path}${uri}`

if (!sockets[fullNamespace]) {
sockets[fullNamespace] = new CDPBrowserSocket(fullNamespace)
// When running in Chromium and with a baseUrl set to something that includes basic auth: (e.g. http://user:pass@localhost:1234), the assets
// will load twice. Thus, we need to add the cypress sockets to the window object rather than just relying on a local variable.
window.cypressSockets ||= {}
if (!window.cypressSockets[fullNamespace]) {
window.cypressSockets[fullNamespace] = new CDPBrowserSocket(fullNamespace)
}

return sockets[fullNamespace]
// Connect the socket regardless of whether or not we have newly created it
window.cypressSockets[fullNamespace].connect()

return window.cypressSockets[fullNamespace]
}

return io(uri, opts)
Expand All @@ -27,11 +38,17 @@ export function createWebsocket ({ path, browserFamily }: { path: string, browse

const fullNamespace = `${path}/default`

if (!sockets[fullNamespace]) {
sockets[fullNamespace] = new CDPBrowserSocket(fullNamespace)
// When running in Chromium and with a baseUrl set to something that includes basic auth: (e.g. http://user:pass@localhost:1234), the assets
// will load twice. Thus, we need to add the cypress sockets to the window object rather than just relying on a local variable.
window.cypressSockets ||= {}
if (!window.cypressSockets[fullNamespace]) {
window.cypressSockets[fullNamespace] = new CDPBrowserSocket(fullNamespace)
}

return sockets[fullNamespace]
// Connect the socket regardless of whether or not we have newly created it
window.cypressSockets[fullNamespace].connect()

return window.cypressSockets[fullNamespace]
}

return io({
Expand Down
2 changes: 2 additions & 0 deletions packages/socket/lib/cdp-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export class CDPBrowserSocket extends Emitter implements SocketShape {
if (!cypressSocket.send) {
cypressSocket.send = send
}
}

connect () {
// Set timeout so that the connect event is emitted after the constructor returns and the user has a chance to attach a listener
setTimeout(() => {
super.emit('connect')
Expand Down
55 changes: 55 additions & 0 deletions system-tests/__snapshots__/base_url_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,58 @@ exports['e2e baseUrl / http / passes'] = `
`

exports['e2e baseUrl / https basic auth / passes'] = `
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (base_url.cy.js) │
│ Searched: cypress/e2e/base_url.cy.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: base_url.cy.js (1 of 1)
base url
✓ can visit
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: false │
│ Duration: X seconds │
│ Spec Ran: base_url.cy.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ base_url.cy.js XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 1 1 - - -
`
21 changes: 21 additions & 0 deletions system-tests/test/base_url_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ describe('e2e baseUrl', () => {
})
})

context('https basic auth', () => {
systemTests.setup({
servers: {
port: 443,
https: true,
onServer,
},
settings: {
e2e: {
baseUrl: 'https://test:test@localhost/app',
},
},
})

systemTests.it('passes', {
spec: 'base_url.cy.js',
browser: 'chrome',
snapshot: true,
})
})

context('http', () => {
systemTests.setup({
servers: {
Expand Down

5 comments on commit a1161c9

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on a1161c9 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.2.0/linux-x64/develop-a1161c90e07280b44474d68209570ae222fc4501/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on a1161c9 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.2.0/linux-arm64/develop-a1161c90e07280b44474d68209570ae222fc4501/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on a1161c9 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.2.0/darwin-arm64/develop-a1161c90e07280b44474d68209570ae222fc4501/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on a1161c9 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.2.0/darwin-x64/develop-a1161c90e07280b44474d68209570ae222fc4501/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on a1161c9 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.2.0/win32-x64/develop-a1161c90e07280b44474d68209570ae222fc4501/cypress.tgz

Please sign in to comment.