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

Cannot clear cookie set on multiple subdomains #5723

Closed
aronmgv opened this issue Nov 18, 2019 · 8 comments
Closed

Cannot clear cookie set on multiple subdomains #5723

aronmgv opened this issue Nov 18, 2019 · 8 comments
Labels
topic: cookies 🍪 type: regression A bug that didn't appear until a specific Cy version release v3.5.0 🐛 Issue present since 3.5.0

Comments

@aronmgv
Copy link

aronmgv commented Nov 18, 2019

As mentioned here using command cy.clearCookie('nameOfCookie') we should be able to delete cookie no matter what.. but apparently since then behaviour has changed..

Didn't find an official way to clear the whitelist so tried setting defaults back to undefined or empty array - no effect whatsoever..

Cypress.Cookies.defaults({
    whitelist: [] / undefined
});

Cypress v 3.5.0.

Any other ideas how to remove the cookie which was whitelisted before?? Thx

@jennifer-shehane
Copy link
Member

We will need a fully reproducible example provided. We have tests for clearing cookies and likely there is something more complex involved where your issue is occuring. Provide a complete example or we cannot move forward with fixing your issue.

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Nov 18, 2019
@aronmgv
Copy link
Author

aronmgv commented Nov 18, 2019

Pretty straightforward problem.. simple provide a way to clear a cookie which was whitelisted before.

The login function has this inside (so we dont have to login before each test):

Cypress.Cookies.defaults({
    whitelist: ['jwt-token','csrf-token']
});

During the testing I need to login as different user to test its profile.. the way to do it is to clear jwt-token along with csrf-token what I am not able to perform in any way shape or form..

@bvdr
Copy link

bvdr commented Dec 23, 2019

Here is my workaround to clear cookies that are set using whitelist regex and set them again:

it("Clear browser cookies and localstorage", function(){
  
  //Visit URL
  const host_url = Cypress.env('host_url');
  cy.visit(host_url)

  // Empty defaults
  Cypress.Cookies.defaults({
    whitelist: []
  });

  //Clear localStrage
  cy.clearLocalStorage()

  //Clear Cookies
  cy.clearCookies()

  // Set defaults
  Cypress.Cookies.defaults({
    whitelist: /wordpress_.*|woocommerce_.*|wp_woocommerce_.*/
  })
})

@aelmekeev
Copy link
Contributor

We see the same issue after upgrade to 3.5.0+ of Cypress (going to check 3.8.1 today and see if it will help). It's not possible to reproduce it since it's flaky.

@aelmekeev
Copy link
Contributor

We were able to identify the root cause of "inconsistency" on our side. The reason was in fact that we had two cookies with the same name but different domains. clearCookie did remove only one of those two cookies. I'm not 100% sure that this is exact issue that @MacGyver27 is facing but this is what we've faced.

There is certainly a difference in behaviour between 3.4.1 and 3.5.0 but I'm not 100% sure if it's expected or not.

@jennifer-shehane, this is how it can be reproduced:

./cypress.json

{
  "baseUrl": "https://dev.mysql.com",
  "integrationFolder": "cypress/integration",
  "testFiles": "**/*.js",
  "screenshotOnRunFailure": false,
  "video": false
}

./cypress/integration/spec.js

describe('clearCookie', () => {
  it('should remove all cookies with specified name', () => {
    cy.setCookie('test_cookie', 'value1', {
      domain: 'mysql.com'
    })
    cy.setCookie('test_cookie', 'value2', {
      domain: 'dev.mysql.com'
    })
    cy.getCookie('test_cookie')
      .should('exist')
    cy.clearCookie('test_cookie')
    cy.getCookie('test_cookie')
      .should('not.exist')
  })
})
docker run -it -v $PWD:/e2e -w /e2e cypress/included:3.4.1
      Spec                                                Tests  Passing  Failing  Pending  Skipped 
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔ spec.js                                   221ms        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    All specs passed!                           221ms        1        1        -        -        -  
docker run -it -v $PWD:/e2e -w /e2e cypress/included:3.5.0
 1) clearCookie should remove all cookies with specified name:
     AssertionError: expected { Object (name, value, ...) } to not exist
      at Assertion.<anonymous> (https://dev.mysql.com/__cypress/runner/cypress_runner.js:85804:27)
      at Assertion.get (https://dev.mysql.com/__cypress/runner/cypress_runner.js:7750:37)

     Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✖  spec.js                                  520ms        1        -        1        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✖  1 of 1 failed (100%)                     520ms        1        -        1        -        -  

@jennifer-shehane
Copy link
Member

I can still reproduce the issue provided by @aelmekeev. The cookie is not removed in Cypress 3.5.0+.

cypress.json

{
  "baseUrl": "https://dev.mysql.com"
}

spec.js

it('should remove all cookies with specified name', () => {
  cy.setCookie('test_cookie', 'value1', {
    domain: 'mysql.com'
  })
  cy.setCookie('test_cookie', 'value2', {
    domain: 'dev.mysql.com'
  })

  cy.getCookie('test_cookie').should('exist').then((cookie) => {
    cy.log(cookie)
  })
  cy.clearCookie('test_cookie')
  cy.getCookie('test_cookie').should('not.exist')
})

Screen Shot 2020-10-20 at 3 08 59 PM

3.4.1

Screen Shot 2020-10-20 at 3 04 05 PM

3.5.0

Screen Shot 2020-10-20 at 3 05 52 PM

@jennifer-shehane jennifer-shehane changed the title Cannot clear whitelisted cookie Cannot clear cookie set on multiple subdomains Oct 20, 2020
@jennifer-shehane jennifer-shehane added type: regression A bug that didn't appear until a specific Cy version release v3.5.0 🐛 Issue present since 3.5.0 and removed stage: needs information Not enough info to reproduce the issue labels Oct 20, 2020
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Oct 20, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: ready for work The issue is reproducible and in scope labels Nov 23, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 23, 2022

The code for this is done in cypress-io/cypress#24692, 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 Dec 6, 2022

Released in 12.0.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v12.0.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Dec 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cookies 🍪 type: regression A bug that didn't appear until a specific Cy version release v3.5.0 🐛 Issue present since 3.5.0
Projects
None yet
Development

No branches or pull requests

5 participants