Bug 1527961 [wpt PR 15372] - Implement Signed Exchange reporting for distributors, a=testonly
authorTsuyoshi Horo <horo@chromium.org>
Wed, 06 Mar 2019 12:33:36 +0000
changeset 464642 5f4503098f27
parent 464641 5fcf15c3c730
child 464643 135e1b3fbd10
push id35717
push useraciure@mozilla.com
push dateSun, 17 Mar 2019 09:45:26 +0000
treeherdermozilla-central@e0861be8d6c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1527961, 15372, 910516, 1468855, 634161
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1527961 [wpt PR 15372] - Implement Signed Exchange reporting for distributors, a=testonly Automatic update from web-platform-tests Implement Signed Exchange reporting for distributors This CL implements Signed Exchange reporting for distributors. Spec: https://github.com/WICG/webpackage/pull/374 This CL has two success test cases only. I will add more failure test cases in another CL. Bug: 910516 Change-Id: I31a6e629073970e03a93d2379be1ae63ef6adf6b Reviewed-on: https://chromium-review.googlesource.com/c/1468855 Commit-Queue: Tsuyoshi Horo <horo@chromium.org> Reviewed-by: Christian Dullweber <dullweber@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Kunihiko Sakamoto <ksakamoto@chromium.org> Reviewed-by: Eric Orth <ericorth@chromium.org> Cr-Commit-Position: refs/heads/master@{#634161} -- wpt-commits: 66dbfd0ae579135db73772c534879c51f6dbc674 wpt-pr: 15372
testing/web-platform/tests/network-error-logging/support/nel.sub.js
testing/web-platform/tests/network-error-logging/support/report.py
testing/web-platform/tests/signed-exchange/reporting/sxg-reporting-navigation-ok.tentative.html
testing/web-platform/tests/signed-exchange/reporting/sxg-reporting-prefetch-ok.tentative.html
testing/web-platform/tests/signed-exchange/resources/sxg-util.js
--- a/testing/web-platform/tests/network-error-logging/support/nel.sub.js
+++ b/testing/web-platform/tests/network-error-logging/support/nel.sub.js
@@ -202,8 +202,33 @@ async function reportExists(expected) {
   const json = await response.json();
   for (const report of json) {
     if (_isSubsetOf(expected, report)) {
       return true;
     }
   }
   return false;
 }
+
+/*
+ * Verifies that reports were uploaded that contains all of the fields in
+ * expected.
+ */
+
+async function reportsExist(expected_reports) {
+  const timeout = 10;
+  let reportLocation =
+    "/network-error-logging/support/report.py?op=retrieve_report&timeout=" +
+    timeout + "&reportID=" + reportID;
+  // There must be the report of pass.png, so adding 1.
+  const min_count = expected_reports.length + 1;
+  reportLocation += "&min_count=" + min_count;
+  const response = await fetch(reportLocation);
+  const json = await response.json();
+  for (const expected of expected_reports) {
+    const found = json.some((report) => {
+      return _isSubsetOf(expected, report);
+    });
+    if (!found)
+      return false;
+  }
+  return true;
+}
--- a/testing/web-platform/tests/network-error-logging/support/report.py
+++ b/testing/web-platform/tests/network-error-logging/support/report.py
@@ -1,18 +1,18 @@
 import time
 import json
 import re
 
-def retrieve_from_stash(request, key, timeout, default_value):
+def retrieve_from_stash(request, key, timeout, min_count, default_value):
   t0 = time.time()
   while time.time() - t0 < timeout:
     time.sleep(0.5)
     value = request.server.stash.take(key=key)
-    if value is not None:
+    if value is not None and len(value) >= min_count:
       request.server.stash.put(key=key, value=value)
       return json.dumps(value)
 
   return default_value
 
 def main(request, response):
   # Handle CORS preflight requests
   if request.method == 'OPTIONS':
@@ -29,17 +29,21 @@ def main(request, response):
   op = request.GET.first("op");
   key = request.GET.first("reportID")
 
   if op == "retrieve_report":
     try:
       timeout = float(request.GET.first("timeout"))
     except:
       timeout = 0.5
