diff --git a/browser/components/extensions/parent/ext-pkcs11.js b/browser/components/extensions/parent/ext-pkcs11.js index 334adaa2c3ed1..db6a6af7c87b0 100644 --- a/browser/components/extensions/parent/ext-pkcs11.js +++ b/browser/components/extensions/parent/ext-pkcs11.js @@ -7,7 +7,6 @@ XPCOMUtils.defineLazyModuleGetters(this, { ctypes: "resource://gre/modules/ctypes.jsm", NativeManifests: "resource://gre/modules/NativeManifests.jsm", - OS: "resource://gre/modules/osfile.jsm", }); XPCOMUtils.defineLazyServiceGetter( @@ -17,6 +16,9 @@ XPCOMUtils.defineLazyServiceGetter( "nsIPKCS11ModuleDB" ); +// eslint-disable-next-line mozilla/reject-importGlobalProperties +Cu.importGlobalProperties(["PathUtils"]); + var { DefaultMap } = ExtensionUtils; const findModuleByPath = function(path) { @@ -38,12 +40,18 @@ this.pkcs11 = class extends ExtensionAPI { ); if (hostInfo) { if (AppConstants.platform === "win") { - hostInfo.manifest.path = OS.Path.join( - OS.Path.dirname(hostInfo.path), - hostInfo.manifest.path - ); + // If the path specified in the manifest is not an abslute path, + // translate it relative to manifest's directory. + if (!PathUtils.isAbsolute(hostInfo.manifest.path)) { + hostInfo.manifest.path = PathUtils.normalize( + PathUtils.joinRelative( + PathUtils.parent(hostInfo.path), + hostInfo.manifest.path + ) + ); + } } - let manifestLib = OS.Path.basename(hostInfo.manifest.path); + let manifestLib = PathUtils.filename(hostInfo.manifest.path); if (AppConstants.platform !== "linux") { manifestLib = manifestLib.toLowerCase(manifestLib); } diff --git a/browser/components/extensions/test/xpcshell/test_ext_pkcs11_management.js b/browser/components/extensions/test/xpcshell/test_ext_pkcs11_management.js index 6463c5964870d..36f66ecebdece 100644 --- a/browser/components/extensions/test/xpcshell/test_ext_pkcs11_management.js +++ b/browser/components/extensions/test/xpcshell/test_ext_pkcs11_management.js @@ -3,28 +3,39 @@ XPCOMUtils.defineLazyModuleGetters(this, { ctypes: "resource://gre/modules/ctypes.jsm", MockRegistry: "resource://testing-common/MockRegistry.jsm", - OS: "resource://gre/modules/osfile.jsm", }); do_get_profile(); -let tmpDir = FileUtils.getDir("TmpD", ["PKCS11"]); + +let tmpDir; +let baseDir; let slug = AppConstants.platform === "linux" ? "pkcs11-modules" : "PKCS11Modules"; -tmpDir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); -let baseDir = OS.Path.join(tmpDir.path, slug); -OS.File.makeDir(baseDir); -registerCleanupFunction(() => { - tmpDir.remove(true); +add_task(async function setupTest() { + tmpDir = await IOUtils.createUniqueDirectory( + Services.dirsvc.get("TmpD", Ci.nsIFile).path, + "PKCS11" + ); + + baseDir = PathUtils.join(tmpDir, slug); + await IOUtils.makeDirectory(baseDir); }); -function getPath(filename) { - return OS.Path.join(baseDir, filename); -} +registerCleanupFunction(async () => { + await IOUtils.remove(tmpDir, { recursive: true }); +}); -const testmodule = - "../../../../../security/manager/ssl/tests/unit/pkcs11testmodule/" + - ctypes.libraryName("pkcs11testmodule"); +const testmodule = PathUtils.join( + PathUtils.parent(Services.dirsvc.get("CurWorkD", Ci.nsIFile).path, 5), + "security", + "manager", + "ssl", + "tests", + "unit", + "pkcs11testmodule", + ctypes.libraryName("pkcs11testmodule") +); // This function was inspired by the native messaging test under // toolkit/components/extensions @@ -39,8 +50,8 @@ async function setupManifests(modules) { allowed_extensions: [module.id], }; - let manifestPath = getPath(`${module.name}.json`); - await OS.File.writeAtomic(manifestPath, JSON.stringify(manifest)); + let manifestPath = PathUtils.join(baseDir, `${module.name}.json`); + await IOUtils.writeJSON(manifestPath, manifest); return manifestPath; } @@ -50,10 +61,11 @@ async function setupManifests(modules) { case "linux": let dirProvider = { getFile(property) { - if (property == "XREUserNativeManifests") { - return tmpDir.clone(); - } else if (property == "XRESysNativeManifests") { - return tmpDir.clone(); + if ( + property == "XREUserNativeManifests" || + property == "XRESysNativeManifests" + ) { + return new FileUtils.File(tmpDir); } return null; }, @@ -78,10 +90,6 @@ async function setupManifests(modules) { }); for (let module of modules) { - if (!OS.Path.winIsAbsolute(module.path)) { - let cwd = await OS.File.getCurrentDirectory(); - module.path = OS.Path.join(cwd, module.path); - } let manifestPath = await writeManifest(module); registry.setValue( Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, @@ -248,13 +256,16 @@ add_task(async function test_pkcs11() { { name: "internalmodule", description: "Builtin Roots Module", - path: ctypes.libraryName("nssckbi"), + path: PathUtils.join( + Services.dirsvc.get("CurWorkD", Ci.nsIFile).path, + ctypes.libraryName("nssckbi") + ), id: "pkcs11@tests.mozilla.org", }, { name: "osclientcerts", description: "OS Client Cert Module", - path: OS.Path.join(libDir.path, ctypes.libraryName("osclientcerts")), + path: PathUtils.join(libDir.path, ctypes.libraryName("osclientcerts")), id: "pkcs11@tests.mozilla.org", }, ]);