cypress
cypress copied to clipboard
Cypress crashes on websocket upgrade request over https after update from 9.7.0 to 10.0.3
Current 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
Before it worked good. But today I got same issue :/. Can't find the solution, so downgraded to 9.7.0 again. Hope you'll find solution soon. Good luck.
Hey @Mjohner. Thank you for opening an issue. I tried to reproduce with the example you provided but the test didn't seem to fail or produce any failure logs. You provided enough context where we might be able to add a unit test and potentially fix the issue, but a full reproduction would be very beneficial. Would you be able to provide that?
@AtofStryker have you also tried it with the electron browser?
@AtofStryker have you also tried it with the electron browser?
@MJohner I did, but was unable to reproduce in Electron, Chrome, Edge, and Firefox. I put together a reproduction repository here with the test in question. Can you see if you can clone this repository, run yarn
, yarn cypress open
, and select the spec and reproduce the issue?
@AtofStryker thanks for the investigation. I tried it on my private machine and here it works too.🤔 At wednesday I'll try it on my business machine. Maybe its a proxy or certifacte issue.
@MJohner looking forward to hearing how it goes!
@AtofStryker yes with the default configuration it works on my business machine too. What matters are the client certificates. Unfortunately I could not push to your test repository. But the changes are simple:
- Add the cert and key from the appending here and rename them from .txt to .pem:
ca-cert.txt
ca-key.txt
- Add the following client certificate config to
cypress.config.js
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
clientCertificates: [
{
url: 'https://websocketstest.com/',
ca: [],
certs: [
{
key: 'cypress/certs/ca-key.pem',
cert: 'cypress/certs/ca-cert.pem'
}
]
}
]
});
- Run the test and you get the error: https://user-images.githubusercontent.com/47743448/173807899-5359c014-cfbd-4a5d-a84c-7bb1ba2289d1.mp4
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.
I have the same issue with 10.1.0 and 10.2.0. Good to see there is a reproducible version. I hope the issue gets prioritised highly.
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)
I had the same problem after update from 9.5.4 to 10.3.1 :( (checked with electron, chrome and firefox) Cannot read properties of undefined (reading 'port') TypeError: Cannot read properties of undefined (reading 'port') at ClientCertificateStore.getClientCertificateAgentOptionsForUrl (/home/-----/.cache/Cypress/10.3.1/Cypress/resources/app/packages/network/lib/client-certificates.js:127:34) Is any update in this case?
i have the same problem and could fix it by adding the following code in {cypress-cache-folder}/10.3.1/Cypress/resources/app/packages/network/lib/agent.js (from line 134):
if (!options.uri) {
options.uri = url_1.default.parse(options.href);
}
In the repo, its from line 182. Maybe this helps for fixing :) I can't guess all consequences of this change.
Same problem here in 10.3.0. As a quick fix, we decided to disable the webSockets module in our application for Cypress environment because it was not critical for our tests suite. Everyone cannot do that, so we hope this will be fixed soon, have a nice day :)
@MarcAntoineBabe can you please share how did you do it?
Same issue here, we had to downgrade from version 10.4.0 to 9.7.0.
The code for this is done in cypress-io/cypress#23449, but has yet to be released. We'll update this issue and reference the changelog when it's released.
Released in 10.7.0
.
This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v10.7.0, please open a new issue.