Bug 1452715 - Add support for same-site cookie attribute to "Cookies" netmonitor side-panel; r=Honza

MozReview-Commit-ID: ESP8L9vqNjU

--HG--
extra : rebase_source : 3d25dce7298b2464cd3ca84a75b87187e1a093f1
This commit is contained in:
Vincent Lequertier 2018-05-05 18:24:20 +02:00
parent 3c2f4b195e
commit 10e03e088f
5 changed files with 109 additions and 1 deletions

View File

@ -47,6 +47,7 @@ support-files =
sjs_hsts-test-server.sjs
sjs_json-test-server.sjs
sjs_method-test-server.sjs
sjs_set-cookie-same-site.sjs
sjs_simple-test-server.sjs
sjs_simple-unsorted-cookies-test-server.sjs
sjs_sorting-test-server.sjs
@ -173,6 +174,7 @@ skip-if = os == 'win' # bug 1391264
[browser_net_security-warnings.js]
[browser_net_send-beacon.js]
[browser_net_send-beacon-other-tab.js]
[browser_net_set-cookie-same-site.js]
[browser_net_simple-request-data.js]
[browser_net_simple-request-details.js]
skip-if = true # Bug 1258809

View File

@ -0,0 +1,74 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test if the 'Same site' cookie attribute is correctly set in the cookie panel
*/
add_task(async function() {
let { tab, monitor } = await initNetMonitor(SET_COOKIE_SAME_SITE_SJS);
info("Starting test... ");
let { document, store, windowRequire } = monitor.panelWin;
let Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
store.dispatch(Actions.batchEnable(false));
tab.linkedBrowser.reload();
let wait = waitForNetworkEvents(monitor, 1);
await wait;
wait = waitForDOM(document, ".headers-overview");
EventUtils.sendMouseEvent({ type: "mousedown" },
document.querySelectorAll(".request-list-item")[0]);
await wait;
EventUtils.sendMouseEvent({ type: "click" },
document.querySelector("#cookies-tab"));
info("Checking the SameSite property");
const expectedValues = [
{
key: "Response cookies",
value: ""
},
{
key: "foo",
value: ""
},
{
key: "samesite",
value: "Lax"
},
{
key: "value",
value: "bar"
},
{
key: "Request cookies",
value: ""
},
{
key: "foo",
value: "bar"
},
];
let labelCells = document.querySelectorAll(".treeLabelCell");
let valueCells = document.querySelectorAll(".treeValueCell");
is(valueCells.length, labelCells.length, "Number of labels "
+ labelCells.length + " different from number of values " + valueCells.length);
// Go through the cookie properties and check if each one has the expected
// label and value
for (let index = 0; index < labelCells.length; ++index) {
is(labelCells[index].innerText, expectedValues[index].key,
"Actual label " + labelCells[index].innerText
+ " not equal to expected label " + expectedValues[index].key);
is(valueCells[index].innerText, expectedValues[index].value,
"Actual value " + valueCells[index].innerText
+ " not equal to expected value " + expectedValues[index].value);
}
await teardown(monitor);
});

View File

@ -85,6 +85,7 @@ const CORS_SJS_PATH = "/browser/devtools/client/netmonitor/test/sjs_cors-test-se
const HSTS_SJS = EXAMPLE_URL + "sjs_hsts-test-server.sjs";
const METHOD_SJS = EXAMPLE_URL + "sjs_method-test-server.sjs";
const SLOW_SJS = EXAMPLE_URL + "sjs_slow-test-server.sjs";
const SET_COOKIE_SAME_SITE_SJS = EXAMPLE_URL + "sjs_set-cookie-same-site.sjs";
const HSTS_BASE_URL = EXAMPLE_URL;
const HSTS_PAGE_URL = CUSTOM_GET_URL;

View File

@ -0,0 +1,10 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function handleRequest(request, response) {
response.setStatusLine(request.httpVersion, 200, "Och Aye");
response.setHeader("Set-Cookie", "foo=bar; SameSite=Lax");
response.write("Hello world!");
}

View File

@ -69,6 +69,14 @@ const L10N = new LocalizationHelper("devtools/client/locales/netmonitor.properti
// The cache used in the `nsIURL` function.
const gNSURLStore = new Map();
// "Lax", "Strict" and "Unset" are special values of the SameSite cookie
// attribute that should not be translated.
const COOKIE_SAMESITE = {
LAX: "Lax",
STRICT: "Strict",
UNSET: "Unset"
};
/**
* Helper object for networking stuff.
*
@ -353,9 +361,20 @@ var NetworkHelper = {
* @return array
* Array holding an object for each cookie. Each object holds the
* following properties: name, value, secure (boolean), httpOnly
* (boolean), path, domain and expires (ISO date string).
* (boolean), path, domain, samesite and expires (ISO date string).
*/
parseSetCookieHeader: function(header) {
function parseSameSiteAttribute(attribute) {
switch (attribute) {
case COOKIE_SAMESITE.LAX:
return COOKIE_SAMESITE.LAX;
case COOKIE_SAMESITE.STRICT:
return COOKIE_SAMESITE.STRICT;
default:
return COOKIE_SAMESITE.UNSET;
}
}
let rawCookies = header.split(/\r\n|\n|\r/);
let cookies = [];
@ -378,6 +397,8 @@ var NetworkHelper = {
pair[0] = pair[0].toLowerCase();
if (pair[0] == "path" || pair[0] == "domain") {
cookie[pair[0]] = pair[1];
} else if (pair[0] == "samesite") {
cookie[pair[0]] = parseSameSiteAttribute(pair[1]);
} else if (pair[0] == "expires") {
try {
pair[1] = pair[1].replace(/-/g, " ");