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

Broken method setCookie or document.cookie #5198

Closed
ghost opened this issue Sep 25, 2019 · 4 comments
Closed

Broken method setCookie or document.cookie #5198

ghost opened this issue Sep 25, 2019 · 4 comments

Comments

@ghost
Copy link

ghost commented Sep 25, 2019

Current behavior:

Can't set a cookie for a browser to recognize as the login user. The cookie should be a string with the format:

a41c0f40492c7a0ce155e4fde1d800a9; Path=/XXX-crm-api; HttpOnly

I tried both methods - setCookie and document.cookie. I do not see the cookie in browser memory if I set specified path other than "/'. If the path is not specified the cookie does not work properly.

image

image

Here I left the path empty, but as you can see Cypress ads "." before the domain.

Desired behavior:

Cookie is set properly and app redirects to the main site as a logged user. Test passes.

Steps to reproduce: (app code and test code)

login_using_cookie.js:

describe('login using token', () => {
        it('should successfully log into our app', () => {
          Cypress.Cookies.debug(true)
          cy.loginViaCookie()
            .then(() => {
              cy.visit('/')
              cy.get('[class="icon-people"]').click()
            })
        });
}

commands.js:

Cypress.Commands.add('loginViaCookie', () => {
    Cypress.log({
        name: 'loginViaCookie'
    })

    return cy.request({
        method: 'POST',
        url: 'http://lab2.YYY:8080/XXX-crm-api/login',
        headers: {
            "Content-Type": "application/json"
        },
        body: {
            username: "a@admin.com",
            password: "Cypress111"
        },
    })
        .then((resp) => {
             //use document.cookie or setCookie
            // document.cookie = `authtoken=${resp.body.accessToken};path=/XXX-crm-ap;httpOnly: true`
            cy.setCookie('authtoken', resp.body.accessToken, {Path='/XXX-crm-api', httpOnly: true})
        })
})

Versions

Cypress v3.4.1
Chrome v76
Electron v61

@must-git-good
Copy link

must-git-good commented Sep 25, 2019

I'll just +1 that setting cookies seems to have changed (broken) without us changing any code or Cypress versions.

In my case the error is 'TypeError: Cannot read property 'replace' of undefined [even though we are successfully getting a token that should be set as a cookie.

Programmatic login DOES seem to work on Electron, but is broken in Chrome, and happens across our local systems but not on our CI (which is Chrome-pinned).

So it feels like something changed in how Chrome assigns cookies?

Edit: The above report looks like it's older Chrome, so maybe this isn't the issue, but I still think it's likely...the latest Chrome release seems to have done a bunch of work to how cookies are handled.

Anyone else have the issue? More information for the team to use to reconcile?

@flotwig
Copy link
Contributor

flotwig commented Sep 25, 2019

Related: #5142 (changes between chrome 76 => 77)

@must-git-good
Copy link

must-git-good commented Sep 25, 2019

Thanks for the link, flotwig. I'll dig into that ticket and see if it resolves our issues.

EDIT: For anyone else just now seeing this issue...the above link on cookie domain formatting got us up and running again.

@jennifer-shehane
Copy link
Member

Since this issue hasn't had activity in a while, we'll close the issue until we can confirm this is still happening. Please comment if there is new information to provide concerning the original issue and we'd be happy to reopen.

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

No branches or pull requests

3 participants