diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 6b42b6c48165..8c9b11482dac 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -10,6 +10,7 @@ _Released 03/1/2023 (PENDING)_ **Bugfixes:** - Fixed an issue where cookies were being duplicated with the same hostname, but a prepended dot. Fixed an issue where cookies may not be expiring correctly. Fixes [#25174](https://github.com/cypress-io/cypress/issues/25174), [#25205](https://github.com/cypress-io/cypress/issues/25205) and [#25495](https://github.com/cypress-io/cypress/issues/25495). +- Fixed an issue where cookies weren't being synced when the application was stable. Fixed in [#25855](https://github.com/cypress-io/cypress/pull/25855). Fixes [#25835](https://github.com/cypress-io/cypress/issues/25835). - Added missing TypeScript type definitions for the [`cy.reload()`](https://docs.cypress.io/api/commands/reload) command. Addressed in [#25779](https://github.com/cypress-io/cypress/pull/25779). - Ensure Angular components are mounted inside the correct element. Fixes [#24385](https://github.com/cypress-io/cypress/issues/24385) - Fix a bug where files outside the project root in a monorepo are not correctly served when using Vite. Addressed in [#25801](https://github.com/cypress-io/cypress/pull/25801) diff --git a/packages/driver/cypress/e2e/e2e/origin/cookie_behavior.cy.ts b/packages/driver/cypress/e2e/e2e/origin/cookie_behavior.cy.ts index 6e0965aada61..626e4f8a3a56 100644 --- a/packages/driver/cypress/e2e/e2e/origin/cookie_behavior.cy.ts +++ b/packages/driver/cypress/e2e/e2e/origin/cookie_behavior.cy.ts @@ -251,17 +251,7 @@ describe('Cookie Behavior', { browser: '!webkit' }, () => { // though request is cross origin, site should have access directly to cookie because it is same site // assert cookie value is actually set in the browser - // current expected assertion. NOTE: This SHOULD be consistent - if (Cypress.isBrowser('firefox')) { - // firefox actually sets the cookie correctly - cy.getCookie('foo1').its('value').should('equal', 'bar1') - } else { - cy.getCookie('foo1').should('equal', null) - } - - // FIXME: Ideally, browser should have access to this cookie. Should be fixed in https://github.com/cypress-io/cypress/pull/23643. - // future expected assertion - // cy.getCookie('foo1').its('value').should('equal', 'bar1') + cy.getCookie('foo1').its('value').should('equal', 'bar1') cy.window().then((win) => { // but send the cookies in the request @@ -298,17 +288,7 @@ describe('Cookie Behavior', { browser: '!webkit' }, () => { // though request is cross origin, site should have access directly to cookie because it is same site // assert cookie value is actually set in the browser - // current expected assertion. NOTE: This SHOULD be consistent - if (Cypress.isBrowser('firefox')) { - // firefox actually sets the cookie correctly - cy.getCookie('foo1').its('value').should('equal', 'bar1') - } else { - cy.getCookie('foo1').should('equal', null) - } - - // FIXME: Ideally, browser should have access to this cookie. Should be fixed in https://github.com/cypress-io/cypress/pull/23643. - // future expected assertion - // cy.getCookie('foo1').its('value').should('equal', 'bar1') + cy.getCookie('foo1').its('value').should('equal', 'bar1') cy.window().then((win) => { // but send the cookies in the request @@ -376,17 +356,7 @@ describe('Cookie Behavior', { browser: '!webkit' }, () => { }) // assert cookie value is actually set in the browser - // current expected assertion. - if (Cypress.isBrowser('firefox')) { - // firefox actually sets the cookie correctly - cy.getCookie('foo1').its('value').should('equal', 'bar1') - } else { - cy.getCookie('foo1').should('equal', null) - } - - // FIXME: Ideally, browser should have access to this cookie. Should be fixed in https://github.com/cypress-io/cypress/pull/23643. - // future expected assertion - // cy.getCookie('foo1').its('value').should('equal', 'bar1') + cy.getCookie('foo1').its('value').should('equal', 'bar1') cy.window().then((win) => { return cy.wrap(window.makeRequest(win, `${scheme}://app.foobar.com:${crossOriginPort}/test-request-credentials`, 'fetch', 'include')) @@ -418,17 +388,7 @@ describe('Cookie Behavior', { browser: '!webkit' }, () => { }) // assert cookie value is actually set in the browser - // current expected assertion. NOTE: This SHOULD be consistent - if (Cypress.isBrowser('firefox')) { - // firefox actually sets the cookie correctly - cy.getCookie('foo1').its('value').should('equal', 'bar1') - } else { - cy.getCookie('foo1').should('equal', null) - } - - // FIXME: Ideally, browser should have access to this cookie. Should be fixed in https://github.com/cypress-io/cypress/pull/23643. - // future expected assertion - // cy.getCookie('foo1').its('value').should('equal', 'bar1') + cy.getCookie('foo1').its('value').should('equal', 'bar1') cy.window().then((win) => { return cy.wrap(window.makeRequest(win, `${scheme}://app.foobar.com:${crossOriginPort}/test-request-credentials`, 'fetch')) @@ -529,14 +489,11 @@ describe('Cookie Behavior', { browser: '!webkit' }, () => { return cy.wrap(window.makeRequest(win, `${scheme}://www.barbaz.com:${sameOriginPort}/set-cookie-credentials?cookie=bar1=baz1; Domain=barbaz.com; SameSite=None; Secure`, 'xmlHttpRequest', true)) }) - // assert cookie value is actually set in the browser if (scheme === 'https') { - // FIXME: cy.getCookie does not believe this cookie exists. Should be fixed in https://github.com/cypress-io/cypress/pull/23643. - cy.getCookie('bar1').should('equal', null) - // can only set third-party SameSite=None with Secure attribute, which is only possibly over https - - //expected future assertion - // cy.getCookie('bar1').its('value').should('equal', 'baz1') + // assert cookie value is actually set in the browser, even if in a different domain + cy.getCookie('bar1', { + domain: 'barbaz.com', + }).its('value').should('equal', 'baz1') } else { cy.getCookie('bar1').should('equal', null) } @@ -572,12 +529,10 @@ describe('Cookie Behavior', { browser: '!webkit' }, () => { return cy.wrap(window.makeRequest(win, `${scheme}://www.barbaz.com:${sameOriginPort}/set-cookie-credentials?cookie=bar1=baz1; Domain=barbaz.com; SameSite=None; Secure`, 'xmlHttpRequest', true)) }) - // FIXME: cy.getCookie does not believe this cookie exists. Should be fixed in https://github.com/cypress-io/cypress/pull/23643. - cy.getCookie('bar1').should('equal', null) - // can only set third-party SameSite=None with Secure attribute, which is only possibly over https - - //expected future assertion - // cy.getCookie('bar1').its('value').should('equal', 'baz1') + // assert cookie value is actually set in the browser, even if in a different domain + cy.getCookie('bar1', { + domain: 'barbaz.com', + }).its('value').should('equal', 'baz1') cy.window().then((win) => { return cy.wrap(window.makeRequest(win, `${scheme}://www.barbaz.com:${sameOriginPort}/test-request-credentials`, 'xmlHttpRequest', true)) @@ -649,14 +604,11 @@ describe('Cookie Behavior', { browser: '!webkit' }, () => { return cy.wrap(window.makeRequest(win, `${scheme}://www.barbaz.com:${sameOriginPort}/set-cookie-credentials?cookie=bar1=baz1; Domain=barbaz.com; SameSite=None; Secure`, 'fetch', 'include')) }) - // assert cookie value is actually set in the browser if (scheme === 'https') { - // FIXME: cy.getCookie does not believe this cookie exists. Should be fixed in https://github.com/cypress-io/cypress/pull/23643. - cy.getCookie('bar1').should('equal', null) - // can only set third-party SameSite=None with Secure attribute, which is only possibly over https - - //expected future assertion - // cy.getCookie('bar1').its('value').should('equal', 'baz1') + // assert cookie value is actually set in the browser, even if in a different domain + cy.getCookie('bar1', { + domain: 'barbaz.com', + }).its('value').should('equal', 'baz1') } else { cy.getCookie('bar1').should('equal', null) } @@ -695,14 +647,10 @@ describe('Cookie Behavior', { browser: '!webkit' }, () => { return cy.wrap(window.makeRequest(win, `${scheme}://www.barbaz.com:${sameOriginPort}/set-cookie-credentials?cookie=bar1=baz1; Domain=barbaz.com; SameSite=None; Secure`, 'fetch', 'include')) }) - // assert cookie value is actually set in the browser - - // FIXME: cy.getCookie does not believe this cookie exists, though it is set in the browser. Should be fixed in https://github.com/cypress-io/cypress/pull/23643. - cy.getCookie('bar1').should('equal', null) - // can only set third-party SameSite=None with Secure attribute, which is only possibly over https - - //expected future assertion - // cy.getCookie('bar1').its('value').should('equal', 'baz1') + // assert cookie value is actually set in the browser, even if in a different domain + cy.getCookie('bar1', { + domain: 'barbaz.com', + }).its('value').should('equal', 'baz1') cy.window().then((win) => { return cy.wrap(window.makeRequest(win, `${scheme}://www.barbaz.com:${sameOriginPort}/test-request-credentials`, 'fetch', 'include')) diff --git a/packages/driver/src/cross-origin/events/cookies.ts b/packages/driver/src/cross-origin/events/cookies.ts index a4198143dd67..655d6d28c765 100644 --- a/packages/driver/src/cross-origin/events/cookies.ts +++ b/packages/driver/src/cross-origin/events/cookies.ts @@ -22,11 +22,7 @@ export const handleCrossOriginCookies = (Cypress: ICypress) => { waitingToSend = true - // this event allows running a handler before stability is released. - // this prevents subsequent commands from running until the cookies - // are set via automation - // @ts-ignore - Cypress.once('before:stability:release', () => { + const syncCookiesViaAutomation = () => { const cookies = cookiesToSend cookiesToSend = [] @@ -37,6 +33,18 @@ export const handleCrossOriginCookies = (Cypress: ICypress) => { .catch(() => { // errors here can be ignored as they're not user-actionable }) - }) + } + + // if the application is already stable, sync the cookies to the automation client immediately + if (cy.state('isStable')) { + syncCookiesViaAutomation() + } else { + // otherwise, wait until stability is achieved + // this event allows running a handler before stability is released. + // this prevents subsequent commands from running until the cookies + // are set via automation + // @ts-ignore + Cypress.once('before:stability:release', syncCookiesViaAutomation) + } }) }