Commit 20da5e85 authored by Domenic Denicola's avatar Domenic Denicola Committed by Commit Bot

Origin isolation: add WPTs for different ports

Bug: 1042415
Change-Id: I5842aa32abc0b23e492c84ba0dc0e5906283a805
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2199550
Auto-Submit: Domenic Denicola <domenic@chromium.org>
Commit-Queue: James MacLean <wjmaclean@chromium.org>
Reviewed-by: default avatarJames MacLean <wjmaclean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785929}
parent f97ff9ea
<!DOCTYPE html>
<meta charset="utf-8">
<title>Parent is not isolated, child is isolated, child is different-origin to the parent because of a port mismatch</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script type="module">
import {
insertIframe,
testDifferentAgentClusters
} from "./resources/helpers.mjs";
promise_setup(async () => {
await insertIframe("{{hosts[][]}}:{{ports[https][1]}}", "?1");
});
// Since they're different-origin, the child's isolation request is respected,
// so the parent ends up in the site-keyed agent cluster and the child in the
// origin-keyed one.
testDifferentAgentClusters([self, 0]);
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Parent is not isolated, subdomain child 1 is not isolated, different-port-same-subdomain child 2 is isolated</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script type="module">
import {
insertIframe,
testSameAgentCluster,
testDifferentAgentClusters,
} from "./resources/helpers.mjs";
promise_setup(async () => {
// Order of loading should not matter, but we make it sequential to ensure the
// tests are deterministic.
await insertIframe("{{hosts[][www]}}");
await insertIframe("{{hosts[][www]}}:{{ports[https][1]}}", "?1");
});
// Since everybody is different-origin, everyone's requests/non-requests get
// respected.
//
// So, the parent and child 1 end up in the site-keyed agent cluster, and child
// 2 ends up in its own origin-keyed agent cluster.
testSameAgentCluster([self, 0], "Parent to child1");
testDifferentAgentClusters([self, 1], "Parent to child2");
testDifferentAgentClusters([0, 1], "child1 to child2");
testDifferentAgentClusters([1, 0], "child2 to child1");
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Parent is isolated, child is not isolated, child is is different-origin to the parent because of a port mismatch</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script type="module">
import {
insertIframe,
testDifferentAgentClusters
} from "./resources/helpers.mjs";
promise_setup(async () => {
await insertIframe("{{hosts[][]}}:{{ports[https][1]}}");
});
// Since they're different-origin, the parent's isolation request is respected,
// as is the child's non-request. So the parent ends up in the origin-keyed
// agent cluster and the child ends up in the site-keyed one.
testDifferentAgentClusters([self, 0]);
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Parent is isolated, child is not isolated, child is different-origin to the parent because of a port mismatch</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script type="module">
import {
insertIframe,
testDifferentAgentClusters
} from "./resources/helpers.mjs";
promise_setup(async () => {
await insertIframe("{{hosts[][]}}:{{ports[https][1]}}", "?1");
});
// Both request isolation, so the parent ends up in one origin-keyed agent
// cluster (the default port's origin), and the child ends up in a different
// origin-keyed agent cluster (the other port's origin).
testDifferentAgentClusters([self, 0]);
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Parent is isolated, subdomain child 1 is not isolated, different-port-same-subdomain child 2 is isolated</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script type="module">
import {
insertIframe,
testDifferentAgentClusters,
} from "./resources/helpers.mjs";
promise_setup(async () => {
// Order of loading should not matter, but we make it sequential to ensure the
// tests are deterministic.
await insertIframe("{{hosts[][www]}}");
await insertIframe("{{hosts[][www]}}:{{ports[https][1]}}", "?1");
});
// Since everybody is different-origin, everyone's requests/non-requests get
// respected.
//
// So, the parent ends up in its origin-keyed agent cluster, child 1 ends up in
// the site-keyed agent cluster, and child 2 ends up in a different origin-keyed
// agent cluster.
testDifferentAgentClusters([self, 0], "Parent to child1");
testDifferentAgentClusters([self, 1], "Parent to child2");
testDifferentAgentClusters([0, 1], "child1 to child2");
testDifferentAgentClusters([1, 0], "child2 to child1");
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Parent is isolated, subdomain child 1 is isolated, different-port-same-subdomain child 2 is isolated</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script type="module">
import {
insertIframe,
testDifferentAgentClusters,
} from "./resources/helpers.mjs";
promise_setup(async () => {
// Order of loading should not matter, but we make it sequential to ensure the
// tests are deterministic.
await insertIframe("{{hosts[][www]}}", "?1");
await insertIframe("{{hosts[][www]}}:{{ports[https][1]}}", "?1");
});
// Since everybody is different-origin, everyone's requests get
// respected.
//
// So, the parent ends up in its origin-keyed agent cluster, child 1 ends up in
// a second origin-keyed agent cluster, and child 2 ends up in a third
// origin-keyed agent cluster.
testDifferentAgentClusters([self, 0], "Parent to child1");
testDifferentAgentClusters([self, 1], "Parent to child2");
testDifferentAgentClusters([0, 1], "child1 to child2");
testDifferentAgentClusters([1, 0], "child2 to child1");
</script>
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
* Inserts an iframe usable for origin isolation testing, and returns a promise * Inserts an iframe usable for origin isolation testing, and returns a promise
* fulfilled when the iframe is loaded and its document.domain is set. The * fulfilled when the iframe is loaded and its document.domain is set. The
* iframe will point to the send-origin-isolation-header.py file, on the * iframe will point to the send-origin-isolation-header.py file, on the
* designated hostname * designated host
* @param {string} hostname - The hostname used to calculate the iframe's src="" * @param {string} host - The host used to calculate the iframe's src=""
* @param {string=} header - The value of the Origin-Isolation header that the * @param {string=} header - The value of the Origin-Isolation header that the
* iframe will set. Omit this to set no header. * iframe will set. Omit this to set no header.
* @returns {HTMLIFrameElement} The created iframe element * @returns {HTMLIFrameElement} The created iframe element
*/ */
export async function insertIframe(hostname, header) { export async function insertIframe(host, header) {
const iframe = document.createElement("iframe"); const iframe = document.createElement("iframe");
const navigatePromise = navigateIframe(iframe, hostname, header); const navigatePromise = navigateIframe(iframe, host, header);
document.body.append(iframe); document.body.append(iframe);
await navigatePromise; await navigatePromise;
await setBothDocumentDomains(iframe.contentWindow); await setBothDocumentDomains(iframe.contentWindow);
...@@ -21,15 +21,14 @@ export async function insertIframe(hostname, header) { ...@@ -21,15 +21,14 @@ export async function insertIframe(hostname, header) {
* Navigates an iframe to a page for origin isolation testing, similar to * Navigates an iframe to a page for origin isolation testing, similar to
* insertIframe but operating on an existing iframe. * insertIframe but operating on an existing iframe.
* @param {HTMLIFrameElement} iframeEl - The <iframe> element to navigate * @param {HTMLIFrameElement} iframeEl - The <iframe> element to navigate
* @param {string} hostname - The hostname used to calculate the iframe's new * @param {string} host - The host to calculate the iframe's new src=""
* src=""
* @param {string=} header - The value of the Origin-Isolation header that the * @param {string=} header - The value of the Origin-Isolation header that the
* newly-navigated-to page will set. Omit this to set no header. * newly-navigated-to page will set. Omit this to set no header.
* @returns {Promise} a promise fulfilled when the load event fires, or rejected * @returns {Promise} a promise fulfilled when the load event fires, or rejected
* if the error event fires * if the error event fires
*/ */
export function navigateIframe(iframeEl, hostname, header) { export function navigateIframe(iframeEl, host, header) {
const url = getIframeURL(hostname, header); const url = getIframeURL(host, header);
const waitPromise = waitForIframe(iframeEl, url); const waitPromise = waitForIframe(iframeEl, url);
iframeEl.src = url; iframeEl.src = url;
...@@ -230,9 +229,9 @@ async function getOriginIsolationRestricted(frameWindow) { ...@@ -230,9 +229,9 @@ async function getOriginIsolationRestricted(frameWindow) {
return waitForMessage(frameWindow); return waitForMessage(frameWindow);
} }
function getIframeURL(hostname, header) { function getIframeURL(host, header) {
const url = new URL("send-origin-isolation-header.py", import.meta.url); const url = new URL("send-origin-isolation-header.py", import.meta.url);
url.hostname = hostname; url.host = host;
if (header !== undefined) { if (header !== undefined) {
url.searchParams.set("header", header); url.searchParams.set("header", header);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment