function initTest() {
SimpleTest.waitForExplicitFinish();
// Allow all cookies, then do the actual test initialization
SpecialPowers.pushPrefEnv({ "set": [
["network.cookie.cookieBehavior", 0],
// Bug 1617611: Fix all the tests broken by "cookies SameSite=lax by default"
["network.cookie.sameSite.laxByDefault", false],
["network.cors_preflight.authorization_covered_by_wildcard", false],
]
}, initTestCallback);
}
function initTestCallback() {
window.addEventListener("message", function(e) {
gen.next(e.data);
});
gen = runTest();
gen.next()
}
// eslint-disable-next-line complexity
function* runTest() { var loader = document.getElementById('loader'); var loaderWindow = loader.contentWindow;
loader.onload = function () { gen.next() };
// Test preflight-less requests
basePath = "/tests/dom/security/test/cors/file_CrossSiteXHR_server.sjs?" base = self.location.origin;
baseHost = self.location.host;
baseURL = base + basePath;
if ("username" in test) {
req.username = test.username;
}
if ("password" in test) {
req.password = test.password;
}
if (test.noAllowPreflight)
req.url += "&noAllowPreflight";
if (test.allowCred)
req.url += "&allowCred";
if (test.pass && "headers" in test) {
function isUnsafeHeader(name) {
lName = name.toLowerCase();
return lName != "accept" &&
lName != "accept-language" &&
(lName != "content-type" ||
!["text/plain", "multipart/form-data", "application/x-www-form-urlencoded"]
.includes(test.headers[name].toLowerCase()));
}
req.url += "&headers=" + escape(JSON.stringify(test.headers));
reqHeaders =
escape(Object.keys(test.headers)
.filter(isUnsafeHeader)
.map(s => s.toLowerCase())
.sort()
.join(","));
req.url += reqHeaders ? "&requestHeaders=" + reqHeaders : "";
}
if ("allowHeaders" in test)
req.url += "&allowHeaders=" + escape(test.allowHeaders);
if ("allowMethods" in test)
req.url += "&allowMethods=" + escape(test.allowMethods);
if (test.body)
req.url += "&body=" + escape(test.body);
if (test.status) {
req.url += "&status=" + test.status;
req.url += "&statusMessage=" + escape(test.statusMessage);
}
if (test.preflightStatus)
req.url += "&preflightStatus=" + test.preflightStatus;
if (test.responseHeaders)
req.url += "&responseHeaders=" + escape(JSON.stringify(test.responseHeaders));
if (test.exposeHeaders)
req.url += "&exposeHeaders=" + escape(test.exposeHeaders);
if (test.preflightBody)
req.url += "&preflightBody=" + escape(test.preflightBody);
loaderWindow.postMessage(JSON.stringify(req), origin);
res = JSON.parse(yield);
if (test.pass) {
is(res.didFail, false, "shouldn't have failed in test for " + JSON.stringify(test));
if (test.status) {
is(res.status, test.status, "wrong status in test for " + JSON.stringify(test));
is(res.statusText, test.statusMessage, "wrong status text for " + JSON.stringify(test));
}
else {
is(res.status, 200, "wrong status in test for " + JSON.stringify(test));
is(res.statusText, "OK", "wrong status text for " + JSON.stringify(test));
}
if (test.method !== "HEAD") {
is(res.responseXML, "hello pass", "wrong responseXML in test for " + JSON.stringify(test));
is(res.responseText, "hello pass\n", "wrong responseText in test for " + JSON.stringify(test));
is(res.events.join(","), "opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend", "wrong responseText in test for " + JSON.stringify(test));
}
else {
is(res.responseXML, null, "wrong responseXML in test for " + JSON.stringify(test));
is(res.responseText, "", "wrong responseText in test for " + JSON.stringify(test));
is(res.events.join(","), "opening,rs1,sending,loadstart,rs2,rs4,load,loadend", "wrong responseText in test for " + JSON.stringify(test));
}
if (test.responseHeaders) {
for (header in test.responseHeaders) {
if (!test.expectedResponseHeaders.includes(header)) {
is(res.responseHeaders[header], null, "|xhr.getResponseHeader()|wrong response header (" + header + ") in test for " +
JSON.stringify(test));
is(res.allResponseHeaders[header], undefined, "|xhr.getAllResponseHeaderss()|wrong response header (" + header + ") in test for " +
JSON.stringify(test));
}
else {
is(res.responseHeaders[header], test.responseHeaders[header], "|xhr.getResponseHeader()|wrong response header (" + header + ") in test for " +
JSON.stringify(test));
is(res.allResponseHeaders[header.toLowerCase()], test.responseHeaders[header], "|xhr.getAllResponseHeaderss()|wrong response header (" + header + ") in test for " +
JSON.stringify(test));
}
}
}
}
else {
is(res.didFail, true, "should have failed in test for " + JSON.stringify(test));
is(res.status, 0, "wrong status in test for " + JSON.stringify(test));
is(res.statusText, "", "wrong status text for " + JSON.stringify(test));
is(res.responseXML, null, "wrong responseXML in test for " + JSON.stringify(test));
is(res.responseText, "", "wrong responseText in test for " + JSON.stringify(test));
if (!res.sendThrew) {
is(res.events.join(","), "opening,rs1,sending,loadstart,rs4,error,loadend", "wrong events in test for " + JSON.stringify(test));
}
is(res.progressEvents, 0, "wrong events in test for " + JSON.stringify(test));
if (test.responseHeaders) {
for (header in test.responseHeaders) {
is(res.responseHeaders[header], null, "wrong response header (" + header + ") in test for " +
JSON.stringify(test));
}
}
}
}
if (test.setCookie)
req.url += "&setCookie=" + escape(test.setCookie);
if (test.cookie)
req.url += "&cookie=" + escape(test.cookie);
if (test.noCookie)
req.url += "&noCookie";
if ("allowHeaders" in test)
req.url += "&allowHeaders=" + escape(test.allowHeaders);
if ("allowMethods" in test)
req.url += "&allowMethods=" + escape(test.allowMethods);
res = JSON.parse(yield);
if (test.pass) {
is(res.didFail, false, "shouldn't have failed in test for " + JSON.stringify(test));
is(res.status, 200, "wrong status in test for " + JSON.stringify(test));
is(res.statusText, "OK", "wrong status text for " + JSON.stringify(test));
is(res.responseXML, "hello pass", "wrong responseXML in test for " + JSON.stringify(test));
is(res.responseText, "hello pass\n", "wrong responseText in test for " + JSON.stringify(test));
is(res.events.join(","), "opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend", "wrong responseText in test for " + JSON.stringify(test));
}
else {
is(res.didFail, true, "should have failed in test for " + JSON.stringify(test));
is(res.status, 0, "wrong status in test for " + JSON.stringify(test));
is(res.statusText, "", "wrong status text for " + JSON.stringify(test));
is(res.responseXML, null, "wrong responseXML in test for " + JSON.stringify(test));
is(res.responseText, "", "wrong responseText in test for " + JSON.stringify(test));
is(res.events.join(","), "opening,rs1,sending,loadstart,rs4,error,loadend", "wrong events in test for " + JSON.stringify(test));
is(res.progressEvents, 0, "wrong events in test for " + JSON.stringify(test));
}
}
// Make sure to clear cookies to avoid affecting other tests
document.cookie = "a=; partitioned; secure; samesite=none; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT"
is(document.cookie, "", "No cookies should be left over");
res = JSON.parse(yield);
if (test.pass) {
is(res.didFail, false, "shouldn't have failed in test for " + JSON.stringify(test));
is(res.status, 200, "wrong status in test for " + JSON.stringify(test));
is(res.statusText, "OK", "wrong status text for " + JSON.stringify(test));
is(res.responseXML, "hello pass", "wrong responseXML in test for " + JSON.stringify(test));
is(res.responseText, "hello pass\n", "wrong responseText in test for " + JSON.stringify(test));
is(res.events.join(","), "opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend", "wrong responseText in test for " + JSON.stringify(test));
}
else {
is(res.didFail, true, "should have failed in test for " + JSON.stringify(test));
is(res.status, 0, "wrong status in test for " + JSON.stringify(test));
is(res.statusText, "", "wrong status text for " + JSON.stringify(test));
is(res.responseXML, null, "wrong responseXML in test for " + JSON.stringify(test));
is(res.responseText, "", "wrong responseText in test for " + JSON.stringify(test));
is(res.events.join(","), "opening,rs1,sending,loadstart,rs4,error,loadend", "wrong events in test for " + JSON.stringify(test));
is(res.progressEvents, 0, "wrong progressevents in test for " + JSON.stringify(test));
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.