test_security-info-static-hpkp.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Test that NetworkHelper.parseSecurityInfo correctly detects static hpkp pins
  5. const { require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {});
  6. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  7. const Services = require("Services");
  8. Object.defineProperty(this, "NetworkHelper", {
  9. get: function () {
  10. return require("devtools/shared/webconsole/network-helper");
  11. },
  12. configurable: true,
  13. writeable: false,
  14. enumerable: true
  15. });
  16. var Ci = Components.interfaces;
  17. const wpl = Ci.nsIWebProgressListener;
  18. const MockSecurityInfo = {
  19. QueryInterface: XPCOMUtils.generateQI([Ci.nsITransportSecurityInfo,
  20. Ci.nsISSLStatusProvider]),
  21. securityState: wpl.STATE_IS_SECURE,
  22. errorCode: 0,
  23. SSLStatus: {
  24. cipherSuite: "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256",
  25. protocolVersion: 3, // TLS_VERSION_1_2
  26. serverCert: {
  27. validity: {}
  28. },
  29. }
  30. };
  31. const MockHttpInfo = {
  32. hostname: "include-subdomains.pinning.example.com",
  33. private: false,
  34. };
  35. function run_test() {
  36. Services.prefs.setIntPref("security.cert_pinning.enforcement_level", 1);
  37. let result = NetworkHelper.parseSecurityInfo(MockSecurityInfo, MockHttpInfo);
  38. equal(result.hpkp, true, "Static HPKP detected.");
  39. }