Skip to content

Commit

Permalink
fix: the cookie_behavior tests by syncing cookies immediately if … (#…
Browse files Browse the repository at this point in the history
…25855)

* fix: fix the cookie_behavior tests by syncing cookies immediately if the application is already stable

* chore: add changelog entry

* [run ci]

* chore: address comments from code review
  • Loading branch information
AtofStryker authored Feb 20, 2023
1 parent 59c1175 commit 46b35d3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 78 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
92 changes: 20 additions & 72 deletions packages/driver/cypress/e2e/e2e/origin/cookie_behavior.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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'))
Expand Down
20 changes: 14 additions & 6 deletions packages/driver/src/cross-origin/events/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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)
}
})
}

4 comments on commit 46b35d3

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46b35d3 Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.7.0/linux-arm64/develop-46b35d3a0d4fd4d8af56a2907a181e56d703bf12/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46b35d3 Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.7.0/linux-x64/develop-46b35d3a0d4fd4d8af56a2907a181e56d703bf12/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46b35d3 Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.7.0/darwin-x64/develop-46b35d3a0d4fd4d8af56a2907a181e56d703bf12/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46b35d3 Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.7.0/win32-x64/develop-46b35d3a0d4fd4d8af56a2907a181e56d703bf12/cypress.tgz

Please sign in to comment.