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

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

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

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

@ -20,19 +20,17 @@ namespace PathUtils {
DOMString filename(DOMString path); 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 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 `/` * If the path provided is a root path (e.g., `C:` on Windows or `/`
* on *NIX), then null is returned. * on *NIX), then null is returned.
*/ */
[Throws] [Throws]
DOMString? parent(DOMString path, optional long depth = 1); DOMString? parent(DOMString path);
/** /**
* Join the given components into a full 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, void PathUtils::Parent(const GlobalObject&, const nsAString& aPath,
const int32_t aDepth, nsString& aResult, nsString& aResult, ErrorResult& aErr) {
ErrorResult& aErr) {
if (aPath.IsEmpty()) { if (aPath.IsEmpty()) {
aErr.ThrowNotAllowedError(ERROR_EMPTY_PATH); aErr.ThrowNotAllowedError(ERROR_EMPTY_PATH);
return; return;
@ -155,18 +154,10 @@ void PathUtils::Parent(const GlobalObject&, const nsAString& aPath,
return; return;
} }
if (aDepth <= 0) {
aErr.ThrowNotSupportedError("A depth of at least 1 is required");
return;
}
nsCOMPtr<nsIFile> parent; nsCOMPtr<nsIFile> parent;
for (int32_t i = 0; path && i < aDepth; i++) { if (nsresult rv = path->GetParent(getter_AddRefs(parent)); NS_FAILED(rv)) {
if (nsresult rv = path->GetParent(getter_AddRefs(parent)); NS_FAILED(rv)) { ThrowError(aErr, rv, ERROR_GET_PARENT);
ThrowError(aErr, rv, ERROR_GET_PARENT); return;
return;
}
path = parent;
} }
if (parent) { if (parent) {

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

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

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

@ -119,37 +119,6 @@
"\\\\server", "\\\\server",
"PathUtils.parent() with a UNC server path and child component" "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 { } else {
is( is(
PathUtils.parent("/"), PathUtils.parent("/"),
@ -166,37 +135,6 @@
"/var", "/var",
"PathUtils.parent() with a 3 component path" "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}`
);
}
}
} }
}); });