Cypress crashes on websocket upgrade request over https after update from 9.7.0 to 10.0.3
See original GitHub issueCurrent behavior
After I updated my Cypress Version from 9.7.0 to 10.0.3 Cypress crashes on all my tests, which are executed against our test environment. The same tests on localhost are still working. On the test environment I use a client certificate for authentication. I can start the test and while its running, Cypress crashes with the following error, when my application tries to open a websocket connection over https:
Cannot read properties of undefined (reading 'port')
TypeError: Cannot read properties of undefined (reading 'port')
at ClientCertificateStore.getClientCertificateAgentOptionsForUrl (C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\packages\network\lib\client-certificates.js:128:34)
at C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\packages\network\lib\agent.js:133:81
at getFirstWorkingFamily (C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\packages\network\lib\agent.js:87:16)
at CombinedAgent.addRequest (C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\packages\network\lib\agent.js:129:16)
at new ClientRequest (node:_http_client:305:16)
at Object.request (node:https:353:10)
at Array.stream (C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\node_modules\http-proxy\lib\http-proxy\passes\ws-incoming.js:103:80)
at ProxyServer.<anonymous> (C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\node_modules\http-proxy\lib\http-proxy\index.js:81:21)
at ServerE2E.proxyWebsockets (C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\packages\server\lib\server-base.js:312:26)
at ServerE2E.onUpgrade (C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\packages\server\lib\server-base.js:381:21)
at Server.<anonymous> (C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\packages\server\lib\server-e2e.js:60:67)
at C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\packages\server\lib\server-base.js:390:28
at Array.map (<anonymous>:null:null)
at ServerE2E.onSniUpgrade (C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\packages\server\lib\server-base.js:389:25)
at Server._onUpgrade (C:\Users\U807050\AppData\Local\Cypress\Cache\10.0.3\Cypress\resources\app\packages\https-proxy\lib\server.js:97:17)
at Server.emit (node:events:390:28)
at Server.emit (node:domain:475:12)
at onParserExecuteCommon (node:_http_server:727:14)
at onParserExecute (node:_http_server:640:3)
After some debugging I could figure out the following problem:
_.assign(options, clientCertificateStore.getClientCertificateAgentOptionsForUrl(options.uri))
(https://github.com/cypress-io/cypress/blob/develop/packages/network/lib/agent.ts#L192)
here the options
do not have a uri
property.
because of this in the client.certificates.js
(https://github.com/cypress-io/cypress/blob/develop/packages/network/lib/client-certificates.ts#L1540) the requestUrl
is undefined, which leads Cypress to crash.
At this point _.assign(options, clientCertificateStore.getClientCertificateAgentOptionsForUrl(options.uri))
, the options
has the following structure: options.txt
As you can see, there is no uri
property…
I could not figure out, why it was working before the Cypress update. Maybe it wasn’t working to but Cypress could handle the error.
And maybe there is some connection to this Issue: https://github.com/cypress-io/cypress/issues/19722
Desired behavior
Cypress should not crash, when an application tries to open a websocket connection over https.
Test code to reproduce
describe('Open Application with websockets', () => {
it('Open Application with websockets', () => {
cy.visit('https://websocketstest.com/')
});
});
Cypress Version
10.0.3
Other
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:17 (4 by maintainers)
Top GitHub Comments
Same issue here with 10.3.0. When is it resolved? I don’t wanna go back to Version 9.7.
Cannot read properties of undefined (reading 'port') TypeError: Cannot read properties of undefined (reading 'port') at ClientCertificateStore.getClientCertificateAgentOptionsForUrl (xxxxxx\node_modules\.bin\cypressbin\10.3.0\Cypress\resources\app\packages\network\lib\client-certificates.js:127:34)
Hey @MJohner. Sorry for the delay! I was able to add your code to the reproduction repository and was able to reproduce it quite easily 😄 . Next step is to get this issue routed over to a team to prioritize .
Repository is up to date here.