Commit cc224570 authored by Matt Menke's avatar Matt Menke Committed by Chromium LUCI CQ

SXG + reporting: Make WPT tests work with NetworkIsolationKeys.

NetworkIsolationKeys include top frame origin and frame origin.
The WPT SXG reporting tests load an SXG in a cross-site iframe, but
learn reporting information in the top-level browsing context, so it
had a different NIK.

This CL fixes those tests to learn reporting information in an iframe,
so they have the same NetworkIsolationKey as the signed exchange. With
this CL, all SXG WPT tests should now pass with reporting data
partitioned by NetworkIsolationKey.

Bug: 1156951
Change-Id: I0f8aa3bc51a276a71c28e92a056e709721bffb04
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580587
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarKunihiko Sakamoto <ksakamoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835642}
parent 34d5ab46
...@@ -24,6 +24,15 @@ function nel_test(callback, name, properties) { ...@@ -24,6 +24,15 @@ function nel_test(callback, name, properties) {
}, name, properties); }, name, properties);
} }
function nel_iframe_test(callback, name, properties) {
promise_test(async t => {
await obtainNELLock();
await clearReportingAndNELConfigurationsInIframe();
await callback(t);
await releaseNELLock();
}, name, properties);
}
/* /*
* Helper functions for constructing domain names that contain NEL policies. * Helper functions for constructing domain names that contain NEL policies.
*/ */
...@@ -68,6 +77,37 @@ function fetchResourceWithZeroSuccessFractionPolicy(subdomain) { ...@@ -68,6 +77,37 @@ function fetchResourceWithZeroSuccessFractionPolicy(subdomain) {
return fetch(url, {mode: "no-cors"}); return fetch(url, {mode: "no-cors"});
} }
/*
* Similar to the above methods, but fetch resources in an iframe. Allows matching
* full context of reports sent from an iframe that's same-site relative to the domains
* a policy set.
*/
function loadResourceWithBasicPolicyInIframe(subdomain) {
return loadResourceWithPolicyInIframe(
getURLForResourceWithBasicPolicy(subdomain));
}
function loadResourceWithZeroSuccessFractionPolicyInIframe(subdomain) {
return loadResourceWithPolicyInIframe(
_getNELResourceURL(subdomain, "pass.png?id="+reportID+"&success_fraction=0.0"));
}
function clearResourceWithBasicPolicyInIframe(subdomain) {
return loadResourceWithPolicyInIframe(
getURLForClearingConfiguration(subdomain));
}
function loadResourceWithPolicyInIframe(url) {
return new Promise((resolve, reject) => {
const frame = document.createElement('iframe');
frame.src = url;
frame.onload = () => resolve(frame);
frame.onerror = () => reject('failed to load ' + url);
document.body.appendChild(frame);
});
}
/* /*
* Fetches a resource whose headers define an include_subdomains NEL policy. * Fetches a resource whose headers define an include_subdomains NEL policy.
*/ */
...@@ -170,6 +210,16 @@ async function clearReportingAndNELConfigurations(subdomain) { ...@@ -170,6 +210,16 @@ async function clearReportingAndNELConfigurations(subdomain) {
return; return;
} }
async function clearReportingAndNELConfigurationsInIframe(subdomain) {
await Promise.all([
clearResourceWithBasicPolicyInIframe(""),
clearResourceWithBasicPolicyInIframe("www"),
clearResourceWithBasicPolicyInIframe("www1"),
clearResourceWithBasicPolicyInIframe("www2"),
]);
return;
}
/* /*
* Returns whether all of the fields in obj1 also exist in obj2 with the same * Returns whether all of the fields in obj1 also exist in obj2 with the same
* values. (Put another way, returns whether obj1 and obj2 are equal, ignoring * values. (Put another way, returns whether obj1 and obj2 are equal, ignoring
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + '/signed-exchange/resources/sxg/sxg-cert-not-found.sxg?navigation'; alt_origin + '/signed-exchange/resources/sxg/sxg-cert-not-found.sxg?navigation';
const cert_url = test_origin + '/signed-exchange/resources/not_found_certfile.cbor'; const cert_url = test_origin + '/signed-exchange/resources/not_found_certfile.cbor';
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<script> <script>
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg/sxg-cert-not-found-on-alt-origin.sxg?navigation'; '/signed-exchange/resources/sxg/sxg-cert-not-found-on-alt-origin.sxg?navigation';
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg/sxg-invalid-cert-format.sxg?navigation'; '/signed-exchange/resources/sxg/sxg-invalid-cert-format.sxg?navigation';
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<script> <script>
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg/sxg-invalid-cert-format-on-alt-origin.sxg?navigation'; '/signed-exchange/resources/sxg/sxg-invalid-cert-format-on-alt-origin.sxg?navigation';
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg/sxg-validity-period-too-long.sxg?navigation'; '/signed-exchange/resources/sxg/sxg-validity-period-too-long.sxg?navigation';
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<script> <script>
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg/sxg-validity-period-too-long-cert-on-alt-origin.sxg?navigation'; '/signed-exchange/resources/sxg/sxg-validity-period-too-long-cert-on-alt-origin.sxg?navigation';
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithZeroSuccessFractionPolicy(); await loadResourceWithZeroSuccessFractionPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + '/signed-exchange/resources/sxg/sxg-cert-not-found.sxg?navigation'; alt_origin + '/signed-exchange/resources/sxg/sxg-cert-not-found.sxg?navigation';
const cert_url = test_origin + '/signed-exchange/resources/not_found_certfile.cbor'; const cert_url = test_origin + '/signed-exchange/resources/not_found_certfile.cbor';
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg/sxg-invalid-integrity-header.sxg?navigation'; '/signed-exchange/resources/sxg/sxg-invalid-integrity-header.sxg?navigation';
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg/sxg-merkle-integrity-error.sxg?navigation'; '/signed-exchange/resources/sxg/sxg-merkle-integrity-error.sxg?navigation';
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = alt_origin + '/signed-exchange/resources/sxg/sxg-location.sxg?navigation'; const sxg_url = alt_origin + '/signed-exchange/resources/sxg/sxg-location.sxg?navigation';
const cert_url = test_origin + '/signed-exchange/resources/127.0.0.1.sxg.pem.cbor'; const cert_url = test_origin + '/signed-exchange/resources/127.0.0.1.sxg.pem.cbor';
const message = await openSXGInIframeAndWaitForMessage(t, sxg_url, 'no-referrer'); const message = await openSXGInIframeAndWaitForMessage(t, sxg_url, 'no-referrer');
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = alt_origin + '/signed-exchange/resources/sxg/sxg-location.sxg?navigation'; const sxg_url = alt_origin + '/signed-exchange/resources/sxg/sxg-location.sxg?navigation';
const cert_url = test_origin + '/signed-exchange/resources/127.0.0.1.sxg.pem.cbor'; const cert_url = test_origin + '/signed-exchange/resources/127.0.0.1.sxg.pem.cbor';
const message = await openSXGInIframeAndWaitForMessage(t, sxg_url, 'origin'); const message = await openSXGInIframeAndWaitForMessage(t, sxg_url, 'origin');
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = alt_origin + '/signed-exchange/resources/sxg/sxg-location.sxg?navigation'; const sxg_url = alt_origin + '/signed-exchange/resources/sxg/sxg-location.sxg?navigation';
const cert_url = test_origin + '/signed-exchange/resources/127.0.0.1.sxg.pem.cbor'; const cert_url = test_origin + '/signed-exchange/resources/127.0.0.1.sxg.pem.cbor';
const message = await openSXGInIframeAndWaitForMessage(t, sxg_url); const message = await openSXGInIframeAndWaitForMessage(t, sxg_url);
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
<script> <script>
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg/sxg-invalid-format.sxg?navigation'; '/signed-exchange/resources/sxg/sxg-invalid-format.sxg?navigation';
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg/sxg-invalid-cert-sha256.sxg?navigation'; '/signed-exchange/resources/sxg/sxg-invalid-cert-sha256.sxg?navigation';
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<script> <script>
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
nel_test(async t => { nel_iframe_test(async t => {
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const sxg_url = const sxg_url =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg/sxg-invalid-cert-sha256-cert-on-alt-origin.sxg?navigation'; '/signed-exchange/resources/sxg/sxg-invalid-cert-sha256-cert-on-alt-origin.sxg?navigation';
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
<script src="../resources/sxg-util.js"></script> <script src="../resources/sxg-util.js"></script>
<body> <body>
<script> <script>
nel_test(async t => { nel_iframe_test(async t => {
const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN; const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
const test_origin = get_host_info().HTTPS_ORIGIN; const test_origin = get_host_info().HTTPS_ORIGIN;
await fetchResourceWithBasicPolicy(); await loadResourceWithBasicPolicyInIframe();
const iframe_path = const iframe_path =
alt_origin + alt_origin +
'/signed-exchange/resources/sxg-subresource-mismatch-iframe.html'; '/signed-exchange/resources/sxg-subresource-mismatch-iframe.html';
......
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