tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_osclientcerts_module.js (2189B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 // Any copyright is dedicated to the Public Domain.
      3 // http://creativecommons.org/publicdomain/zero/1.0/
      4 "use strict";
      5 
      6 // Tests that the platform can load the osclientcerts module.
      7 
      8 // Ensure that the appropriate initialization has happened.
      9 Services.prefs.setBoolPref("security.osclientcerts.autoload", false);
     10 do_get_profile();
     11 
     12 const { TestUtils } = ChromeUtils.importESModule(
     13  "resource://testing-common/TestUtils.sys.mjs"
     14 );
     15 
     16 async function check_osclientcerts_module_loaded() {
     17  // Loading happens asynchronously, so we have to wait for the notification.
     18  await TestUtils.topicObserved("psm:load-os-client-certs-module-task-ran");
     19  let testModule = checkPKCS11ModuleExists("OS Client Cert Module");
     20 
     21  // Check that listing the slots for the osclientcerts module works.
     22  let testModuleSlotNames = Array.from(
     23    testModule.listSlots(),
     24    slot => slot.name
     25  );
     26  testModuleSlotNames.sort();
     27  const expectedSlotNames = ["OS Client Cert Slot"];
     28  deepEqual(
     29    testModuleSlotNames,
     30    expectedSlotNames,
     31    "Actual and expected slot names should be equal"
     32  );
     33 }
     34 
     35 add_task(async function run_test() {
     36  // Check that if we haven't loaded the osclientcerts module, we don't find it
     37  // in the module list.
     38  checkPKCS11ModuleNotPresent("OS Client Cert Module");
     39 
     40  // Check that enabling the pref that loads the osclientcerts module makes it
     41  // appear in the module list.
     42  Services.prefs.setBoolPref("security.osclientcerts.autoload", true);
     43  await check_osclientcerts_module_loaded();
     44 
     45  // Check that disabling the pref that loads the osclientcerts module (thus
     46  // unloading the module) makes it disappear from the module list.
     47  Services.prefs.setBoolPref("security.osclientcerts.autoload", false);
     48  checkPKCS11ModuleNotPresent("OS Client Cert Module");
     49 
     50  // Check that loading the module again succeeds.
     51  Services.prefs.setBoolPref("security.osclientcerts.autoload", true);
     52  await check_osclientcerts_module_loaded();
     53 
     54  // And once more check that unloading succeeds.
     55  Services.prefs.setBoolPref("security.osclientcerts.autoload", false);
     56  checkPKCS11ModuleNotPresent("OS Client Cert Module");
     57 });