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

cy.setCookie is Not Setting Desired Cookie Expiry #5599

Open
ghost opened this issue Nov 4, 2019 · 14 comments
Open

cy.setCookie is Not Setting Desired Cookie Expiry #5599

ghost opened this issue Nov 4, 2019 · 14 comments
Labels
prevent-stale mark an issue so it is ignored by stale[bot] topic: cookies 🍪 type: bug

Comments

@ghost
Copy link

ghost commented Nov 4, 2019

Current behavior:

cy.setCookie is not setting the expiry as desired.

Desired behavior:

cy.setCookie sets the expiry that the code provides.

Steps to reproduce:

describe('Cypress Cookie Issue', function () {
    it('Expiry Problem', function () {
        let email = '[email protected]'
        let password = 'abc123'
        cy.createAccount(email, password)
        cy.login(email, password)
        cy.visit('/')
        cy.getCookie('jwt').then((jwt) => {
            cy.setCookie('jwt', jwt.value, {expiry: 10000000000})
            cy.getCookie('jwt').then((setJWT) => {
                expect(setJWT.expiry).to.equal(10000000000)
            })
        })
    })
})

image

Versions

Cypress 3.6.0, Chrome 78.

I started experiencing this problem when I upgraded from Cypress 3.2.0 to 3.6.0.

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Nov 4, 2019

Hey @toddmkemp, simplifying this test - it does set a cookies expiry and overwrites an existing set when the cookie is set on the same domain here.

it('Expiry Problem', function () {
  cy.visit('https://example.cypress.io/commands/traversal')
  cy.setCookie('foo', 'bar', { expiry: 50000000 })
  cy.setCookie('foo', 'bar', { expiry: 10000000000 })
  cy.getCookie('foo').then((foo) => {
    expect(foo.expiry).to.equal(10000000000)
  })
})

Screen Shot 2019-11-04 at 2 52 18 PM

We'll need a more specific example of the issue that we can run on our computer exhibiting the exact issue before we can move forward.

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

ghost commented Nov 4, 2019

Hi @jennifer-shehane,

I've investigated a little more and the issue is a little more complex than what I initially thought. Using a similar approach to cookie manipulation that you took, I wrote the following:

describe('Cypress Cookie Issue', function () {

    beforeEach(function () {
        cy.visit('https://en.wikipedia.org/')
    })

    it('Passes', function () {
        cy.getCookie('WMF-Last-Access-Global')
        cy.setCookie('WMF-Last-Access-Global', 'value', {expiry: 10000000000})
        cy.getCookie('WMF-Last-Access-Global').then((cookie) => {
            expect(cookie.expiry).to.equal(10000000000)
        })
    })

    it('Fails', function () {
        cy.getCookie('WMF-Last-Access')
        cy.setCookie('WMF-Last-Access', 'value', {expiry: 10000000000})
        cy.getCookie('WMF-Last-Access').then((cookie) => {
            expect(cookie.expiry).to.equal(10000000000)
        })
    })
})

The first test passes and the second one fails. The only difference between the tests is the cookie itself. Specifically, the domains of the cookies are different which seems to be what is problematic here.

Please let me know if you have questions or if there is anything else I can provide to help you diagnose the issue.

@ghost
Copy link
Author

ghost commented Nov 7, 2019

@jennifer-shehane : Did my latest comments provide any clarity on the matter? I'm happy to continue to investigate if you are still unable to reproduce the problem.

@ghost
Copy link
Author

ghost commented Dec 31, 2019

Hello again @jennifer-shehane. I saw in the release notes for Cypress versions since 3.6.0 that there have been a number of fixes for behaviour involving cookies so I upgraded to version 3.8.1 to see if that would fix this issue but I am still seeing the failure here.

image

Again, the only difference between these tests is the cookie itself, so I would expect both tests to pass.

Please provide an update on this issue.

@jennifer-shehane
Copy link
Member