-    return [("Content-Type", "application/json")], retrieve_from_stash(request, key, timeout, '[]')
+    try:
+      min_count = int(request.GET.first("min_count"))
+    except:
+      min_count = 1
+    return [("Content-Type", "application/json")], retrieve_from_stash(request, key, timeout, min_count, '[]')
 
   # append new reports
   new_reports = json.loads(request.body)
   for report in new_reports:
     report["metadata"] = {
       "content_type": request.headers["Content-Type"],
     }
   with request.server.stash.lock:
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/signed-exchange/reporting/sxg-reporting-navigation-ok.tentative.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<title>SXG reporting test of ok for navigation</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="/network-error-logging/support/nel.sub.js"></script>
+<script src="../resources/sxg-util.js"></script>
+<body>
+<script>
+const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
+const test_origin = get_host_info().HTTPS_ORIGIN;
+
+nel_test(async t => {
+  await fetchResourceWithBasicPolicy();
+  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 message = await openSXGInIframeAndWaitForMessage(t, sxg_url);
+  assert_equals(message.location,
+                innerURLOrigin() + '/signed-exchange/resources/inner-url.html');
+  assert_false(message.is_fallback);
+  assert_true(await reportsExist([
+    {
+      url: sxg_url,
+      user_agent: navigator.userAgent,
+      type: "network-error",
+      body: {
+        phase: "sxg",
+        type: "ok",
+        status_code: 200,
+        referrer: location.href,
+        sxg: {
+          outer_url: sxg_url,
+          inner_url:
+              innerURLOrigin() + '/signed-exchange/resources/inner-url.html',
+          cert_url: [cert_url]
+        }
+      },
+      metadata: {
+        content_type: "application/reports+json",
+      },
+    },
+    {
+      url: sxg_url,
+      user_agent: navigator.userAgent,
+      type: "network-error",
+      body: {
+        phase: "application",
+        type: "ok",
+        status_code: 200,
+        referrer: location.href,
+      },
+      metadata: {
+        content_type: "application/reports+json",
+      },
+    },
+  ]));
+}, 'SXG success report must be sent for navigation.');
+</script>
+</body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/signed-exchange/reporting/sxg-reporting-prefetch-ok.tentative.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<title>SXG reporting test of ok for prefetch</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="/network-error-logging/support/nel.sub.js"></script>
+<script src="../resources/sxg-util.js"></script>
+<body>
+<script>
+const alt_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
+const test_origin = get_host_info().HTTPS_ORIGIN;
+
+nel_test(async t => {
+  await fetchResourceWithBasicPolicy();
+  const sxg_url = alt_origin + '/signed-exchange/resources/sxg/sxg-location.sxg?prefetch';
+  const cert_url = test_origin + '/signed-exchange/resources/127.0.0.1.sxg.pem.cbor';
+  addPrefetch(sxg_url);
+  assert_true(await reportsExist([
+    {
+      url: sxg_url,
+      user_agent: navigator.userAgent,
+      type: "network-error",
+      body: {
+        phase: "sxg",
+        type: "ok",
+        status_code: 200,
+        referrer: location.href,
+        sxg: {
+          outer_url: sxg_url,
+          inner_url:
+              innerURLOrigin() + '/signed-exchange/resources/inner-url.html',
+          cert_url: [cert_url]
+        }
+      },
+      metadata: {
+        content_type: "application/reports+json",
+      },
+    },
+    {
+      url: sxg_url,
+      user_agent: navigator.userAgent,
+      type: "network-error",
+      body: {
+        phase: "application",
+        type: "ok",
+        status_code: 200,
+        referrer: location.href,
+      },
+      metadata: {
+        content_type: "application/reports+json",
+      },
+    },
+  ]));
+}, 'SXG success report must be sent for prefetching.');
+</script>
+</body>
--- a/testing/web-platform/tests/signed-exchange/resources/sxg-util.js
+++ b/testing/web-platform/tests/signed-exchange/resources/sxg-util.js
@@ -60,8 +60,15 @@ function runReferrerTests(test_cases) {
       const fallbackMessage =
           await openSXGInIframeAndWaitForMessage(
                 t, invalidSxgUrl, test_case.referrerPolicy);
       assert_true(fallbackMessage.is_fallback);
       assert_equals(fallbackMessage.referrer, test_case.expectedReferrer);
     }, 'Referrer of SignedHTTPExchange test : ' + JSON.stringify(test_case));
   }
 }
+
+function addPrefetch(url) {
+  const link = document.createElement('link');
+  link.rel = 'prefetch';
+  link.href = url;
+  document.body.appendChild(link);
+}