Skip to content
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

Cypress crash with literal IPv6 URL in cy.visit #25950

Open
MikeMcC399 opened this issue Feb 25, 2023 · 9 comments
Open

Cypress crash with literal IPv6 URL in cy.visit #25950

MikeMcC399 opened this issue Feb 25, 2023 · 9 comments
Labels
E2E Issue related to end-to-end testing topic: visit Problems with cy.visit command type: bug

Comments

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Feb 25, 2023

Current behavior

Cypress crashes if a literal IPv6 URL is used as parameter for cy.visit, for example:

cy.visit('http://[::1]:3000')

causes:

Invalid URL
TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:372:5)
    at URL.onParseError (node:internal/url:553:9)
    at new URL (node:internal/url:629:5)
    at Object.q (<embedded>:4805:38028)
    at _.get (<embedded>:5213:71723)
    at _.set (<embedded>:5213:73007)
    at <embedded>:5226:8345
    at <embedded>:4805:38908
    at m.<anonymous> (<embedded>:2781:13724)
    at m.emit (node:events:539:35)
    at T (<embedded>:2216:61720)
    at w (<embedded>:2216:60611)
    at process.processTicksAndRejections (node:internal/process/task_queues:85:21)

Desired behavior

  1. Cypress should not crash
  2. Cypress should accept URLs with IPv6 literals according to RFC3986: URI Generic Syntax in cy.visit. They do not cause a problem in cy.request.

Test code to reproduce

cy.visit('http://[::1]:3000')

Repository to reproduce:

clone https://github.com/MikeMcC399/http-server-test

npm ci
npm test

Cypress Version

First reported in 12.7.0
Confirmed still an issue in Cypress 13.7.2

Node version

18.19.0 (and 20.12.1)

Operating System

Ubuntu 22.04

Debug Logs

crash_issue_25950.log

  cypress:network:agent addRequest called { isHttps: false, href: 'http://[::1]:3000/' } +60ms
  cypress:network:agent got family { family: 6, href: 'http://[::1]:3000/' } +0ms
  cypress:network:cors Parsed URL { port: '3000', protocol: 'http:', subdomain: null, domain: '', tld: '::1' } +3ms
  cypress:network:cors Parsed URL { port: '3000', protocol: 'http:', subdomain: null, domain: '', tld: '::1' } +1ms
  cypress:network:cors Parsed URL { port: '3000', protocol: 'http:', subdomain: null, domain: '', tld: '::1' } +0ms
  cypress:server:remote-states setting remote state { auth: null, origin: 'http://[::1]:3000', strategy: 'http', fileServer: null, domainName: '::1', props: { port: '3000', protocol: 'http:', subdomain: null, domain: '', tld: '::1' } } for http://::1:3000 +4ms
Invalid URL
TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:399:5)
    at URL.onParseError (node:internal/url:566:9)
    at new URL (node:internal/url:646:5)
    at Object.q (<embedded>:4410:33142)
    at _.get (<embedded>:4513:69481)
    at _.set (<embedded>:4513:70765)
    at <embedded>:4526:18564
    at <embedded>:4410:34022
    at m.<anonymous> (<embedded>:2525:46704)
    at m.emit (node:events:525:35)
    at E (<embedded>:2525:13651)
    at w (<embedded>:2525:12542)
    at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Related issues

@MikeMcC399
Copy link
Contributor Author

For convenience I also added a GitHub workflow to demonstrate:

https://github.com/MikeMcC399/http-server-test/actions/workflows/test.yml

There is already a debug log posted in the original post.

@flotwig
Copy link
Contributor

flotwig commented Feb 28, 2023

Seems like this is a bug with our usage of parse-domain not parsing IPv6 correctly, based on log output that ::1 is the "tld" of this URL:

2023-02-25T16:19:39.215Z cypress:network:cors Parsed URL { port: '3000', protocol: 'http:', subdomain: null, domain: '', tld: '::1' }

It should be possible to fix this in our parse-domain wrapper here:

export function parseDomain (domain: string, options = {}) {
return _parseDomain(domain, _.defaults(options, {
privateTlds: true,
customTlds: customTldsRe,
}))
}

In the meantime, would cy.visit('http://localhost6:3000') work for you?

@flotwig flotwig added type: bug topic: visit Problems with cy.visit command routed-to-e2e E2E Issue related to end-to-end testing labels Feb 28, 2023
@MikeMcC399
Copy link
Contributor Author

MikeMcC399 commented Feb 28, 2023

@flotwig

Thanks for picking this up! At one point I was trying to use literal IPv6 as a workaround for the wait-on issue. Thanks for the workaround suggestion, which may be helpful for others reading this. At the moment I don't need it, however I wanted to make sure it was reported as a bug.

Temporarily replacing the literal IPv6 by something else according to the system being used would work e.g. according to what is defined in /etc/hosts. In the case of ubuntu on GitHub that would be ip6-localhost. The issue there though is that it is not platform-independent. (I don't know if there is an equivalent on GitHub windows and macos runners. ip6-localhost is not accepted there. I didn't investigate this any further.)

@MikeMcC399
Copy link
Contributor Author

  • In the workaround section of issue wait-on issues with Node.js 18 github-action#811 I mentioned where it would be convenient to be able to include the literal IPv6 loopback address ::1 in the baseUrl declaration to make it consistent with the hostname being used in the wait-on declaration. Due to the bug in this issue here, that is not possible.

  • From the tests I have done so far it seems that you can get away with leaving baseUrl as localhost, but I can't say if that is always going to be the case.

@nagash77 nagash77 added Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed routed-to-e2e labels Apr 19, 2023
@MikeMcC399
Copy link
Contributor Author

This issue is unresolved in Cypress 12.12.0.
Repro repo https://github.com/MikeMcC399/http-server-test is updated to latest versions.

@MikeMcC399
Copy link
Contributor Author

@flotwig

Thanks very much for your pointer to the source of the problem back a few months ago. Are you still involved in Cypress or did you drop out?

@jennifer-shehane
Copy link
Member

Hey @MikeMcC399, flotwig is not on the team at the moment and we are not currently prioritizing this issue.

@jennifer-shehane jennifer-shehane removed the Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. label Jan 2, 2024
@jennifer-shehane
Copy link
Member

Likely a good first step for this would be to pull in the updates from the main https://github.com/peerigon/parse-domain repo into https://github.com/cypress-io/parse-domain - or validate whether our commits on parse-domain are even necessary anymore. There are some breaking changes in usage, so the signature will need updating after it's pulled back into Cypress.

@MikeMcC399
Copy link
Contributor Author

@jennifer-shehane

Cypress is at

"@cypress/parse-domain": "2.4.0",

There are no newer 2.x releases on https://github.com/peerigon/parse-domain/releases and the v3.0.0 already contains breaking changes.

v6.0.0 is the first release with ESM-only support instead of CommonJS.

v8.0.1 is the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing topic: visit Problems with cy.visit command type: bug
Projects
None yet
Development

No branches or pull requests

4 participants