Bug 1561435 - Format caps/, a=automatic-formatting

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D35897

--HG--
extra : source : d4805a576be19af1130a6b52810d4108c49178d5
This commit is contained in:
Victor Porof 2019-07-05 09:58:41 +02:00
parent 0e8a695ad5
commit c24167d198
5 changed files with 445 additions and 221 deletions

View File

@ -44,7 +44,6 @@ module.exports = {
],
"overrides": [{
"files": [
"caps/**",
"chrome/**",
"config/**",
"devtools/**",

View File

@ -40,7 +40,6 @@ toolkit/components/telemetry/datareporting-prefs.js
toolkit/components/telemetry/healthreport-prefs.js
# Ignore all top-level directories for now.
caps/**
chrome/**
config/**
docshell/**

View File

@ -1,6 +1,6 @@
"use strict";
let tests = [ "about:robots?foo", "about:robots#foo", "about:robots?foo#bar"];
let tests = ["about:robots?foo", "about:robots#foo", "about:robots?foo#bar"];
tests.forEach(async test => {
add_task(async () => {
await BrowserTestUtils.withNewTab(test, async browser => {

View File

@ -6,177 +6,239 @@ const kDummyPage = getRootDirectory(gTestPath);
const kAboutPagesRegistered = Promise.all([
BrowserTestUtils.registerAboutPage(
registerCleanupFunction, "test-chrome-privs", kDummyPage,
Ci.nsIAboutModule.ALLOW_SCRIPT),
registerCleanupFunction,
"test-chrome-privs",
kDummyPage,
Ci.nsIAboutModule.ALLOW_SCRIPT
),
BrowserTestUtils.registerAboutPage(
registerCleanupFunction, "test-chrome-privs2", kDummyPage,
Ci.nsIAboutModule.ALLOW_SCRIPT),
registerCleanupFunction,
"test-chrome-privs2",
kDummyPage,
Ci.nsIAboutModule.ALLOW_SCRIPT
),
BrowserTestUtils.registerAboutPage(
registerCleanupFunction, "test-unknown-linkable", kDummyPage,
Ci.nsIAboutModule.MAKE_LINKABLE | Ci.nsIAboutModule.ALLOW_SCRIPT),
registerCleanupFunction,
"test-unknown-linkable",
kDummyPage,
Ci.nsIAboutModule.MAKE_LINKABLE | Ci.nsIAboutModule.ALLOW_SCRIPT
),
BrowserTestUtils.registerAboutPage(
registerCleanupFunction, "test-unknown-linkable2", kDummyPage,
Ci.nsIAboutModule.MAKE_LINKABLE | Ci.nsIAboutModule.ALLOW_SCRIPT),
registerCleanupFunction,
"test-unknown-linkable2",
kDummyPage,
Ci.nsIAboutModule.MAKE_LINKABLE | Ci.nsIAboutModule.ALLOW_SCRIPT
),
BrowserTestUtils.registerAboutPage(
registerCleanupFunction, "test-unknown-unlinkable", kDummyPage,
Ci.nsIAboutModule.ALLOW_SCRIPT),
registerCleanupFunction,
"test-unknown-unlinkable",
kDummyPage,
Ci.nsIAboutModule.ALLOW_SCRIPT
),
BrowserTestUtils.registerAboutPage(
registerCleanupFunction, "test-unknown-unlinkable2", kDummyPage,
Ci.nsIAboutModule.ALLOW_SCRIPT),
registerCleanupFunction,
"test-unknown-unlinkable2",
kDummyPage,
Ci.nsIAboutModule.ALLOW_SCRIPT
),
BrowserTestUtils.registerAboutPage(
registerCleanupFunction, "test-content-unlinkable", kDummyPage,
Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT | Ci.nsIAboutModule.ALLOW_SCRIPT),
registerCleanupFunction,
"test-content-unlinkable",
kDummyPage,
Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT |
Ci.nsIAboutModule.ALLOW_SCRIPT
),
BrowserTestUtils.registerAboutPage(
registerCleanupFunction, "test-content-unlinkable2", kDummyPage,
Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT | Ci.nsIAboutModule.ALLOW_SCRIPT),
registerCleanupFunction,
"test-content-unlinkable2",
kDummyPage,
Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT |
Ci.nsIAboutModule.ALLOW_SCRIPT
),
BrowserTestUtils.registerAboutPage(
registerCleanupFunction, "test-content-linkable", kDummyPage,
Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT | Ci.nsIAboutModule.MAKE_LINKABLE |
Ci.nsIAboutModule.ALLOW_SCRIPT),
registerCleanupFunction,
"test-content-linkable",
kDummyPage,
Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT |
Ci.nsIAboutModule.MAKE_LINKABLE |
Ci.nsIAboutModule.ALLOW_SCRIPT
),
BrowserTestUtils.registerAboutPage(
registerCleanupFunction, "test-content-linkable2", kDummyPage,
Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT | Ci.nsIAboutModule.MAKE_LINKABLE |
Ci.nsIAboutModule.ALLOW_SCRIPT),
registerCleanupFunction,
"test-content-linkable2",
kDummyPage,
Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT |
Ci.nsIAboutModule.MAKE_LINKABLE |
Ci.nsIAboutModule.ALLOW_SCRIPT
),
]);
const URLs = new Map([
["http://www.example.com", [
// For each of these entries, the booleans represent whether the parent URI can:
// - load them
// - load them without principal inheritance
// - whether the URI can be created at all (some protocol handlers will
// refuse to create certain variants)
["http://www.example2.com", true, true, true],
["https://www.example2.com", true, true, true],
["moz-icon:file:///foo/bar/baz.exe", false, false, true],
["moz-icon://.exe", false, false, true],
["chrome://foo/content/bar.xul", false, false, true],
["view-source:http://www.example2.com", false, false, true],
["view-source:https://www.example2.com", false, false, true],
["data:text/html,Hi", true, false, true],
["view-source:data:text/html,Hi", false, false, true],
["javascript:alert('hi')", true, false, true],
["moz://a", false, false, true],
["about:test-chrome-privs", false, false, true],
["about:test-unknown-unlinkable", false, false, true],
["about:test-content-unlinkable", false, false, true],
["about:test-content-linkable", true, true, true],
// Because this page doesn't have SAFE_FOR_UNTRUSTED, the web can't link to it:
["about:test-unknown-linkable", false, false, true],
]],
["view-source:http://www.example.com", [
["http://www.example2.com", true, true, true],
["https://www.example2.com", true, true, true],
["moz-icon:file:///foo/bar/baz.exe", false, false, true],
["moz-icon://.exe", false, false, true],
["chrome://foo/content/bar.xul", false, false, true],
["view-source:http://www.example2.com", true, true, true],
["view-source:https://www.example2.com", true, true, true],
["data:text/html,Hi", true, false, true],
["view-source:data:text/html,Hi", true, false, true],
["javascript:alert('hi')", true, false, true],
["moz://a", false, false, true],
["about:test-chrome-privs", false, false, true],
["about:test-unknown-unlinkable", false, false, true],
["about:test-content-unlinkable", false, false, true],
["about:test-content-linkable", true, true, true],
// Because this page doesn't have SAFE_FOR_UNTRUSTED, the web can't link to it:
["about:test-unknown-linkable", false, false, true],
]],
[
"http://www.example.com",
[
// For each of these entries, the booleans represent whether the parent URI can:
// - load them
// - load them without principal inheritance
// - whether the URI can be created at all (some protocol handlers will
// refuse to create certain variants)
["http://www.example2.com", true, true, true],
["https://www.example2.com", true, true, true],
["moz-icon:file:///foo/bar/baz.exe", false, false, true],
["moz-icon://.exe", false, false, true],
["chrome://foo/content/bar.xul", false, false, true],
["view-source:http://www.example2.com", false, false, true],
["view-source:https://www.example2.com", false, false, true],
["data:text/html,Hi", true, false, true],
["view-source:data:text/html,Hi", false, false, true],
["javascript:alert('hi')", true, false, true],
["moz://a", false, false, true],
["about:test-chrome-privs", false, false, true],
["about:test-unknown-unlinkable", false, false, true],
["about:test-content-unlinkable", false, false, true],
["about:test-content-linkable", true, true, true],
// Because this page doesn't have SAFE_FOR_UNTRUSTED, the web can't link to it:
["about:test-unknown-linkable", false, false, true],
],
],
[
"view-source:http://www.example.com",
[
["http://www.example2.com", true, true, true],
["https://www.example2.com", true, true, true],
["moz-icon:file:///foo/bar/baz.exe", false, false, true],
["moz-icon://.exe", false, false, true],
["chrome://foo/content/bar.xul", false, false, true],
["view-source:http://www.example2.com", true, true, true],
["view-source:https://www.example2.com", true, true, true],
["data:text/html,Hi", true, false, true],
["view-source:data:text/html,Hi", true, false, true],
["javascript:alert('hi')", true, false, true],
["moz://a", false, false, true],
["about:test-chrome-privs", false, false, true],
["about:test-unknown-unlinkable", false, false, true],
["about:test-content-unlinkable", false, false, true],
["about:test-content-linkable", true, true, true],
// Because this page doesn't have SAFE_FOR_UNTRUSTED, the web can't link to it:
["about:test-unknown-linkable", false, false, true],
],
],
// about: related tests.
["about:test-chrome-privs", [
["about:test-chrome-privs", true, true, true],
["about:test-chrome-privs2", true, true, true],
["about:test-chrome-privs2?foo#bar", true, true, true],
["about:test-chrome-privs2?foo", true, true, true],
["about:test-chrome-privs2#bar", true, true, true],
[
"about:test-chrome-privs",
[
["about:test-chrome-privs", true, true, true],
["about:test-chrome-privs2", true, true, true],
["about:test-chrome-privs2?foo#bar", true, true, true],
["about:test-chrome-privs2?foo", true, true, true],
["about:test-chrome-privs2#bar", true, true, true],
["about:test-unknown-unlinkable", true, true, true],
["about:test-unknown-unlinkable", true, true, true],
["about:test-content-unlinkable", true, true, true],
["about:test-content-unlinkable?foo", true, true, true],
["about:test-content-unlinkable?foo#bar", true, true, true],
["about:test-content-unlinkable#bar", true, true, true],
["about:test-content-unlinkable", true, true, true],
["about:test-content-unlinkable?foo", true, true, true],
["about:test-content-unlinkable?foo#bar", true, true, true],
["about:test-content-unlinkable#bar", true, true, true],
["about:test-content-linkable", true, true, true],
["about:test-content-linkable", true, true, true],
["about:test-unknown-linkable", true, true, true],
["moz-icon:file:///foo/bar/baz.exe", true, true, true],
["moz-icon://.exe", true, true, true],
]],
["about:test-unknown-unlinkable", [
["about:test-chrome-privs", false, false, true],
["about:test-unknown-linkable", true, true, true],
["moz-icon:file:///foo/bar/baz.exe", true, true, true],
["moz-icon://.exe", true, true, true],
],
],
[
"about:test-unknown-unlinkable",
[
["about:test-chrome-privs", false, false, true],
// Can link to ourselves:
["about:test-unknown-unlinkable", true, true, true],
// Can't link to unlinkable content if we're not sure it's privileged:
["about:test-unknown-unlinkable2", false, false, true],
// Can link to ourselves:
["about:test-unknown-unlinkable", true, true, true],
// Can't link to unlinkable content if we're not sure it's privileged:
["about:test-unknown-unlinkable2", false, false, true],
["about:test-content-unlinkable", true, true, true],
["about:test-content-unlinkable2", true, true, true],
["about:test-content-unlinkable2?foo", true, true, true],
["about:test-content-unlinkable2?foo#bar", true, true, true],
["about:test-content-unlinkable2#bar", true, true, true],
["about:test-content-unlinkable", true, true, true],
["about:test-content-unlinkable2", true, true, true],
["about:test-content-unlinkable2?foo", true, true, true],
["about:test-content-unlinkable2?foo#bar", true, true, true],
["about:test-content-unlinkable2#bar", true, true, true],
["about:test-content-linkable", true, true, true],
["about:test-content-linkable", true, true, true],
// Because this page doesn't have SAFE_FOR_UNTRUSTED, the web can't link to it:
["about:test-unknown-linkable", false, false, true],
]],
["about:test-content-unlinkable", [
["about:test-chrome-privs", false, false, true],
// Because this page doesn't have SAFE_FOR_UNTRUSTED, the web can't link to it:
["about:test-unknown-linkable", false, false, true],
],
],
[
"about:test-content-unlinkable",
[
["about:test-chrome-privs", false, false, true],
// Can't link to unlinkable content if we're not sure it's privileged:
["about:test-unknown-unlinkable", false, false, true],
// Can't link to unlinkable content if we're not sure it's privileged:
["about:test-unknown-unlinkable", false, false, true],
["about:test-content-unlinkable", true, true, true],
["about:test-content-unlinkable2", true, true, true],
["about:test-content-unlinkable2?foo", true, true, true],
["about:test-content-unlinkable2?foo#bar", true, true, true],
["about:test-content-unlinkable2#bar", true, true, true],
["about:test-content-unlinkable", true, true, true],
["about:test-content-unlinkable2", true, true, true],
["about:test-content-unlinkable2?foo", true, true, true],
["about:test-content-unlinkable2?foo#bar", true, true, true],
["about:test-content-unlinkable2#bar", true, true, true],
["about:test-content-linkable", true, true, true],
["about:test-unknown-linkable", false, false, true],
]],
["about:test-unknown-linkable", [
["about:test-chrome-privs", false, false, true],
["about:test-content-linkable", true, true, true],
["about:test-unknown-linkable", false, false, true],
],
],
[
"about:test-unknown-linkable",
[
["about:test-chrome-privs", false, false, true],
// Linkable content can't link to unlinkable content.
["about:test-unknown-unlinkable", false, false, true],
// Linkable content can't link to unlinkable content.
["about:test-unknown-unlinkable", false, false, true],
["about:test-content-unlinkable", false, false, true],
["about:test-content-unlinkable2", false, false, true],
["about:test-content-unlinkable2?foo", false, false, true],
["about:test-content-unlinkable2?foo#bar", false, false, true],
["about:test-content-unlinkable2#bar", false, false, true],
["about:test-content-unlinkable", false, false, true],
["about:test-content-unlinkable2", false, false, true],
["about:test-content-unlinkable2?foo", false, false, true],
["about:test-content-unlinkable2?foo#bar", false, false, true],
["about:test-content-unlinkable2#bar", false, false, true],
// ... but it can link to other linkable content.
["about:test-content-linkable", true, true, true],
// ... but it can link to other linkable content.
["about:test-content-linkable", true, true, true],
// Can link to ourselves:
["about:test-unknown-linkable", true, true, true],
// Can link to ourselves:
["about:test-unknown-linkable", true, true, true],
// Because this page doesn't have SAFE_FOR_UNTRUSTED, the web can't link to it:
["about:test-unknown-linkable2", false, false, true],
]],
["about:test-content-linkable", [
["about:test-chrome-privs", false, false, true],
// Because this page doesn't have SAFE_FOR_UNTRUSTED, the web can't link to it:
["about:test-unknown-linkable2", false, false, true],
],
],
[
"about:test-content-linkable",
[
["about:test-chrome-privs", false, false, true],
// Linkable content can't link to unlinkable content.
["about:test-unknown-unlinkable", false, false, true],
// Linkable content can't link to unlinkable content.
["about:test-unknown-unlinkable", false, false, true],
["about:test-content-unlinkable", false, false, true],
["about:test-content-unlinkable", false, false, true],
// ... but it can link to itself and other linkable content.
["about:test-content-linkable", true, true, true],
["about:test-content-linkable2", true, true, true],
// ... but it can link to itself and other linkable content.
["about:test-content-linkable", true, true, true],
["about:test-content-linkable2", true, true, true],
// Because this page doesn't have SAFE_FOR_UNTRUSTED, the web can't link to it:
["about:test-unknown-linkable", false, false, true],
]],
// Because this page doesn't have SAFE_FOR_UNTRUSTED, the web can't link to it:
["about:test-unknown-linkable", false, false, true],
],
],
]);
function testURL(source, target, canLoad, canLoadWithoutInherit, canCreate, flags) {
function testURL(
source,
target,
canLoad,
canLoadWithoutInherit,
canCreate,
flags
) {
function getPrincipalDesc(principal) {
if (principal.URI) {
return principal.URI.spec;
@ -194,11 +256,21 @@ function testURL(source, target, canLoad, canLoadWithoutInherit, canCreate, flag
try {
targetURI = makeURI(target);
} catch (ex) {
ok(!canCreate, "Shouldn't be passing URIs that we can't create. Failed to create: " + target);
ok(
!canCreate,
"Shouldn't be passing URIs that we can't create. Failed to create: " +
target
);
return;
}
ok(canCreate, "Created a URI for " + target + " which should " +
(canCreate ? "" : "not ") + "be possible.");
ok(
canCreate,
"Created a URI for " +
target +
" which should " +
(canCreate ? "" : "not ") +
"be possible."
);
try {
ssm.checkLoadURIWithPrincipal(source, targetURI, flags);
} catch (ex) {
@ -207,10 +279,17 @@ function testURL(source, target, canLoad, canLoadWithoutInherit, canCreate, flag
}
let inheritDisallowed = flags & ssm.DISALLOW_INHERIT_PRINCIPAL;
let shouldThrow = inheritDisallowed ? !canLoadWithoutInherit : !canLoad;
ok(threw == shouldThrow,
"Should " + (shouldThrow ? "" : "not ") + "throw an error when loading " +
target + " from " + getPrincipalDesc(source) +
(inheritDisallowed ? " without" : " with") + " principal inheritance.");
ok(
threw == shouldThrow,
"Should " +
(shouldThrow ? "" : "not ") +
"throw an error when loading " +
target +
" from " +
getPrincipalDesc(source) +
(inheritDisallowed ? " without" : " with") +
" principal inheritance."
);
}
add_task(async function() {
@ -223,40 +302,79 @@ add_task(async function() {
} else {
source = ssm.createCodebasePrincipal(makeURI(sourceString), {});
}
for (let [target, canLoad, canLoadWithoutInherit, canCreate] of targetsAndExpectations) {
testURL(source, target, canLoad, canLoadWithoutInherit, canCreate, baseFlags);
testURL(source, target, canLoad, canLoadWithoutInherit, canCreate,
baseFlags | ssm.DISALLOW_INHERIT_PRINCIPAL);
for (let [
target,
canLoad,
canLoadWithoutInherit,
canCreate,
] of targetsAndExpectations) {
testURL(
source,
target,
canLoad,
canLoadWithoutInherit,
canCreate,
baseFlags
);
testURL(
source,
target,
canLoad,
canLoadWithoutInherit,
canCreate,
baseFlags | ssm.DISALLOW_INHERIT_PRINCIPAL
);
}
}
// Now test blob URIs, which we need to do in-content.
await BrowserTestUtils.withNewTab("http://www.example.com/", async function(browser) {
await ContentTask.spawn(
browser,
testURL.toString(),
async function(testURLFn) {
// eslint-disable-next-line no-shadow , no-eval
let testURL = eval("(" + testURLFn + ")");
// eslint-disable-next-line no-shadow
let ssm = Services.scriptSecurityManager;
// eslint-disable-next-line no-shadow
let baseFlags = ssm.STANDARD | ssm.DONT_REPORT_ERRORS;
// eslint-disable-next-line no-unused-vars
let makeURI = ChromeUtils.import("resource://gre/modules/BrowserUtils.jsm", {}).BrowserUtils.makeURI;
let b = new content.Blob(["I am a blob"]);
let contentBlobURI = content.URL.createObjectURL(b);
let contentPrincipal = content.document.nodePrincipal;
// Loading this blob URI from the content page should work:
testURL(contentPrincipal, contentBlobURI, true, true, true, baseFlags);
testURL(contentPrincipal, contentBlobURI, true, true, true,
baseFlags | ssm.DISALLOW_INHERIT_PRINCIPAL);
await BrowserTestUtils.withNewTab("http://www.example.com/", async function(
browser
) {
await ContentTask.spawn(browser, testURL.toString(), async function(
testURLFn
) {
// eslint-disable-next-line no-shadow , no-eval
let testURL = eval("(" + testURLFn + ")");
// eslint-disable-next-line no-shadow
let ssm = Services.scriptSecurityManager;
// eslint-disable-next-line no-shadow
let baseFlags = ssm.STANDARD | ssm.DONT_REPORT_ERRORS;
// eslint-disable-next-line no-unused-vars
let makeURI = ChromeUtils.import(
"resource://gre/modules/BrowserUtils.jsm",
{}
).BrowserUtils.makeURI;
let b = new content.Blob(["I am a blob"]);
let contentBlobURI = content.URL.createObjectURL(b);
let contentPrincipal = content.document.nodePrincipal;
// Loading this blob URI from the content page should work:
testURL(contentPrincipal, contentBlobURI, true, true, true, baseFlags);
testURL(
contentPrincipal,
contentBlobURI,
true,
true,
true,
baseFlags | ssm.DISALLOW_INHERIT_PRINCIPAL
);
testURL(contentPrincipal, "view-source:" + contentBlobURI, false, false, true,
baseFlags);
testURL(contentPrincipal, "view-source:" + contentBlobURI, false, false, true,
baseFlags | ssm.DISALLOW_INHERIT_PRINCIPAL);
}
);
testURL(
contentPrincipal,
"view-source:" + contentBlobURI,
false,
false,
true,
baseFlags
);
testURL(
contentPrincipal,
"view-source:" + contentBlobURI,
false,
false,
true,
baseFlags | ssm.DISALLOW_INHERIT_PRINCIPAL
);
});
});
});

View File

@ -1,10 +1,16 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var ssm = Services.scriptSecurityManager;
function makeURI(uri) { return Services.io.newURI(uri); }
function makeURI(uri) {
return Services.io.newURI(uri);
}
function checkThrows(f) {
var threw = false;
try { f(); } catch (e) { threw = true; }
try {
f();
} catch (e) {
threw = true;
}
Assert.ok(threw);
}
@ -19,10 +25,15 @@ function checkCrossOrigin(a, b) {
function checkOriginAttributes(prin, attrs, suffix) {
attrs = attrs || {};
Assert.equal(prin.originAttributes.inIsolatedMozBrowser, attrs.inIsolatedMozBrowser || false);
Assert.equal(
prin.originAttributes.inIsolatedMozBrowser,
attrs.inIsolatedMozBrowser || false
);
Assert.equal(prin.originSuffix, suffix || "");
Assert.equal(ChromeUtils.originAttributesToSuffix(attrs), suffix || "");
Assert.ok(ChromeUtils.originAttributesMatchPattern(prin.originAttributes, attrs));
Assert.ok(
ChromeUtils.originAttributesMatchPattern(prin.originAttributes, attrs)
);
if (!prin.isNullPrincipal && !prin.origin.startsWith("[")) {
Assert.ok(ssm.createCodebasePrincipalFromOrigin(prin.origin).equals(prin));
} else {
@ -33,26 +44,42 @@ function checkOriginAttributes(prin, attrs, suffix) {
function checkSandboxOriginAttributes(arr, attrs, options) {
options = options || {};
var sandbox = Cu.Sandbox(arr, options);
checkOriginAttributes(Cu.getObjectPrincipal(sandbox), attrs,
ChromeUtils.originAttributesToSuffix(attrs));
checkOriginAttributes(
Cu.getObjectPrincipal(sandbox),
attrs,
ChromeUtils.originAttributesToSuffix(attrs)
);
}
// utility function useful for debugging
function printAttrs(name, attrs) {
info(name + " {\n" +
"\tuserContextId: " + attrs.userContextId + ",\n" +
"\tinIsolatedMozBrowser: " + attrs.inIsolatedMozBrowser + ",\n" +
"\tprivateBrowsingId: '" + attrs.privateBrowsingId + "',\n" +
"\tfirstPartyDomain: '" + attrs.firstPartyDomain + "'\n}");
info(
name +
" {\n" +
"\tuserContextId: " +
attrs.userContextId +
",\n" +
"\tinIsolatedMozBrowser: " +
attrs.inIsolatedMozBrowser +
",\n" +
"\tprivateBrowsingId: '" +
attrs.privateBrowsingId +
"',\n" +
"\tfirstPartyDomain: '" +
attrs.firstPartyDomain +
"'\n}"
);
}
function checkValues(attrs, values) {
values = values || {};
// printAttrs("attrs", attrs);
// printAttrs("values", values);
Assert.equal(attrs.userContextId, values.userContextId || 0);
Assert.equal(attrs.inIsolatedMozBrowser, values.inIsolatedMozBrowser || false);
Assert.equal(
attrs.inIsolatedMozBrowser,
values.inIsolatedMozBrowser || false
);
Assert.equal(attrs.privateBrowsingId, values.privateBrowsingId || "");
Assert.equal(attrs.firstPartyDomain, values.firstPartyDomain || "");
}
@ -61,58 +88,124 @@ function run_test() {
// Attributeless origins.
Assert.equal(ssm.getSystemPrincipal().origin, "[System Principal]");
checkOriginAttributes(ssm.getSystemPrincipal());
var exampleOrg = ssm.createCodebasePrincipal(makeURI("http://example.org"), {});
var exampleOrg = ssm.createCodebasePrincipal(
makeURI("http://example.org"),
{}
);
Assert.equal(exampleOrg.origin, "http://example.org");
checkOriginAttributes(exampleOrg);
var exampleCom = ssm.createCodebasePrincipal(makeURI("https://www.example.com:123"), {});
var exampleCom = ssm.createCodebasePrincipal(
makeURI("https://www.example.com:123"),
{}
);
Assert.equal(exampleCom.origin, "https://www.example.com:123");
checkOriginAttributes(exampleCom);
var nullPrin = Cu.getObjectPrincipal(new Cu.Sandbox(null));
Assert.ok(/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(nullPrin.origin));
Assert.ok(
/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(nullPrin.origin)
);
checkOriginAttributes(nullPrin);
var ipv6Prin = ssm.createCodebasePrincipal(makeURI("https://[2001:db8::ff00:42:8329]:123"), {});
var ipv6Prin = ssm.createCodebasePrincipal(
makeURI("https://[2001:db8::ff00:42:8329]:123"),
{}
);
Assert.equal(ipv6Prin.origin, "https://[2001:db8::ff00:42:8329]:123");
checkOriginAttributes(ipv6Prin);
var ipv6NPPrin = ssm.createCodebasePrincipal(makeURI("https://[2001:db8::ff00:42:8329]"), {});
var ipv6NPPrin = ssm.createCodebasePrincipal(
makeURI("https://[2001:db8::ff00:42:8329]"),
{}
);
Assert.equal(ipv6NPPrin.origin, "https://[2001:db8::ff00:42:8329]");
checkOriginAttributes(ipv6NPPrin);
var ep = Cu.getObjectPrincipal(Cu.Sandbox([exampleCom, nullPrin, exampleOrg]));
var ep = Cu.getObjectPrincipal(
Cu.Sandbox([exampleCom, nullPrin, exampleOrg])
);
checkOriginAttributes(ep);
checkCrossOrigin(exampleCom, exampleOrg);
checkCrossOrigin(exampleOrg, nullPrin);
// nsEP origins should be in lexical order.
Assert.equal(ep.origin, `[Expanded Principal [${exampleOrg.origin}, ${exampleCom.origin}, ${nullPrin.origin}]]`);
Assert.equal(
ep.origin,
`[Expanded Principal [${exampleOrg.origin}, ${exampleCom.origin}, ${
nullPrin.origin
}]]`
);
// Make sure createCodebasePrincipal does what the rest of gecko does.
Assert.ok(exampleOrg.equals(Cu.getObjectPrincipal(new Cu.Sandbox("http://example.org"))));
Assert.ok(
exampleOrg.equals(
Cu.getObjectPrincipal(new Cu.Sandbox("http://example.org"))
)
);
//
// Test origin attributes.
//
// Just browser.
var exampleOrg_browser = ssm.createCodebasePrincipal(makeURI("http://example.org"), {inIsolatedMozBrowser: true});
var nullPrin_browser = ssm.createNullPrincipal({inIsolatedMozBrowser: true});
checkOriginAttributes(exampleOrg_browser, {inIsolatedMozBrowser: true}, "^inBrowser=1");
checkOriginAttributes(nullPrin_browser, {inIsolatedMozBrowser: true}, "^inBrowser=1");
var exampleOrg_browser = ssm.createCodebasePrincipal(
makeURI("http://example.org"),
{ inIsolatedMozBrowser: true }
);
var nullPrin_browser = ssm.createNullPrincipal({
inIsolatedMozBrowser: true,
});
checkOriginAttributes(
exampleOrg_browser,
{ inIsolatedMozBrowser: true },
"^inBrowser=1"
);
checkOriginAttributes(
nullPrin_browser,
{ inIsolatedMozBrowser: true },
"^inBrowser=1"
);
Assert.equal(exampleOrg_browser.origin, "http://example.org^inBrowser=1");
// First party Uri
var exampleOrg_firstPartyDomain = ssm.createCodebasePrincipal(makeURI("http://example.org"), {firstPartyDomain: "example.org"});
checkOriginAttributes(exampleOrg_firstPartyDomain, { firstPartyDomain: "example.org" }, "^firstPartyDomain=example.org");
Assert.equal(exampleOrg_firstPartyDomain.origin, "http://example.org^firstPartyDomain=example.org");
var exampleOrg_firstPartyDomain = ssm.createCodebasePrincipal(
makeURI("http://example.org"),
{ firstPartyDomain: "example.org" }
);
checkOriginAttributes(
exampleOrg_firstPartyDomain,
{ firstPartyDomain: "example.org" },
"^firstPartyDomain=example.org"
);
Assert.equal(
exampleOrg_firstPartyDomain.origin,
"http://example.org^firstPartyDomain=example.org"
);
// Just userContext.
var exampleOrg_userContext = ssm.createCodebasePrincipal(makeURI("http://example.org"), {userContextId: 42});
checkOriginAttributes(exampleOrg_userContext, { userContextId: 42 }, "^userContextId=42");
Assert.equal(exampleOrg_userContext.origin, "http://example.org^userContextId=42");
var exampleOrg_userContext = ssm.createCodebasePrincipal(
makeURI("http://example.org"),
{ userContextId: 42 }
);
checkOriginAttributes(
exampleOrg_userContext,
{ userContextId: 42 },
"^userContextId=42"
);
Assert.equal(
exampleOrg_userContext.origin,
"http://example.org^userContextId=42"
);
checkSandboxOriginAttributes(null, {});
checkSandboxOriginAttributes("http://example.org", {});
checkSandboxOriginAttributes("http://example.org", {}, {originAttributes: {}});
checkSandboxOriginAttributes(
"http://example.org",
{},
{ originAttributes: {} }
);
checkSandboxOriginAttributes(["http://example.org"], {});
checkSandboxOriginAttributes(["http://example.org"], {}, {originAttributes: {}});
checkSandboxOriginAttributes(
["http://example.org"],
{},
{ originAttributes: {} }
);
// Check that all of the above are cross-origin.
checkCrossOrigin(exampleOrg_browser, nullPrin_browser);
@ -127,8 +220,18 @@ function run_test() {
Assert.equal(prin.isSystemPrincipal, kind == "systemPrincipal");
}
checkKind(ssm.createNullPrincipal({}), "nullPrincipal");
checkKind(ssm.createCodebasePrincipal(makeURI("http://www.example.com"), {}), "codebasePrincipal");
checkKind(Cu.getObjectPrincipal(Cu.Sandbox([ssm.createCodebasePrincipal(makeURI("http://www.example.com"), {})])), "expandedPrincipal");
checkKind(
ssm.createCodebasePrincipal(makeURI("http://www.example.com"), {}),
"codebasePrincipal"
);
checkKind(
Cu.getObjectPrincipal(
Cu.Sandbox([
ssm.createCodebasePrincipal(makeURI("http://www.example.com"), {}),
])
),
"expandedPrincipal"
);
checkKind(ssm.getSystemPrincipal(), "systemPrincipal");
//
@ -142,10 +245,11 @@ function run_test() {
var uri = "http://example.org";
var tests = [
[ "", {} ],
[ "^userContextId=3", {userContextId: 3} ],
[ "^inBrowser=1", {inIsolatedMozBrowser: true} ],
[ "^firstPartyDomain=example.org", {firstPartyDomain: "example.org"} ] ];
["", {}],
["^userContextId=3", { userContextId: 3 }],
["^inBrowser=1", { inIsolatedMozBrowser: true }],
["^firstPartyDomain=example.org", { firstPartyDomain: "example.org" }],
];
// check that we can create an origin attributes from an origin properly
tests.forEach(t => {
@ -167,8 +271,9 @@ function run_test() {
// [2] - the expected result after setting userContextId to the default
// [3] - the expected result of creating a suffix from [2]
var dflt_tests = [
[ "", {}, {}, "" ],
[ "^userContextId=3", {userContextId: 3}, {}, "" ] ];
["", {}, {}, ""],
["^userContextId=3", { userContextId: 3 }, {}, ""],
];
// check that we can set the userContextId to default properly
dflt_tests.forEach(t => {
@ -186,8 +291,9 @@ function run_test() {
// [2] - the expected result after setting firstPartyUri to the default
// [3] - the expected result of creating a suffix from [2]
var dflt2_tests = [
[ "", {}, {}, "" ],
[ "^firstPartyDomain=foo.com", {firstPartyDomain: "foo.com"}, {}, "" ] ];
["", {}, {}, ""],
["^firstPartyDomain=foo.com", { firstPartyDomain: "foo.com" }, {}, ""],
];
// check that we can set the userContextId to default properly
dflt2_tests.forEach(t => {
@ -213,5 +319,7 @@ function run_test() {
var aboutBlankURI = makeURI("about:blank");
var aboutBlankPrin = ssm.createCodebasePrincipal(aboutBlankURI, {});
Assert.ok(/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(aboutBlankPrin.origin));
Assert.ok(
/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(aboutBlankPrin.origin)
);
}