cypress: Cookies are broken with cy.origin

Current behavior

I’m trying to test a WordPress plugin. The plugin does different things depending on if the domain is recognized or not.

For this reason I’m running the exact same test (except the last assertion) twice, once normally, and once wrapped in cy.origin. experimentalSessionAndOrigin is set to true

The test without the cy.origin works perfectly.

The one wrapped in cy.origin runs twice (test retry):

  • On the first iteration, it is unable to log in to /wp-admin. The browser freezes for a while, then it returns to the login screen without any errors
  • On the second try, it manages to log in, and displays the WP dashboard, but the very next page navigation kicks us back to the login screen image

This is fairly repeatable

Desired behavior

No response

Test code to reproduce

describe('Manual plugin activation', () => {
  describe('w/ random domain', () => {
    beforeEach(() => {
      // This command brings up the appropriate docker containers, and sets WP up with a random domain,
      // which it adds to the hosts file so the browser can access it.
      // It then executes Cypress.config('baseUrl', baseUrl); to prepare for the tests
      // This seem to be working correctly, as the page does show up correctly in response to cy.visit()
      cy.resetTestingEnv({ randomBaseUrl: true })
    })

    it('should display signup CTA when autoconfig fails', () => {
      cy.origin(Cypress.config('baseUrl'), {}, () => {
        // cy.adminAuth()
        cy.visit('/wp-admin')

        // eslint-disable-next-line cypress/no-unnecessary-waiting
        cy.wait(500) // The login page clears/resets the input from js whan loaded, so need to wait

        cy.contains('Username').type(Cypress.env('CYPRESS_WP_ADMIN_USER'))
        cy.contains('Password').type(Cypress.env('CYPRESS_WP_ADMIN_PASS'))
        cy.contains('Log In').click()

        cy.contains('Dashboard').should('exist')

        // cy.activatePluginGui();
        cy.visit('/wp-admin/plugins.php')

        cy.get('#activate-plugin1').click()
        cy.contains('Thank you for installing plugin1 plugin!').should(
          'exist',
        )

        // cy.visitPluginSettings();
        cy.visit('/wp-admin/admin.php?page=plugin1')
        cy.contains('Create your account')
        .should('have.attr', 'href')
        .and(
          'include',
          'https://www.plugin1-staging.com/signup-wordpress',
        )
      })
    })
  })

  describe('w/ standard domain', () => {
    beforeEach(() => {
      // In this case it does the exact same as above with the exception that it sets a pre-defined domain
      // so it is recognized by the plugin. This domain does match the one given in cypress.config.js -> e2e.baseUrl
      cy.resetTestingEnv()
    })

    it('should display MS admin link when autoconfig succeeds', () => {
      // cy.adminAuth();
      cy.visit('/wp-admin')

      // eslint-disable-next-line cypress/no-unnecessary-waiting
      cy.wait(500) // The login page clears/resets the input from js whan loaded, so need to wait

      cy.contains('Username').type(Cypress.env('CYPRESS_WP_ADMIN_USER'))
      cy.contains('Password').type(Cypress.env('CYPRESS_WP_ADMIN_PASS'))
      cy.contains('Log In').click()

      cy.contains('Dashboard').should('exist')

      // cy.activatePluginGui();
      cy.visit('/wp-admin/plugins.php')

      cy.get('#activate-plugin1').click()
      cy.contains('Thank you for installing plugin1\'s plugin!').should(
        'exist',
      )

      // cy.visitPluginSettings();
      cy.visit('/wp-admin/admin.php?page=plugin1')
      cy.contains('Go to your plugin1 backend').should(
        'have.attr',
        'href',
        'https://admin.plugin1-staging.com/sites/145',
      )
    })
  })
})

Cypress Version (that I tested with and is broken)

10.3, 10.3.1, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.11, 12.2, 12.5.1, 12.17.0, 13.2.0, 13.6.2, 13.7.2

Other

I suspect that changing Cypress.config(‘baseUrl’); might be a contributing factor in this issue

Not sure how to create a demo test setup of this complexity (multiple domains, etc.) so please let me know what other information or debug output to provide in order to track down the issue

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 3
  • Comments: 44 (16 by maintainers)

Most upvoted comments

@kgartland-rstudio Not to my knowledge

@AtofStryker The reproduction repo has been updated to 13.6.2, the issue seems to persist.

I have the exact same issue on a website. When entering the website, it creates a cookie PHPSESSID, which is not preserved while the login form is submitted and therefor the CSRF token fails.

@AtofStryker

Sent, please look for an email with the title VM image - bug reproduction for #23165

Hi @AtofStryker!

I have checked against the latest Cypress (10.8), unfortunately, it’s still broken. I updated the description above and the reproduction repository

I have updated the reproduction repo to Cypress 10.7, so you can work against the latest version. The problem is also present in 10.7

Hi @denke8! I used a Linux VM to run your repro and I was able to reproduce the behavior you’re seeing 🎉 Thank you for putting together a simple repro for us with clear steps in the README, it helps loads ❤

The issue unfortunately is still present, updated the reproduction to the latest version, 13.2.0

@denke8 I have the OVA file on hand but haven’t had a chance to install the image and investigate. I’m hoping to have time on next rotation to dig in a bit more.

@denke8 Thank you for being patience with us. Sorry I haven’t been able to take a look. But I do have some bandwidth available in the coming days so I might be able to take a look and since if I can run again on my ubuntu machine. You deserve an answer and I’m going to work through getting you one.

@denke8 I’m sorry to hear that. Hopefully I can take a look at this issue again soon to hopefully determine a root cause.

@AtofStryker Sounds great, let me know if I can help in any other way … video, debug output, etc.