tor-browser

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

test_nonascii_path.js (1693B)


      1 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
      2 // This Source Code Form is subject to the terms of the Mozilla Public
      3 // License, v. 2.0. If a copy of the MPL was not distributed with this
      4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
      5 
      6 "use strict";
      7 
      8 // Tests to make sure that the certificate DB works with non-ASCII paths.
      9 
     10 // Append a single quote and non-ASCII characters to the profile path.
     11 let profd = Services.env.get("XPCSHELL_TEST_PROFILE_DIR");
     12 let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
     13 file.initWithPath(profd);
     14 file.append("'รท1");
     15 Services.env.set("XPCSHELL_TEST_PROFILE_DIR", file.path);
     16 
     17 file = do_get_profile(); // must be called before getting nsIX509CertDB
     18 Assert.ok(
     19  /[^\x20-\x7f]/.test(file.path),
     20  "the profile path should contain a non-ASCII character"
     21 );
     22 
     23 // Restore the original value.
     24 Services.env.set("XPCSHELL_TEST_PROFILE_DIR", profd);
     25 
     26 const certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
     27  Ci.nsIX509CertDB
     28 );
     29 
     30 function load_cert(cert_name, trust_string) {
     31  let cert_filename = cert_name + ".pem";
     32  return addCertFromFile(
     33    certdb,
     34    "test_cert_trust/" + cert_filename,
     35    trust_string
     36  );
     37 }
     38 
     39 function run_test() {
     40  let certList = ["ca", "int", "ee"];
     41  let loadedCerts = [];
     42  for (let certName of certList) {
     43    loadedCerts.push(load_cert(certName, ",,"));
     44  }
     45 
     46  let ca_cert = loadedCerts[0];
     47  notEqual(ca_cert, null, "CA cert should have successfully loaded");
     48  let int_cert = loadedCerts[1];
     49  notEqual(int_cert, null, "Intermediate cert should have successfully loaded");
     50  let ee_cert = loadedCerts[2];
     51  notEqual(ee_cert, null, "EE cert should have successfully loaded");
     52 }