Bug 1342178 - Combine test_network_security-{hsts/hpkp}.html. r=keeler,honza draft
authorJonathan Hao <jhao@mozilla.com>
Wed, 05 Apr 2017 15:17:02 +0800
changeset 556015 5b93e347f7bd74bc786f5e6e05666c50fc5783b7
parent 499512 ff04d410e74b69acfab17ef7e73e7397602d5a68
child 556016 62b82478e245c0d23a0e8df740e628d9cfa9483b
push id52406
push userbmo:jhao@mozilla.com
push dateWed, 05 Apr 2017 08:09:51 +0000
reviewerskeeler, honza
bugs1342178
milestone55.0a1
Bug 1342178 - Combine test_network_security-{hsts/hpkp}.html. r=keeler,honza MozReview-Commit-ID: 3xXdOa1j7hm
devtools/shared/webconsole/test/test_network_security-hpkp.html
--- a/devtools/shared/webconsole/test/test_network_security-hpkp.html
+++ b/devtools/shared/webconsole/test/test_network_security-hpkp.html
@@ -17,29 +17,45 @@
 SimpleTest.waitForExplicitFinish();
 
 let gCurrentTestCase = -1;
 const HPKP_PREF = "security.cert_pinning.process_headers_from_non_builtin_roots";
 
 // Static pins tested by unit/test_security-info-static-hpkp.js.
 const TEST_CASES = [
   {
-    desc: "no Public Key Pinning",
+    desc: "no HSTS",
     url: "https://example.com",
+    usesHSTS: false,
+    usesPinning: false,
+  },
+  {
+    desc: "HSTS from this response",
+    url: "https://example.com/"+
+         "browser/browser/base/content/test/general/browser_star_hsts.sjs",
+    usesHSTS: true,
+    usesPinning: false,
+  },
+  {
+    desc: "stored HSTS from previous response, no Public Key Pinning",
+    url: "https://example.com/",
+    usesHSTS: true,
     usesPinning: false,
   },
   {
     desc: "dynamic Public Key Pinning with this request",
     url: "https://include-subdomains.pinning-dynamic.example.com/" +
          "browser/browser/base/content/test/general/pinning_headers.sjs",
+    usesHSTS: false,
     usesPinning: true,
   },
   {
     desc: "dynamic Public Key Pinning with previous request",
     url: "https://include-subdomains.pinning-dynamic.example.com/",
+    usesHSTS: false,
     usesPinning: true,
   }
 ];
 
 function startTest() {
   // Need to enable this pref or pinning headers are rejected due test
   // certificate.
   Services.prefs.setBoolPref(HPKP_PREF, true);
@@ -49,21 +65,23 @@ function startTest() {
     // Reset pinning state.
     let gSSService = Cc["@mozilla.org/ssservice;1"]
                        .getService(Ci.nsISiteSecurityService);
 
     let gIOService = Cc["@mozilla.org/network/io-service;1"]
                        .getService(Ci.nsIIOService);
     for (let {url} of TEST_CASES) {
       let uri = gIOService.newURI(url);
+      gSSService.removeState(Ci.nsISiteSecurityService.HEADER_HSTS, uri, 0);
       gSSService.removeState(Ci.nsISiteSecurityService.HEADER_HPKP, uri, 0);
     }
   });
 
-  info("Test detection of Public Key Pinning.");
+  info("Test detection of HTTP Strict Transport Security" +
+       " and Public Key Pinning.");
   removeEventListener("load", startTest);
   attachConsoleToTab(["NetworkActivity"], onAttach);
 }
 
 function onAttach(state, response) {
   onNetworkEventUpdate = onNetworkEventUpdate.bind(null, state);
   state.dbgClient.addListener("networkEventUpdate", onNetworkEventUpdate);
 
@@ -83,16 +101,18 @@ function runNextCase(state) {
 
   let iframe = document.querySelector("iframe").contentWindow;
   iframe.wrappedJSObject.makeXhrCallback("GET", url);
 }
 
 function onNetworkEventUpdate(state, type, packet) {
   function onSecurityInfo(received) {
     let data = TEST_CASES[gCurrentTestCase];
+    is(received.securityInfo.hsts, data.usesHSTS,
+      "Strict Transport Security detected correctly.");
     is(received.securityInfo.hpkp, data.usesPinning,
       "Public Key Pinning detected correctly.");
 
     runNextCase(state);
   }
 
   if (packet.updateType === "securityInfo") {
     state.client.getSecurityInfo(packet.from, onSecurityInfo);