Bug 1393439 - P4: Modify wpt test to verify only the opaque response with the empty string will pass the SRI check. r?bkelly draft
authorTom Tung <shes050117@gmail.com>
Tue, 29 Aug 2017 18:48:23 +0800
changeset 657114 13310367ca283ab780ffe315c34969505454f816
parent 654863 6a71b48f72e53504ede46b9a3b6383ba3b9a7fef
child 729356 2f671ad7d9aa3ac56bf2580ad8fc1253e75789f4
push id77447
push userttung@mozilla.com
push dateFri, 01 Sep 2017 03:53:01 +0000
reviewersbkelly
bugs1393439
milestone57.0a1
Bug 1393439 - P4: Modify wpt test to verify only the opaque response with the empty string will pass the SRI check. r?bkelly MozReview-Commit-ID: 34zwNXQ3a9G
testing/web-platform/tests/fetch/api/basic/integrity.js
--- a/testing/web-platform/tests/fetch/api/basic/integrity.js
+++ b/testing/web-platform/tests/fetch/api/basic/integrity.js
@@ -1,45 +1,80 @@
 if (this.document === undefined) {
   importScripts("/resources/testharness.js");
   importScripts("../resources/utils.js");
 }
 
-function integrity(desc, url, integrity, shouldPass) {
-   if (shouldPass) {
+function integrity(desc, url, integrity, initRequestMode, shouldPass) {
+  var fetchRequestInit = {'integrity': integrity}
+  if (!!initRequestMode && initRequestMode !== "") {
+    fetchRequestInit.mode = initRequestMode;
+  }
+  var fetchPromise = fetch(url, fetchRequestInit);
+
+  if (shouldPass) {
     promise_test(function(test) {
-      return fetch(url, {'integrity': integrity}).then(function(resp) {
-        assert_equals(resp.status, 200, "Response's status is 200");
+      return fetchPromise.then(function(resp) {
+        if (initRequestMode !== "no-cors") {
+          assert_equals(resp.status, 200, "Response's status is 200");
+        } else {
+          assert_equals(resp.status, 0, "Opaque response's status is 0");
+          assert_equals(resp.type, "opaque");
+        }
       });
     }, desc);
   } else {
     promise_test(function(test) {
-      return promise_rejects(test, new TypeError(), fetch(url, {'integrity': integrity}));
+      return promise_rejects(test, new TypeError(), fetchPromise);
     }, desc);
   }
 }
 
 var topSha256 = "sha256-KHIDZcXnR2oBHk9DrAA+5fFiR6JjudYjqoXtMR1zvzk=";
 var topSha384 = "sha384-MgZYnnAzPM/MjhqfOIMfQK5qcFvGZsGLzx4Phd7/A8fHTqqLqXqKo8cNzY3xEPTL";
 var topSha512 = "sha512-D6yns0qxG0E7+TwkevZ4Jt5t7Iy3ugmAajG/dlf6Pado1JqTyneKXICDiqFIkLMRExgtvg8PlxbKTkYfRejSOg==";
 var invalidSha256 = "sha256-dKUcPOn/AlUjWIwcHeHNqYXPlvyGiq+2dWOdFcE+24I=";
 var invalidSha512 = "sha512-oUceBRNxPxnY60g/VtPCj2syT4wo4EZh2CgYdWy9veW8+OsReTXoh7dizMGZafvx9+QhMS39L/gIkxnPIn41Zg==";
 
 var url = "../resources/top.txt";
 var corsUrl = "http://{{host}}:{{ports[http][1]}}" + dirname(location.pathname) + RESOURCES_DIR + "top.txt";
 /* Enable CORS*/
 corsUrl += "?pipe=header(Access-Control-Allow-Origin,*)";
+var corsUrl2 = "https://{{host}}:{{ports[https][0]}}/fetch/api/resource/top.txt";
 
-integrity("Empty string integrity", url, "", true);
-integrity("SHA-256 integrity", url, topSha256, true);
-integrity("SHA-384 integrity", url, topSha384, true);
-integrity("SHA-512 integrity", url, topSha512, true);
-integrity("Invalid integrity", url, invalidSha256, false);
-integrity("Multiple integrities: valid stronger than invalid", url, invalidSha256 + " " + topSha384, true);
-integrity("Multiple integrities: invalid stronger than valid", url, invalidSha512 + " " + topSha384, false);
-integrity("Multiple integrities: invalid as strong as valid", url, invalidSha512 + " " + topSha512, true);
-integrity("Multiple integrities: both are valid", url,  topSha384 + " " + topSha512, true);
-integrity("Multiple integrities: both are invalid", url, invalidSha256 + " " + invalidSha512, false);
-integrity("CORS empty integrity", corsUrl, "", true);
-integrity("CORS SHA-512 integrity", corsUrl, topSha512, true);
-integrity("CORS invalid integrity", corsUrl, invalidSha512, false);
+integrity("Empty string integrity", url, "", /* initRequestMode */ undefined,
+          /* shouldPass */ true);
+integrity("SHA-256 integrity", url, topSha256, /* initRequestMode */ undefined,
+          /* shouldPass */ true);
+integrity("SHA-384 integrity", url, topSha384, /* initRequestMode */ undefined,
+          /* shouldPass */ true);
+integrity("SHA-512 integrity", url, topSha512, /* initRequestMode */ undefined,
+          /* shouldPass */ true);
+integrity("Invalid integrity", url, invalidSha256,
+          /* initRequestMode */ undefined, /* shouldPass */  false);
+integrity("Multiple integrities: valid stronger than invalid", url,
+          invalidSha256 + " " + topSha384, /* initRequestMode */ undefined,
+          /* shouldPass */ true);
+integrity("Multiple integrities: invalid stronger than valid",
+          url, invalidSha512 + " " + topSha384, /* initRequestMode */ undefined,
+          /* shouldPass */ false);
+integrity("Multiple integrities: invalid as strong as valid", url,
+          invalidSha512 + " " + topSha512, /* initRequestMode */ undefined,
+          /* shouldPass */ true);
+integrity("Multiple integrities: both are valid", url,
+          topSha384 + " " + topSha512, /* initRequestMode */ undefined,
+          /* shouldPass */ true);
+integrity("Multiple integrities: both are invalid", url,
+          invalidSha256 + " " + invalidSha512, /* initRequestMode */ undefined,
+          /* shouldPass */ false);
+integrity("CORS empty integrity", corsUrl, "", /* initRequestMode */ undefined,
+          /* shouldPass */ true);
+integrity("CORS SHA-512 integrity", corsUrl, topSha512,
+          /* initRequestMode */ undefined, /* shouldPass */ true);
+integrity("CORS invalid integrity", corsUrl, invalidSha512,
+          /* initRequestMode */ undefined, /* shouldPass */ false);
+
+integrity("Empty string integrity for opaque response", corsUrl2, "",
+          /* initRequestMode */ "no-cors", /* shouldPass */ true);
+integrity("SHA-* integrity for opaque response", corsUrl2, topSha512,
+          /* initRequestMode */ "no-cors", /* shouldPass */ false);
 
 done();