Skip to content

Commit

Permalink
Bug 1541508 - Use Services.env in security/ r=keeler
Browse files Browse the repository at this point in the history
  • Loading branch information
Barret Rennie committed Nov 25, 2022
1 parent a616981 commit fd3a3d1
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 44 deletions.
18 changes: 6 additions & 12 deletions security/manager/ssl/tests/unit/head_psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,16 +686,13 @@ async function asyncStartTLSTestServer(

const CALLBACK_PORT = 8444;

let envSvc = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let greBinDir = Services.dirsvc.get("GreBinD", Ci.nsIFile);
envSvc.set("DYLD_LIBRARY_PATH", greBinDir.path);
Services.env.set("DYLD_LIBRARY_PATH", greBinDir.path);
// TODO(bug 1107794): Android libraries are in /data/local/xpcb, but "GreBinD"
// does not return this path on Android, so hard code it here.
envSvc.set("LD_LIBRARY_PATH", greBinDir.path + ":/data/local/xpcb");
envSvc.set("MOZ_TLS_SERVER_DEBUG_LEVEL", "3");
envSvc.set("MOZ_TLS_SERVER_CALLBACK_PORT", CALLBACK_PORT);
Services.env.set("LD_LIBRARY_PATH", greBinDir.path + ":/data/local/xpcb");
Services.env.set("MOZ_TLS_SERVER_DEBUG_LEVEL", "3");
Services.env.set("MOZ_TLS_SERVER_CALLBACK_PORT", CALLBACK_PORT);

let httpServer = new HttpServer();
let serverReady = new Promise(resolve => {
Expand Down Expand Up @@ -1173,14 +1170,11 @@ function getSubjectAndSPKIHash(nsCert) {
}

function run_certutil_on_directory(directory, args, expectSuccess = true) {
let envSvc = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let greBinDir = Services.dirsvc.get("GreBinD", Ci.nsIFile);
envSvc.set("DYLD_LIBRARY_PATH", greBinDir.path);
Services.env.set("DYLD_LIBRARY_PATH", greBinDir.path);
// TODO(bug 1107794): Android libraries are in /data/local/xpcb, but "GreBinD"
// does not return this path on Android, so hard code it here.
envSvc.set("LD_LIBRARY_PATH", greBinDir.path + ":/data/local/xpcb");
Services.env.set("LD_LIBRARY_PATH", greBinDir.path + ":/data/local/xpcb");
let certutilBin = _getBinaryUtil("certutil");
let process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(certutilBin);
Expand Down
7 changes: 2 additions & 5 deletions security/manager/ssl/tests/unit/test_broken_fips.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@

function run_test() {
// Append a single quote and non-ASCII characters to the profile path.
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let profd = env.get("XPCSHELL_TEST_PROFILE_DIR");
let profd = Services.env.get("XPCSHELL_TEST_PROFILE_DIR");
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
file.initWithPath(profd);
file.append("'÷1");
env.set("XPCSHELL_TEST_PROFILE_DIR", file.path);
Services.env.set("XPCSHELL_TEST_PROFILE_DIR", file.path);

let profile = do_get_profile(); // must be called before getting nsIX509CertDB
Assert.ok(
Expand Down
9 changes: 3 additions & 6 deletions security/manager/ssl/tests/unit/test_nonascii_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
// Tests to make sure that the certificate DB works with non-ASCII paths.

// Append a single quote and non-ASCII characters to the profile path.
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let profd = env.get("XPCSHELL_TEST_PROFILE_DIR");
let profd = Services.env.get("XPCSHELL_TEST_PROFILE_DIR");
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
file.initWithPath(profd);
file.append("'÷1");
env.set("XPCSHELL_TEST_PROFILE_DIR", file.path);
Services.env.set("XPCSHELL_TEST_PROFILE_DIR", file.path);

file = do_get_profile(); // must be called before getting nsIX509CertDB
Assert.ok(
Expand All @@ -24,7 +21,7 @@ Assert.ok(
);

// Restore the original value.
env.set("XPCSHELL_TEST_PROFILE_DIR", profd);
Services.env.set("XPCSHELL_TEST_PROFILE_DIR", profd);

const certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
Ci.nsIX509CertDB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ function run_test() {
});

// Append a single quote and non-ASCII characters to the profile path.
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let profd = env.get("XPCSHELL_TEST_PROFILE_DIR");
let profd = Services.env.get("XPCSHELL_TEST_PROFILE_DIR");
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
file.initWithPath(profd);
file.append("'÷1");
env.set("XPCSHELL_TEST_PROFILE_DIR", file.path);
Services.env.set("XPCSHELL_TEST_PROFILE_DIR", file.path);

let profile = do_get_profile(); // must be called before getting nsIX509CertDB
Assert.ok(
Expand Down
4 changes: 0 additions & 4 deletions security/sandbox/test/browser_bug1393259.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
const kPageURL =
"http://example.com/browser/security/sandbox/test/bug1393259.html";

const environment = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);

// Parameters for running the python script that registers/unregisters fonts.
const kPythonPath = "/usr/bin/python";
const kFontInstallerPath = "browser/security/sandbox/test/mac_register_font.py";
Expand Down
2 changes: 1 addition & 1 deletion security/sandbox/test/browser_content_sandbox_fs_snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Services.scriptloader.loadSubScript(

add_task(async function() {
// Ensure that SNAP is there
const snap = GetEnvironmentVariable("SNAP");
const snap = Services.env.get("SNAP");
ok(snap.length > 1, "SNAP is defined");

// If it is there, do actual testing
Expand Down
4 changes: 2 additions & 2 deletions security/sandbox/test/browser_content_sandbox_fs_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ async function testFileAccessLinuxOnly() {
// allows to handle both $HOME/.config/ or $XDG_CONFIG_HOME
let configDir = GetHomeSubdir(".config");

const xdgConfigHome = GetEnvironmentVariable("XDG_CONFIG_HOME");
const xdgConfigHome = Services.env.get("XDG_CONFIG_HOME");

if (xdgConfigHome.length > 1) {
configDir = GetDir(xdgConfigHome);
Expand Down Expand Up @@ -633,7 +633,7 @@ async function testFileAccessLinuxSnap() {

// Assert that if we run with SNAP= env, then we allow access to it in the
// content process
let snap = GetEnvironmentVariable("SNAP");
let snap = Services.env.get("SNAP");
let snapExpectedResult = false;
if (snap.length > 1) {
snapExpectedResult = true;
Expand Down
2 changes: 1 addition & 1 deletion security/sandbox/test/browser_content_sandbox_fs_xdg.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Services.scriptloader.loadSubScript(

add_task(async function() {
// Ensure that XDG_CONFIG_HOME is there
const xdgConfigHome = GetEnvironmentVariable("XDG_CONFIG_HOME");
const xdgConfigHome = Services.env.get("XDG_CONFIG_HOME");
ok(xdgConfigHome.length > 1, "XDG_CONFIG_HOME is defined");

// If it is there, do actual testing
Expand Down
9 changes: 1 addition & 8 deletions security/sandbox/test/browser_content_sandbox_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"use strict";

const uuidGenerator = Services.uuid;
const environment = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);

/*
* Utility functions for the browser content sandbox tests.
Expand Down Expand Up @@ -307,7 +304,7 @@ function GetDir(path) {
}

function GetDirFromEnvVariable(varName) {
return GetDir(environment.get(varName));
return GetDir(Services.env.get(varName));
}

function GetFile(path) {
Expand All @@ -316,10 +313,6 @@ function GetFile(path) {
return file;
}

function GetEnvironmentVariable(varName) {
return environment.get(varName);
}

function GetBrowserType(type) {
let browserType = undefined;

Expand Down

0 comments on commit fd3a3d1

Please sign in to comment.