tor-browser

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

test_pkcs11_moduleDB.js (1459B)


      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 adding modules with invalid names are prevented.
      7 
      8 // Ensure that the appropriate initialization has happened.
      9 do_get_profile();
     10 
     11 function run_test() {
     12  let libraryFile = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
     13  libraryFile.append("pkcs11testmodule");
     14  libraryFile.append(ctypes.libraryName("pkcs11testmodule"));
     15  ok(libraryFile.exists(), "The pkcs11testmodule file should exist");
     16 
     17  let moduleDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].getService(
     18    Ci.nsIPKCS11ModuleDB
     19  );
     20  throws(
     21    () => moduleDB.addModule("Root Certs", libraryFile.path, 0, 0),
     22    /NS_ERROR_ILLEGAL_VALUE/,
     23    "Adding a module named 'Root Certs' should fail."
     24  );
     25  throws(
     26    () => moduleDB.addModule("", libraryFile.path, 0, 0),
     27    /NS_ERROR_ILLEGAL_VALUE/,
     28    "Adding a module with an empty name should fail."
     29  );
     30 
     31  let bundle = Services.strings.createBundle(
     32    "chrome://pipnss/locale/pipnss.properties"
     33  );
     34  let rootsModuleName = bundle.GetStringFromName("RootCertModuleName");
     35  let foundRootsModule = false;
     36  for (let module of moduleDB.listModules()) {
     37    if (module.name == rootsModuleName) {
     38      foundRootsModule = true;
     39      break;
     40    }
     41  }
     42  ok(
     43    foundRootsModule,
     44    "Should be able to find builtin roots module by localized name."
     45  );
     46 }