-
Notifications
You must be signed in to change notification settings - Fork 607
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
[ | ||
{ | ||
"domain": ".www.yourdomain.com", | ||
"path": "/", | ||
"name": "yourCookieName", | ||
"value": "yourCookieValue", | ||
|
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}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
}); | ||
|
||
|
There was a problem hiding this comment.
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.