Skip to content

Commit

Permalink
feat: make cookies have sameSite key by default
Browse files Browse the repository at this point in the history
BREAKING CHANGE: modifies the shape of Cookie objects
  • Loading branch information
flotwig committed Jun 23, 2020
1 parent 29ca809 commit a925c9f
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 42 deletions.
5 changes: 0 additions & 5 deletions cli/schema/cypress.schema.json
Expand Up @@ -224,11 +224,6 @@
"default": "bundled",
"description": "If set to 'system', Cypress will try to find a Node.js executable on your path to use when executing your plugins. Otherwise, Cypress will use the Node version bundled with Cypress."
},
"experimentalGetCookiesSameSite": {
"type": "boolean",
"default": false,
"description": "If `true`, Cypress will add `sameSite` values to the objects yielded from `cy.setCookie()`, `cy.getCookie()`, and `cy.getCookies()`. This will become the default behavior in Cypress 5.0."
},
"experimentalSourceRewriting": {
"type": "boolean",
"default": false,
Expand Down
6 changes: 0 additions & 6 deletions cli/types/cypress.d.ts
Expand Up @@ -2442,12 +2442,6 @@ declare namespace Cypress {
* @default { runMode: 1, openMode: null }
*/
firefoxGcInterval: Nullable<number | { runMode: Nullable<number>, openMode: Nullable<number> }>
/**
* If `true`, Cypress will add `sameSite` values to the objects yielded from `cy.setCookie()`,
* `cy.getCookie()`, and `cy.getCookies()`. This will become the default behavior in Cypress 5.0.
* @default false
*/
experimentalGetCookiesSameSite: boolean
/**
* Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement
* algorithm.
Expand Down
4 changes: 1 addition & 3 deletions packages/driver/cypress/integration/commands/cookies_spec.js
Expand Up @@ -474,9 +474,7 @@ describe('src/cy/commands/cookies', () => {
})
})

it('can set cookies with sameSite', {
experimentalGetCookiesSameSite: true,
}, () => {
it('can set cookies with sameSite', () => {
Cypress.automation.restore()
Cypress.utils.addTwentyYears.restore()

Expand Down
14 changes: 0 additions & 14 deletions packages/driver/src/cy/commands/cookies.js
Expand Up @@ -58,12 +58,6 @@ const normalizeSameSite = (sameSite) => {
}

module.exports = function (Commands, Cypress, cy, state, config) {
const maybeStripSameSiteProp = (cookie) => {
if (cookie && !Cypress.config('experimentalGetCookiesSameSite')) {
delete cookie.sameSite
}
}

const automateCookies = function (event, obj = {}, log, timeout) {
const automate = () => {
return Cypress.automation(event, mergeDefaults(obj))
Expand Down Expand Up @@ -183,8 +177,6 @@ module.exports = function (Commands, Cypress, cy, state, config) {

return automateCookies('get:cookie', { name }, options._log, options.timeout)
.then((resp) => {
maybeStripSameSiteProp(resp)

options.cookie = resp

return resp
Expand Down Expand Up @@ -222,10 +214,6 @@ module.exports = function (Commands, Cypress, cy, state, config) {

return automateCookies('get:cookies', _.pick(options, 'domain'), options._log, options.timeout)
.then((resp) => {
if (Array.isArray(resp)) {
resp.forEach(maybeStripSameSiteProp)
}

options.cookies = resp

return resp
Expand Down Expand Up @@ -299,8 +287,6 @@ module.exports = function (Commands, Cypress, cy, state, config) {

return automateCookies('set:cookie', cookie, options._log, options.timeout)
.then((resp) => {
maybeStripSameSiteProp(resp)

options.cookie = resp

return resp
Expand Down
9 changes: 4 additions & 5 deletions packages/server/__snapshots__/2_cookies_spec.js
Expand Up @@ -5,11 +5,10 @@ exports['e2e cookies with baseurl'] = `
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (cookies_spec_baseurl.coffee) │
│ Searched: cypress/integration/cookies_spec_baseurl.coffee │
│ Experiments: experimentalGetCookiesSameSite=true │
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (cookies_spec_baseurl.coffee) │
│ Searched: cypress/integration/cookies_spec_baseurl.coffee │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
Expand Down
3 changes: 0 additions & 3 deletions packages/server/lib/config.js
Expand Up @@ -105,7 +105,6 @@ browsers\
// each should start with "experimental" and be camel cased
// example: experimentalComponentTesting
const experimentalConfigKeys = toWords(`\
experimentalGetCookiesSameSite
experimentalSourceRewriting
experimentalComponentTesting
experimentalShadowDomSupport
Expand Down Expand Up @@ -174,7 +173,6 @@ const CONFIG_DEFAULTS = {
componentFolder: 'cypress/component',
// TODO: example for component testing with subkeys
// experimentalComponentTesting: { componentFolder: 'cypress/component' }
experimentalGetCookiesSameSite: false,
experimentalSourceRewriting: false,
experimentalShadowDomSupport: false,
experimentalFetchPolyfill: false,
Expand Down Expand Up @@ -222,7 +220,6 @@ const validationRules = {
// validation for component testing experiment
componentFolder: v.isStringOrFalse,
// experimental flag validation below
experimentalGetCookiesSameSite: v.isBoolean,
experimentalSourceRewriting: v.isBoolean,
experimentalShadowDomSupport: v.isBoolean,
experimentalFetchPolyfill: v.isBoolean,
Expand Down
2 changes: 0 additions & 2 deletions packages/server/lib/experiments.ts
Expand Up @@ -53,7 +53,6 @@ interface StringValues {
const _summaries: StringValues = {
experimentalComponentTesting: 'Framework-specific component testing, uses `componentFolder` to load component specs',
experimentalSourceRewriting: 'Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement algorithm.',
experimentalGetCookiesSameSite: 'Adds `sameSite` values to the objects yielded from `cy.setCookie()`, `cy.getCookie()`, and `cy.getCookies()`. This will become the default behavior in Cypress 5.0.',
experimentalFetchPolyfill: 'Polyfills `window.fetch` to enable Network spying and stubbing',
experimentalShadowDomSupport: 'Enables support for shadow DOM traversal, introduces the `shadow()` command and the `includeShadowDom` option to traversal commands.',
}
Expand All @@ -71,7 +70,6 @@ const _summaries: StringValues = {
const _names: StringValues = {
experimentalComponentTesting: 'Component Testing',
experimentalSourceRewriting: 'Improved source rewriting',
experimentalGetCookiesSameSite: 'Set `sameSite` property when retrieving cookies',
experimentalShadowDomSupport: 'Shadow DOM Support',
experimentalFetchPolyfill: 'Fetch polyfill',
}
Expand Down
2 changes: 0 additions & 2 deletions packages/server/test/e2e/2_cookies_spec.js
Expand Up @@ -194,7 +194,6 @@ describe('e2e cookies', () => {
// we can remove this extra test case
e2e.it('with forced SameSite strictness', {
config: {
experimentalGetCookiesSameSite: true,
baseUrl,
env: {
baseUrl,
Expand Down Expand Up @@ -248,7 +247,6 @@ describe('e2e cookies', () => {
) => {
e2e.it(`passes with baseurl: ${baseUrl}`, {
config: {
experimentalGetCookiesSameSite: true,
baseUrl,
env: {
baseUrl,
Expand Down
2 changes: 0 additions & 2 deletions packages/server/test/unit/config_spec.js
Expand Up @@ -1108,7 +1108,6 @@ describe('lib/config', () => {
requestTimeout: { value: 5000, from: 'default' },
responseTimeout: { value: 30000, from: 'default' },
execTimeout: { value: 60000, from: 'default' },
experimentalGetCookiesSameSite: { value: false, from: 'default' },
experimentalSourceRewriting: { value: false, from: 'default' },
taskTimeout: { value: 60000, from: 'default' },
numTestsKeptInMemory: { value: 50, from: 'default' },
Expand Down Expand Up @@ -1185,7 +1184,6 @@ describe('lib/config', () => {
requestTimeout: { value: 5000, from: 'default' },
responseTimeout: { value: 30000, from: 'default' },
execTimeout: { value: 60000, from: 'default' },
experimentalGetCookiesSameSite: { value: false, from: 'default' },
experimentalSourceRewriting: { value: false, from: 'default' },
taskTimeout: { value: 60000, from: 'default' },
numTestsKeptInMemory: { value: 50, from: 'default' },
Expand Down

0 comments on commit a925c9f

Please sign in to comment.