From 137fa89d2a6e2b57f2bab4b4325b0457806fc0f5 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 31 Mar 2021 04:40:42 -0400 Subject: [PATCH] tests: Always set cookie path to / (to match non-test behavior) --- src/tests/frontend/helper.js | 9 ++------- src/tests/frontend/specs/helper.js | 8 +------- src/tests/frontend/specs/language.js | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/tests/frontend/helper.js b/src/tests/frontend/helper.js index 74275110..2a406a4f 100644 --- a/src/tests/frontend/helper.js +++ b/src/tests/frontend/helper.js @@ -59,19 +59,14 @@ const helper = {}; // Can only happen when the iframe exists, so we're doing it separately from other cookies helper.clearPadPrefCookie = () => { - helper.padChrome$.document.cookie = 'prefsHttp=;expires=Thu, 01 Jan 1970 00:00:00 GMT'; + helper.padChrome$.document.cookie = 'prefsHttp=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; }; // Overwrite all prefs in pad cookie. Assumes http, not https. - // - // `helper.padChrome$.document.cookie` (the iframe) and `window.document.cookie` - // seem to have independent cookies, UNLESS we put path=/ here (which we don't). - // I don't fully understand it, but this function seems to properly simulate - // padCookie.setPref in the client code helper.setPadPrefCookie = (prefs) => { const val = encodeURIComponent(JSON.stringify(prefs)); helper.padChrome$.document.cookie = - `prefsHttp=${val};expires=Thu, 01 Jan 3000 00:00:00 GMT`; + `prefsHttp=${val};expires=Thu, 01 Jan 3000 00:00:00 GMT; path=/`; }; // Functionality for knowing what key event type is required for tests diff --git a/src/tests/frontend/specs/helper.js b/src/tests/frontend/specs/helper.js index 56c7257f..8bc55853 100644 --- a/src/tests/frontend/specs/helper.js +++ b/src/tests/frontend/specs/helper.js @@ -76,14 +76,9 @@ describe('the test helper', function () { // Now that we have a chrome, we can set a pad cookie // so we can confirm it gets wiped as well - chrome$.document.cookie = 'prefsHtml=baz;expires=Thu, 01 Jan 3030 00:00:00 GMT'; + chrome$.document.cookie = 'prefsHtml=baz;expires=Thu, 01 Jan 3030 00:00:00 GMT; path=/'; expect(chrome$.document.cookie).to.contain('prefsHtml=baz'); - // Cookies are weird. Because it's attached to chrome$ (as helper.setPadCookies does) - // AND we didn't put path=/, we shouldn't expect it to be visible on - // window.document.cookie. Let's just be sure. - expect(window.document.cookie).to.not.contain('prefsHtml=baz'); - // give it a second to save the username on the server side await new Promise((resolve) => setTimeout(resolve, 1000)); @@ -96,7 +91,6 @@ describe('the test helper', function () { expect(window.document.cookie).to.not.contain('token=foo'); expect(window.document.cookie).to.not.contain('language=bar'); expect(chrome$.document.cookie).to.contain('prefsHtml=baz'); - expect(window.document.cookie).to.not.contain('prefsHtml=baz'); expect(window.document.cookie).to.not.be(firstCookie); diff --git a/src/tests/frontend/specs/language.js b/src/tests/frontend/specs/language.js index e5240aaa..afc1e240 100644 --- a/src/tests/frontend/specs/language.js +++ b/src/tests/frontend/specs/language.js @@ -1,7 +1,7 @@ 'use strict'; const deletecookie = (name) => { - document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:01 GMT;`; + document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/`; }; describe('Language select and change', function () {