-
Notifications
You must be signed in to change notification settings - Fork 27
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
Support modifying cookies #1384
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
injected/integration-test/test-pages/webcompat/config/modify-cookies.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"unprotectedTemporary": [], | ||
"features": { | ||
"webCompat": { | ||
"exceptions": [], | ||
"state": "enabled", | ||
"settings": { | ||
"modifyCookies": { | ||
"state": "enabled", | ||
"changes": [] | ||
}, | ||
"domains": [ | ||
{ | ||
"domain": ["localhost", "privacy-test-pages.site"], | ||
"patchSettings": [ | ||
{ | ||
"op": "add", | ||
"path": "/modifyCookies/changes/-", | ||
"value": { | ||
"key": "keyToBeDeleted", | ||
"action": "delete" | ||
} | ||
}, | ||
{ | ||
"op": "add", | ||
"path": "/modifyCookies/changes/-", | ||
"value": { | ||
"key": "pathCookie", | ||
"action": "delete" | ||
} | ||
}, | ||
{ | ||
"op": "add", | ||
"path": "/modifyCookies/changes/-", | ||
"value": { | ||
"key": "pathCookieWithPath", | ||
"path": "/webcompat/pages/", | ||
"action": "delete" | ||
} | ||
}, | ||
{ | ||
"op": "add", | ||
"path": "/modifyCookies/changes/-", | ||
"value": { | ||
"key": "nonexistentKey", | ||
"action": "delete" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
injected/integration-test/test-pages/webcompat/pages/modify-cookies.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Modify Cookies</title> | ||
<link rel="stylesheet" href="../../shared/style.css"> | ||
<script> | ||
// Current file path | ||
let path = '/webcompat/pages/' | ||
document.cookie = 'keyToBeDeleted="valueToBeDeleted"' | ||
document.cookie = 'pathCookie="valueToBeDeleted"; path=' + path | ||
document.cookie = 'pathCookieWithPath="valueToBeDeleted"; path=' + path | ||
document.cookie = 'otherKey="valueToRemain"' | ||
</script> | ||
</head> | ||
<body> | ||
<script src="../../shared/utils.js"></script> | ||
<p><a href="../index.html">[WebCompat]</a></p> | ||
|
||
<p>This page verifies that cookie modifications work properly given the <a href="../config/modify-cookies.json">config</a>. At this time, only deletion is supported.</p> | ||
|
||
<script> | ||
// Copy from: https://stackoverflow.com/a/2144404 | ||
function hasCookie(name){ | ||
return document.cookie.split(';').some(c => { | ||
return c.trim().startsWith(name + '='); | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line no-undef | ||
test('Only specified cookies should be removed', async () => { | ||
const specifiedKey = hasCookie('keyToBeDeleted') | ||
const pathKey = hasCookie('pathCookie') | ||
const pathKey2 = hasCookie('pathCookie2') | ||
const pathKey3 = hasCookie('pathCookieWithPath') | ||
const nonexistentKey = hasCookie('nonexistentKey') | ||
const otherKey = hasCookie('otherKey') | ||
|
||
return [ | ||
{ name: 'specified cookie entry deleted', result: specifiedKey, expected: false }, | ||
{ name: 'specified cookie entry with path not deleted', result: pathKey, expected: true }, | ||
{ name: `specified cookie entry with correct path (${path}) deleted`, result: pathKey3, expected: false }, | ||
{ name: 'specified cookie entry that is not present on page load', result: nonexistentKey, expected: false }, | ||
{ name: 'other cookie entry untouched', result: otherKey, expected: true } | ||
]; | ||
}); | ||
|
||
// eslint-disable-next-line no-undef | ||
renderResults(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we add a test that confirms
path
is working as expected?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.
Added test to check both states with path. I'd rather not add a second sub path test to validate some of the other cases (I don't think we need to validate the visibility of the cookie for example, because the behavior of cookie is path not set when deleting won't delete).
The same is true for domain but that's a bit more problematic as we intend to run these in a few places.