Skip to content

Commit

Permalink
Bug 1347817 - Principal must always have a valid origin - part 6 - fi…
Browse files Browse the repository at this point in the history
…xing tests, r=ehsan
  • Loading branch information
bakulf committed Mar 29, 2017
1 parent 6fd7c74 commit 028e9c2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ add_task(function* test_remote_window_open_aboutBlank() {

/**
* For loading the initial about:blank in non-e10s mode, it will be loaded with
* codebase principal. So we test if it has correct firstPartyDomain set.
* a null principal. So we test if it has correct firstPartyDomain set.
*/
add_task(function* test_nonremote_window_open_aboutBlank() {
let win = yield BrowserTestUtils.openNewBrowserWindow({remote: false});
Expand All @@ -43,8 +43,8 @@ add_task(function* test_nonremote_window_open_aboutBlank() {

let attrs = { firstPartyDomain: "about.ef2a7dd5-93bc-417f-a698-142c3116864f.mozilla" };
yield ContentTask.spawn(browser, attrs, function* (expectAttrs) {
Assert.ok(content.document.nodePrincipal.isCodebasePrincipal,
"The principal of non-remote about:blank should be a codebase principal.");
Assert.ok(!content.document.nodePrincipal.isCodebasePrincipal,
"The principal of non-remote about:blank should not be a codebase principal.");
Assert.equal(content.document.nodePrincipal.originAttributes.firstPartyDomain,
expectAttrs.firstPartyDomain,
"non-remote about:blank should have firstPartyDomain set");
Expand Down
5 changes: 3 additions & 2 deletions browser/components/preferences/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ var gPermissionManager = {
try {
uri = Services.io.newURI(input_url);
principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
// If we have ended up with an unknown scheme, the following will throw.
principal.origin;
if (principal.origin.startsWith("moz-nullprincipal:")) {
throw "Null principal";
}
} catch (ex) {
uri = Services.io.newURI("http://" + input_url);
principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
Expand Down
9 changes: 1 addition & 8 deletions caps/tests/unit/test_origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,5 @@ function run_test() {

var aboutBlankURI = makeURI('about:blank');
var aboutBlankPrin = ssm.createCodebasePrincipal(aboutBlankURI, {});
var thrown = false;
try {
aboutBlankPrin.origin;
} catch (e) {
thrown = true;
}
do_check_true(thrown);

do_check_true(/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(aboutBlankPrin.origin));
}
2 changes: 1 addition & 1 deletion dom/base/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ WebSocketImpl::Init(JSContext* aCx,
isNullPrincipal = principal->GetIsNullPrincipal();
}

if (!isNullPrincipal) {
if (isNullPrincipal) {
break;
}

Expand Down
11 changes: 5 additions & 6 deletions dom/base/nsGlobalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2551,12 +2551,11 @@ nsGlobalWindow::SetInitialPrincipalToSubject()

#ifdef DEBUG
// If we have a document loaded at this point, it had better be about:blank.
// Otherwise, something is really weird.
nsCOMPtr<nsIURI> uri;
mDoc->NodePrincipal()->GetURI(getter_AddRefs(uri));
NS_ASSERTION(uri && NS_IsAboutBlank(uri) &&
NS_IsAboutBlank(mDoc->GetDocumentURI()),
"Unexpected original document");
// Otherwise, something is really weird. An about:blank page has a
// NullPrincipal.
bool isNullPrincipal;
MOZ_ASSERT(NS_SUCCEEDED(mDoc->NodePrincipal()->GetIsNullPrincipal(&isNullPrincipal)) &&
isNullPrincipal);
#endif
}

Expand Down
2 changes: 0 additions & 2 deletions dom/security/test/unit/test_isOriginPotentiallyTrustworthy.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ add_task(function* test_isOriginPotentiallyTrustworthy() {
["http://127.0.0.1/", true],
["file:///", true],
["resource:///", true],
["app://", true],
["moz-extension://", true],
["wss://example.com/", true],
["about:config", false],
["urn:generic", false],
["http://example.net/", true],
["ws://example.org/", true],
["chrome://example.net/content/messenger.xul", false],
Expand Down

0 comments on commit 028e9c2

Please sign in to comment.