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

Fix cy.clearCookie, fix HTTP redirect behavior, fix cy.visit HTTPS baseurl behavior #5478

Merged
merged 33 commits into from
Nov 8, 2019

Conversation

flotwig
Copy link
Contributor

@flotwig flotwig commented Oct 25, 2019

User facing changelog

  • Fixed a bug where cy.clearCookie would not act as expected under certain baseUrls. #.5453
  • Fixed a bug where HTTP redirects could cause strange behavior, including cookies not being set as expected, leading to authentication issues and other problems in tests. #.5436, #.5432
  • Fixed a bug where Cypress would not send the expected headers or request body in a cy.visit to an HTTPS URL using the default port, 443. #.5367
  • Fixed a bug where Cypress would crash with the error Failed to parse or set cookie named "foo". when loading certain websites. #.4990

Additional details

  • Previously, when doing Network.deleteCookies in response to a clear:cookie request, we would directly use the user-supplied domain.
    • However, the real domain Chrome expects may be different.
    • This PR changes clear:cookie to use the result of Network.getAllCookies to get the correct domain parameter for the Network.deleteCookies call
  • Even after #.5432 was fixed, there was still an issue with setting cookies on redirects
    • This is because something was seriously wrong with the way we were doing req.init - after a request finished all of it's redirects, I could see the entire redirect stack being popped off, as if the redirects were happening again in reverse
    • This really messed up setting cookies on the correct domain
    • I found a PR to request that would let us return a Promise from options.followRedirect, so we don't need our undocumented, hard-to-understand req.init hack anymore: Support asynchronous followRedirect filter (callback or Promise) request/request#2647
    • Created a cypress-io/request repository to hold patches to request, now that the real request is unmaintained: https://github.com/cypress-io/request
    • After updating the redirect code in request.coffee to simply return a Promise instead of doing the req.init stuff, it works as desired: 7c0304f
    • This should fix #.5436
  • It looks like cy.getCookies is only returning cookies for the current domain, not all domains. This is probably wrong. cy.getCookies() is empty but cookies are still sent #1547
    • Does this also affect cy.clearCookies? cy.clearCookies should clear *ALL* cookies of all domains #408
    • It appears that the Cypress cookies commands are forced to use the current superdomain as the domain for all cookie operations, which seems like an error - how are users supposed to see cookies not for the exact current superdomain?
    • Talked to @brian-mann about this. It's due to the old limitations from the extension API for why it's like this today, so any changes would need to be backwards-compatible with current API usage.
      • Added cy.clear/getCookies({ domain: null }) to clear/return ALL cookies for testing
  • Fixed #.5367 by ensuring that buffers always adds the default port to a URL when storing/retrieving a buffer
  • Fixed a bug where the behavior of setting cookies could differ depending on if cy.visit caused a navigation or not.

How has the user experience changed?

PR Tasks

  • Have tests been added/updated?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 25, 2019

Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.

  • Please write [WIP] in the title of your Pull Request if your PR is not ready for review - someone will review your PR as soon as the [WIP] is removed.
  • Please familiarize yourself with the PR Review Checklist and feel free to make updates on your PR based on these guidelines.

PR Review Checklist

If any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'.

User Experience

  • The feature/bugfix is self-documenting from within the product.
  • The change provides the end user with a way to fix their problem (no dead ends).

Functionality

  • The code works and performs its intended function with the correct logic.
  • Performance has been factored in (for example, the code cleans up after itself to not cause memory leaks).
  • The code guards against edge cases and invalid input and has tests to cover it.

Maintainability

  • The code is readable (too many nested 'if's are a bad sign).
  • Names used for variables, methods, etc, clearly describe their function.
  • The code is easy to understood and there are relevant comments explaining.
  • New algorithms are documented in the code with link(s) to external docs (flowcharts, w3c, chrome, firefox).
  • There are comments containing link(s) to the addressed issue (in tests and code).

Quality

  • The change does not reimplement code.
  • There's not a module from the ecosystem that should be used instead.
  • There is no redundant or duplicate code.
  • There are no irrelevant comments left in the code.
  • Tests are testing the code’s intended functionality in the best way possible.

Internal

  • The original issue has been tagged with a release in ZenHub.

@cypress
Copy link

cypress bot commented Nov 1, 2019



Test summary

3474 0 46 0


Run details

Project cypress
Status Passed
Commit 7f33376
Started Nov 7, 2019 10:37 PM
Ended Nov 7, 2019 10:40 PM
Duration 03:26 💡
OS Linux Debian - 9.8
Browser Multiple

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@flotwig flotwig changed the title [WIP] Fix cy.clearCookie [WIP] Fix cy.clearCookie, fix HTTP redirect behavior, fix cy.visit HTTPS baseurl behavior Nov 6, 2019
@flotwig flotwig changed the title [WIP] Fix cy.clearCookie, fix HTTP redirect behavior, fix cy.visit HTTPS baseurl behavior Fix cy.clearCookie, fix HTTP redirect behavior, fix cy.visit HTTPS baseurl behavior Nov 6, 2019
@nids2307
Copy link

nids2307 commented Nov 8, 2019

which cypress version will have this fix incorporated?

@flotwig
Copy link
Contributor Author

flotwig commented Nov 8, 2019

@nids2307 3.6.1, which will be released later today, if not today then Monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants