Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cookie domain as it could be munged from scenario url #1258

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion capture/engine_scripts/cookies.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"domain": ".www.yourdomain.com",
Copy link
Owner

Choose a reason for hiding this comment

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

Only problem I have here is that this property will be there when using popular plugins to create this JSON file. So, I prefer to leave this as I imagine many users will include this.

"path": "/",
"name": "yourCookieName",
"value": "yourCookieValue",
Expand Down
12 changes: 8 additions & 4 deletions capture/engine_scripts/puppet/loadCookies.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
const fs = require('fs');

module.exports = async (page, scenario) => {
let cookies = [];
const cookies = [];
const cookiePath = scenario.cookiePath;

// READ COOKIES FROM FILE IF EXISTS
if (fs.existsSync(cookiePath)) {
cookies = JSON.parse(fs.readFileSync(cookiePath));
}

// MUNGE COOKIE DOMAIN
// Inject cookie domain, url, secure from scenario url.
const url = new URL(scenario.url);
cookies = cookies.map(cookie => {
cookie.url = 'https://' + cookie.domain;
delete cookie.domain;
cookie.url = `${url.protocol}//${url.hostname}`;
Copy link
Owner

Choose a reason for hiding this comment

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

I prefer this way more to what is currently here. I am a little conflicted about using the "magic" hostname since this could differ from the one exported in the cookie-- but I think this is your whole point. So, I am supportive of this because it will probably work more often than not.

cookie.domain = url.hostname;
if(url.protocol === 'https:') {
cookie.secure = true;
}
return cookie;
});

Expand Down