Backed out 2 changesets (bug 1745352) for failures on test_ext_pkcs11_management.js. CLOSED TREE

Backed out changeset 0975c59084aa (bug 1745352)
Backed out changeset ba57b662bb72 (bug 1745352)
This commit is contained in:
Csoregi Natalia 2022-01-19 06:16:46 +02:00
Родитель 2332b8975c
Коммит 0d1394aa98
6 изменённых файлов: 33 добавлений и 116 удалений

Просмотреть файл

@ -7,6 +7,7 @@
XPCOMUtils.defineLazyModuleGetters(this, {
ctypes: "resource://gre/modules/ctypes.jsm",
NativeManifests: "resource://gre/modules/NativeManifests.jsm",
OS: "resource://gre/modules/osfile.jsm",
});
XPCOMUtils.defineLazyServiceGetter(
@ -37,12 +38,12 @@ this.pkcs11 = class extends ExtensionAPI {
);
if (hostInfo) {
if (AppConstants.platform === "win") {
hostInfo.manifest.path = PathUtils.join(
PathUtils.parent(hostInfo.path),
hostInfo.manifest.path = OS.Path.join(
OS.Path.dirname(hostInfo.path),
hostInfo.manifest.path
);
}
let manifestLib = PathUtils.filename(hostInfo.manifest.path);
let manifestLib = OS.Path.basename(hostInfo.manifest.path);
if (AppConstants.platform !== "linux") {
manifestLib = manifestLib.toLowerCase(manifestLib);
}

Просмотреть файл

@ -3,39 +3,28 @@
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;
let baseDir;
let tmpDir = FileUtils.getDir("TmpD", ["PKCS11"]);
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);
add_task(async function setup() {
let tmpDir = await IOUtils.createUniqueDirectory(
await PathUtils.getTempDir(),
"PKCS11"
);
baseDir = PathUtils.join(tmpDir, slug);
await IOUtils.createDirectory(baseDir);
registerCleanupFunction(() => {
tmpDir.remove(true);
});
registerCleanupFunction(async () => {
await IOUtils.remove(tmpDir, { recursive: true });
});
function getPath(filename) {
return OS.Path.join(baseDir, filename);
}
const testmodule = PathUtils.join(
PathUtils.parent(Services.dirsvc.get("CurWorkD", Ci.nsIFile).path, 5),
"security",
"manager",
"ssl",
"tests",
"unit",
"pkcs11testmodule",
ctypes.libraryName("pkcs11testModule")
);
const testmodule =
"../../../../../security/manager/ssl/tests/unit/pkcs11testmodule/" +
ctypes.libraryName("pkcs11testmodule");
// This function was inspired by the native messaging test under
// toolkit/components/extensions
@ -50,8 +39,8 @@ async function setupManifests(modules) {
allowed_extensions: [module.id],
};
let manifestPath = PathUtils.join(baseDir, `${module.name}.json`);
await IOUtils.writeJSON(manifestPath, manifest);
let manifestPath = getPath(`${module.name}.json`);
await OS.File.writeAtomic(manifestPath, JSON.stringify(manifest));
return manifestPath;
}
@ -89,6 +78,10 @@ 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,
@ -255,16 +248,13 @@ add_task(async function test_pkcs11() {
{
name: "internalmodule",
description: "Builtin Roots Module",
path: PathUtils.join(
Services.dirsvc.get("CurWorkD", Ci.nsIFile).path,
ctypes.libraryName("nssckbi")
),
path: ctypes.libraryName("nssckbi"),
id: "pkcs11@tests.mozilla.org",
},
{
name: "osclientcerts",
description: "OS Client Cert Module",
path: PathUtils.join(libDir.path, ctypes.libraryName("osclientcerts")),
path: OS.Path.join(libDir.path, ctypes.libraryName("osclientcerts")),
id: "pkcs11@tests.mozilla.org",
},
]);

Просмотреть файл

@ -20,19 +20,17 @@ namespace PathUtils {
DOMString filename(DOMString path);
/**
* Return an ancestor directory of the given path.
* Return the parent directory name of the given path.
*
* @param path An absolute path.
* @param depth The number of ancestors to remove, defaulting to 1 (i.e., the
* parent).
*
* @return The ancestor directory.
* @return The parent directory.
*
* If the path provided is a root path (e.g., `C:` on Windows or `/`
* on *NIX), then null is returned.
*/
[Throws]
DOMString? parent(DOMString path, optional long depth = 1);
DOMString? parent(DOMString path);
/**
* Join the given components into a full path.

Просмотреть файл

@ -142,8 +142,7 @@ void PathUtils::Filename(const GlobalObject&, const nsAString& aPath,
}
void PathUtils::Parent(const GlobalObject&, const nsAString& aPath,
const int32_t aDepth, nsString& aResult,
ErrorResult& aErr) {
nsString& aResult, ErrorResult& aErr) {
if (aPath.IsEmpty()) {
aErr.ThrowNotAllowedError(ERROR_EMPTY_PATH);
return;
@ -155,18 +154,10 @@ void PathUtils::Parent(const GlobalObject&, const nsAString& aPath,
return;
}
if (aDepth <= 0) {
aErr.ThrowNotSupportedError("A depth of at least 1 is required");
return;
}
nsCOMPtr<nsIFile> parent;
for (int32_t i = 0; path && i < aDepth; i++) {
if (nsresult rv = path->GetParent(getter_AddRefs(parent)); NS_FAILED(rv)) {
ThrowError(aErr, rv, ERROR_GET_PARENT);
return;
}
path = parent;
if (nsresult rv = path->GetParent(getter_AddRefs(parent)); NS_FAILED(rv)) {
ThrowError(aErr, rv, ERROR_GET_PARENT);
return;
}
if (parent) {

Просмотреть файл

@ -41,8 +41,7 @@ class PathUtils final {
nsString& aResult, ErrorResult& aErr);
static void Parent(const GlobalObject&, const nsAString& aPath,
const int32_t aDepth, nsString& aResult,
ErrorResult& aErr);
nsString& aResult, ErrorResult& aErr);
static void Join(const GlobalObject&, const Sequence<nsString>& aComponents,
nsString& aResult, ErrorResult& aErr);

Просмотреть файл

@ -119,37 +119,6 @@
"\\\\server",
"PathUtils.parent() with a UNC server path and child component"
);
Assert.throws(
() => PathUtils.parent("C:", -1),
/^NotSupportedError: PathUtils.parent: A depth of at least 1 is required/,
"PathUtils.parent() with a negative depth throws"
);
Assert.throws(
() => PathUtils.parent("C:", 0),
/^NotSupportedError: PathUtils.parent: A depth of at least 1 is required/,
"PathUtils.parent() with a zero depth throws"
);
{
const path = "C:\\Users\\User\\AppData\\Local\\Mozilla\\Firefox\\Profiles\\foo.default";
const expected = [
"C:\\Users\\User\\AppData\\Local\\Mozilla\\Firefox\\Profiles",
"C:\\Users\\User\\AppData\\Local\\Mozilla\\Firefox",
"C:\\Users\\User\\AppData\\Local\\Mozilla",
"C:\\Users\\User\\AppData\\Local",
"C:\\Users\\User\\AppData",
"C:\\Users\\User",
"C:\\Users",
"C:",
null,
];
for (const [i, parent] of expected.entries()) {
is(PathUtils.parent(path, i + 1), parent, `PathUtils.parent() with depth=${i + 1}`)
}
}
} else {
is(
PathUtils.parent("/"),
@ -166,37 +135,6 @@
"/var",
"PathUtils.parent() with a 3 component path"
);
Assert.throws(
() => PathUtils.parent("/", -1),
/^NotSupportedError: PathUtils.parent: A depth of at least 1 is required/,
"PathUtils.parent() with a negative depth throws"
);
Assert.throws(
() => PathUtils.parent("/", 0),
/^NotSupportedError: PathUtils.parent: A depth of at least 1 is required/,
"PathUtils.parent() with a zero depth throws"
);
{
const path = "/home/user/.mozilla/firefox/foo.default";
const expected = [
"/home/user/.mozilla/firefox",
"/home/user/.mozilla",
"/home/user",
"/home",
"/",
null,
];
for (const [i, parent] of expected.entries()) {
is(
PathUtils.parent(path, i + 1),
parent,
`PathUtils.parent() with depth=${i + 1}`
);
}
}
}
});