From 765123863feeb8ab23f51a793996ecb681ef0676 Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Mon, 26 Aug 2024 10:31:27 -0400 Subject: [PATCH 1/2] feat: support partitioned cookies --- .../src/utils/serialize-cookie.js | 3 ++ .../tests/unit/services/cookies-test.js | 11 ++++ pnpm-lock.yaml | 54 ++----------------- 3 files changed, 18 insertions(+), 50 deletions(-) diff --git a/packages/ember-cookies/src/utils/serialize-cookie.js b/packages/ember-cookies/src/utils/serialize-cookie.js index af1a8a11..c1f728f6 100644 --- a/packages/ember-cookies/src/utils/serialize-cookie.js +++ b/packages/ember-cookies/src/utils/serialize-cookie.js @@ -24,6 +24,9 @@ export const serializeCookie = (name, value, options = {}) => { if (!isEmpty(options.sameSite)) { cookie = `${cookie}; SameSite=${options.sameSite}`; } + if (options.partitioned) { + cookie = `${cookie}; Partitioned`; + } return cookie; }; diff --git a/packages/test-app/tests/unit/services/cookies-test.js b/packages/test-app/tests/unit/services/cookies-test.js index 3c06276e..4e7b5dcf 100644 --- a/packages/test-app/tests/unit/services/cookies-test.js +++ b/packages/test-app/tests/unit/services/cookies-test.js @@ -289,6 +289,17 @@ module('CookiesService', function (hooks) { this.cookies.write(COOKIE_NAME, 'test', { secure: true }); }); + test('sets the partitioned flag', function (assert) { + assert.expect(1); + defineProperty(this.fakeDocument, 'cookie', { + set(value) { + assert.ok(value.includes('; Partitioned')); + }, + }); + + this.cookies.write(COOKIE_NAME, 'test', { partitioned: true }); + }); + test('sets the path', function (assert) { assert.expect(1); defineProperty(this.fakeDocument, 'cookie', { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 88f074fb..8c681d63 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -139,8 +139,8 @@ importers: specifier: 4.0.2 version: 4.0.2 ember-cookies: - specifier: 1.1.2 - version: 1.1.2 + specifier: link:../ember-cookies + version: link:../ember-cookies ember-disable-prototype-extensions: specifier: 1.1.3 version: 1.1.3 @@ -3056,10 +3056,6 @@ packages: resolution: {integrity: sha512-BtkjulweiXo9c3yVWrtexw2dTmBrvavD/xixNC6TKOBdrixUwU+6nuOO9dufDWsMxoid7MvtmDpzc9+mE8PdaA==} engines: {node: 10.* || >= 12.*} - ember-cookies@1.1.2: - resolution: {integrity: sha512-6GaN0eEDZT9SEUSZBxWzZMlvxjcGKXFTJNjv30LVXTTOxozE5IBmIxiDAEq0udi0UpWUGHLYQBgnANn4jdll7w==} - engines: {node: '>= 16.*'} - ember-disable-prototype-extensions@1.1.3: resolution: {integrity: sha512-SB9NcZ27OtoUk+gfalsc3QU17+54OoqR668qHcuvHByk4KAhGxCKlkm9EBlKJcGr7yceOOAJqohTcCEBqfRw9g==} engines: {node: '>= 0.10.0'} @@ -8439,26 +8435,6 @@ snapshots: dependencies: '@types/node': 22.5.5 - '@types/ember@4.0.11': - dependencies: - '@types/ember__application': 4.0.11(@babel/core@7.25.8) - '@types/ember__array': 4.0.10(@babel/core@7.25.8) - '@types/ember__component': 4.0.22 - '@types/ember__controller': 4.0.12(@babel/core@7.25.8) - '@types/ember__debug': 4.0.8(@babel/core@7.25.8) - '@types/ember__engine': 4.0.11(@babel/core@7.25.8) - '@types/ember__error': 4.0.6 - '@types/ember__object': 4.0.12(@babel/core@7.25.8) - '@types/ember__polyfills': 4.0.6 - '@types/ember__routing': 4.0.22 - '@types/ember__runloop': 4.0.10 - '@types/ember__service': 4.0.9(@babel/core@7.25.8) - '@types/ember__string': 3.0.15 - '@types/ember__template': 4.0.7 - '@types/ember__test': 4.0.6(@babel/core@7.25.8) - '@types/ember__utils': 4.0.7(@babel/core@7.25.8) - '@types/rsvp': 4.0.9 - '@types/ember@4.0.11(@babel/core@7.25.8)': dependencies: '@types/ember__application': 4.0.11(@babel/core@7.25.8) @@ -8485,11 +8461,11 @@ snapshots: '@types/ember__application@4.0.11(@babel/core@7.25.8)': dependencies: '@glimmer/component': 1.1.2(@babel/core@7.25.8) - '@types/ember': 4.0.11 + '@types/ember': 4.0.11(@babel/core@7.25.8) '@types/ember__engine': 4.0.11(@babel/core@7.25.8) '@types/ember__object': 4.0.12(@babel/core@7.25.8) '@types/ember__owner': 4.0.9 - '@types/ember__routing': 4.0.22 + '@types/ember__routing': 4.0.22(@babel/core@7.25.8) transitivePeerDependencies: - '@babel/core' - supports-color @@ -8502,11 +8478,6 @@ snapshots: - '@babel/core' - supports-color - '@types/ember__component@4.0.22': - dependencies: - '@types/ember': 4.0.11 - '@types/ember__object': 4.0.12(@babel/core@7.25.8) - '@types/ember__component@4.0.22(@babel/core@7.25.8)': dependencies: '@types/ember': 4.0.11(@babel/core@7.25.8) @@ -8552,13 +8523,6 @@ snapshots: '@types/ember__polyfills@4.0.6': {} - '@types/ember__routing@4.0.22': - dependencies: - '@types/ember': 4.0.11 - '@types/ember__controller': 4.0.12(@babel/core@7.25.8) - '@types/ember__object': 4.0.12(@babel/core@7.25.8) - '@types/ember__service': 4.0.9(@babel/core@7.25.8) - '@types/ember__routing@4.0.22(@babel/core@7.25.8)': dependencies: '@types/ember': 4.0.11(@babel/core@7.25.8) @@ -8569,10 +8533,6 @@ snapshots: - '@babel/core' - supports-color - '@types/ember__runloop@4.0.10': - dependencies: - '@types/ember': 4.0.11 - '@types/ember__runloop@4.0.10(@babel/core@7.25.8)': dependencies: '@types/ember': 4.0.11(@babel/core@7.25.8) @@ -10665,12 +10625,6 @@ snapshots: - '@babel/core' - supports-color - ember-cookies@1.1.2: - dependencies: - '@embroider/addon-shim': 1.8.9 - transitivePeerDependencies: - - supports-color - ember-disable-prototype-extensions@1.1.3: {} ember-eslint-parser@0.5.2(@babel/core@7.25.8)(eslint@9.12.0): From ea8d1d420b00d623d59d2bb7c4622bafa8f503ba Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Thu, 31 Oct 2024 10:45:45 -0400 Subject: [PATCH 2/2] local testing fails without this change --- package.json | 1 + packages/test-app/package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d19f0902..ee5f1d4d 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "start:addon": "pnpm --filter ember-cookies start", "start:test-app": "pnpm --filter test-app start", "test": "pnpm run test:test-app ember-default", + "test:all": "pnpm --filter test-app test:all", "test:test-app": "pnpm --filter test-app test:one", "test:watch": "concurrently \"pnpm test:watch:test-app\" \"pnpm test:watch:addon\"", "test:watch:addon": "pnpm --filter ember-cookies start", diff --git a/packages/test-app/package.json b/packages/test-app/package.json index 00a8a3f5..2d138d6d 100644 --- a/packages/test-app/package.json +++ b/packages/test-app/package.json @@ -44,7 +44,7 @@ "ember-cli-inject-live-reload": "2.1.0", "ember-cli-sri": "2.1.1", "ember-cli-terser": "4.0.2", - "ember-cookies": "1.1.2", + "ember-cookies": "link:../ember-cookies", "ember-disable-prototype-extensions": "1.1.3", "ember-load-initializers": "2.1.2", "ember-maybe-import-regenerator": "1.0.0",