Bug 932179 - Part 4: Test static pinning with an unit test instead as the test domain is no longer available for mochitests (bug 1096197). r=past
authorSami Jaktholm <sjakthol@outlook.com>
Sat, 10 Jan 2015 22:47:00 +0200
changeset 239999 b7cb3b5da58d6966d852f4f0d978933816377d6c
parent 239998 14d1166ae92bc795a6f4a6aec2a493beeda1f094
child 240000 4e343b8494f90f68b4cf7102d8abe001c788f81a
push id7472
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 20:36:27 +0000
treeherdermozilla-aurora@300ca104f8fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs932179, 1096197
milestone37.0a1
Bug 932179 - Part 4: Test static pinning with an unit test instead as the test domain is no longer available for mochitests (bug 1096197). r=past
toolkit/devtools/webconsole/test/test_network_security-hpkp.html
toolkit/devtools/webconsole/test/unit/test_security-info-static-hpkp.js
toolkit/devtools/webconsole/test/unit/xpcshell.ini
--- a/toolkit/devtools/webconsole/test/test_network_security-hpkp.html
+++ b/toolkit/devtools/webconsole/test/test_network_security-hpkp.html
@@ -13,28 +13,25 @@
 
 <iframe src="https://example.com/chrome/toolkit/devtools/webconsole/test/network_requests_iframe.html"></iframe>
 
 <script class="testbody" type="text/javascript;version=1.8">
 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",
     url: "https://example.com",
     usesPinning: false,
   },
   {
-    desc: "static Public Key Pinning",
-    url: "https://include-subdomains.pinning.example.com/",
-    usesPinning: true,
-  },
-  {
     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",
     usesPinning: true,
   },
   {
     desc: "dynamic Public Key Pinning with previous request",
     url: "https://include-subdomains.pinning-dynamic.example.com/",
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/webconsole/test/unit/test_security-info-static-hpkp.js
@@ -0,0 +1,47 @@
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+// Test that NetworkHelper.parseSecurityInfo correctly detects static hpkp pins
+
+const { devtools } = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {});
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+Object.defineProperty(this, "NetworkHelper", {
+  get: function() {
+    return devtools.require("devtools/toolkit/webconsole/network-helper");
+  },
+  configurable: true,
+  writeable: false,
+  enumerable: true
+});
+
+const Ci = Components.interfaces;
+const wpl = Ci.nsIWebProgressListener;
+
+const MockSecurityInfo = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsITransportSecurityInfo,
+                                         Ci.nsISSLStatusProvider]),
+  securityState: wpl.STATE_IS_SECURE,
+  errorCode: 0,
+  SSLStatus: {
+    cipherSuite: "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256",
+    protocolVersion: 3, // TLS_VERSION_1_2
+    serverCert: {
+      validity: {}
+    },
+  }
+};
+
+const MockRequest = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIPrivateBrowsingChannel]),
+  URI: {
+    host: "include-subdomains.pinning.example.com"
+  }
+};
+
+function run_test() {
+  let result = NetworkHelper.parseSecurityInfo(MockSecurityInfo, MockRequest);
+  equal(result.hpkp, true, "Static HPKP detected.");
+}
--- a/toolkit/devtools/webconsole/test/unit/xpcshell.ini
+++ b/toolkit/devtools/webconsole/test/unit/xpcshell.ini
@@ -5,8 +5,9 @@ skip-if = toolkit == 'android' || toolki
 support-files =
 
 [test_js_property_provider.js]
 [test_network_helper.js]
 [test_security-info-certificate.js]
 [test_security-info-parser.js]
 [test_security-info-protocol-version.js]
 [test_security-info-state.js]
+[test_security-info-static-hpkp.js]