@toddmkemp I have confirmed the behavior you're explaining. There are a couple of other differences in the cookies, mainly one is secure: true and httpOnly: true while the other is false on both of these attributes.

it('Passes', function () {
  cy.visit('https://en.wikipedia.org/')
  cy.setCookie('WMF-Last-Access-Global', 'value', { expiry: 10000000000 })
  cy.getCookie('WMF-Last-Access-Global').then((cookie) => {
    expect(cookie.httpOnly).to.be.false
    expect(cookie.secure).to.be.false
    expect(cookie.domain).to.eq('.wikipedia.org')
    expect(cookie.expiry).to.equal(10000000000)
  })
})

it('Fails', function () {
  cy.visit('https://en.wikipedia.org/')
  cy.setCookie('WMF-Last-Access', 'value', { expiry: 10000000000 })
  cy.getCookie('WMF-Last-Access').then((cookie) => {
    expect(cookie.httpOnly).to.be.true
    expect(cookie.secure).to.be.true
    expect(cookie.domain).to.eq('en.wikipedia.org')
    expect(cookie.expiry).to.equal(10000000000) // fails here <---
  })
})

Screen Shot 2020-01-02 at 12 53 11 PM

@cypress-bot cypress-bot bot added stage: needs investigating Someone from Cypress needs to look at this and removed stage: needs information Not enough info to reproduce the issue labels Jan 2, 2020
@ghost
Copy link
Author

ghost commented Jan 2, 2020

Hello again @jennifer-shehane . Thanks for investigating; glad to hear you were able to reproduce the problem. I hope that we will see this issue fixed in the near future! :)

@jennifer-shehane
Copy link
Member

This is still an issue in 9.5.3

@cypress-bot cypress-bot bot added stage: backlog and removed stage: needs investigating Someone from Cypress needs to look at this labels Apr 28, 2022
@flotwig flotwig removed their assignment Sep 1, 2022
@emilyrohrbough
Copy link
Member

related to: #20588

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 17, 2023
@slieschke
Copy link

The setCookie() expiry is still broken on the latest version of Cypress (v12.12.0 as of writing):

it('Fails', function () {
  cy.visit('https://en.wikipedia.org/')
  cy.setCookie('WMF-Last-Access', 'value', { expiry: 10000000000 })
  cy.getCookie('WMF-Last-Access').then((cookie) => {
    expect(cookie.httpOnly).to.be.true
    expect(cookie.secure).to.be.true
    expect(cookie.domain).to.eq('en.wikipedia.org')
    expect(cookie.expiry).to.equal(10000000000)
  })
})

CleanShot 2023-05-23 at 12 20 37

@cypress-app-bot cypress-app-bot removed the stale no activity on this issue for a long period label May 24, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Nov 21, 2023
@cypress-app-bot cypress-app-bot removed the stale no activity on this issue for a long period label Nov 29, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 27, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2024
@slieschke
Copy link

This is still failing with the latest version of Cypress (v13.15.1 as of writing).

it('Fails', function () {
  cy.log(`Cypress version: ${Cypress.version}`)
  cy.visit('https://en.wikipedia.org/')
  cy.setCookie('WMF-Last-Access', 'value', { expiry: 10000000000 })
  cy.getCookie('WMF-Last-Access').then((cookie) => {
    expect(cookie.httpOnly).to.be.true
    expect(cookie.secure).to.be.true
    expect(cookie.domain).to.eq('en.wikipedia.org')
    expect(cookie.expiry).to.equal(10000000000)
  })
})

CleanShot 2024-10-31 at 23 30 23@2x

@jennifer-shehane jennifer-shehane added prevent-stale mark an issue so it is ignored by stale[bot] and removed stale no activity on this issue for a long period labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prevent-stale mark an issue so it is ignored by stale[bot] topic: cookies 🍪 type: bug
Projects
None yet
Development

No branches or pull requests

5 participants