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

Since 3.5.0, a cy.visit that changes superdomain incorrectly clears cookies of other domains. #5756

Closed
flotwig opened this issue Nov 20, 2019 · 2 comments · Fixed by #5702 · May be fixed by ngChile/ngx-devkit-cypress-builder#20 or qsays/grafana#1
Assignees

Comments

@flotwig
Copy link
Contributor

flotwig commented Nov 20, 2019

Current behavior:

Given the following flow:

  1. http://foo.com sets cookie foo=bar and redirects to http://bar.com
  2. http://bar.com returns 200

cy.visit("http://foo.com") with a current superdomain of foo.com will result in no cookies being set, since the superdomain changes and causes the cookies to erroneously be cleared.

Desired behavior:

Cookies are kept from all redirects during a cy.visit.

This can be accomplished by getting rid of the shortcut we take to make cy.visit only send 1 HTTP request, even if superdomain changes. This shortcut is the root of all evil:

## if we have a buffer for this url
## then just respond with its details
## so we are idempotant and do not make
## another request
if obj = buffers.getByOriginalUrl(urlStr)
debug("got previous request buffer for url:", urlStr)
## reset the cookies from the buffer on the browser
return runPhase ->
resolve(
Promise.map obj.details.cookies, (cookie) ->
## prevent prepending a . to the cookie domain if top-level
## navigation occurs as a result of a cy.visit
if _.isUndefined(cookie.hostOnly) && !cookie.domain?.startsWith('.')
cookie.hostOnly = true
automationRequest('set:cookie', cookie)
.return(obj.details)
)

Steps to reproduce: (app code and test code)

See #5702 for reproduction.

Versions

Cypress >=3.5.0

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 26, 2019

The code for this is done in cypress-io/cypress#5702, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 27, 2019

Released in 3.7.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.