mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Bug 1260626 - Add helper function in head_psm.js to load and unload the test PKCS11 module. r=keeler
This helps cleanup some tests. MozReview-Commit-ID: 5xBBsIgKYR9 --HG-- extra : rebase_source : d87401bfe71dea8560e79db3dbb47ae1ebaa80cd
This commit is contained in:
parent
fdea8ce396
commit
84902dca10
@ -794,3 +794,32 @@ function asyncTestCertificateUsages(certdb, cert, expectedUsages) {
|
||||
});
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the pkcs11testmodule.cpp test PKCS #11 module, and registers a cleanup
|
||||
* function that unloads it once the calling test completes.
|
||||
*
|
||||
* @param {Boolean} expectModuleUnloadToFail
|
||||
* Should be set to true for tests that manually unload the
|
||||
* test module, so the attempt to auto unload the test module
|
||||
* doesn't cause a test failure. Should be set to false
|
||||
* otherwise, so failure to automatically unload the test
|
||||
* module gets reported.
|
||||
*/
|
||||
function loadPKCS11TestModule(expectModuleUnloadToFail) {
|
||||
let libraryFile = Services.dirsvc.get("CurWorkD", Ci.nsILocalFile);
|
||||
libraryFile.append("pkcs11testmodule");
|
||||
libraryFile.append(ctypes.libraryName("pkcs11testmodule"));
|
||||
ok(libraryFile.exists(), "The pkcs11testmodule file should exist");
|
||||
|
||||
let pkcs11 = Cc["@mozilla.org/security/pkcs11;1"].getService(Ci.nsIPKCS11);
|
||||
do_register_cleanup(() => {
|
||||
try {
|
||||
pkcs11.deleteModule("PKCS11 Test Module");
|
||||
} catch (e) {
|
||||
Assert.ok(expectModuleUnloadToFail,
|
||||
`Module unload should suceed only when expected: ${e}`);
|
||||
}
|
||||
});
|
||||
pkcs11.addModule("PKCS11 Test Module", libraryFile.path, 0, 0);
|
||||
}
|
||||
|
@ -72,14 +72,5 @@ function run_test() {
|
||||
Services.obs.addObserver(new SmartcardObserver("smartcard-remove"),
|
||||
"smartcard-remove", false);
|
||||
|
||||
let pkcs11 = Cc["@mozilla.org/security/pkcs11;1"].getService(Ci.nsIPKCS11);
|
||||
do_register_cleanup(function() {
|
||||
pkcs11.deleteModule("PKCS11 Test Module");
|
||||
});
|
||||
let libraryName = ctypes.libraryName("pkcs11testmodule");
|
||||
let libraryFile = Services.dirsvc.get("CurWorkD", Ci.nsILocalFile);
|
||||
libraryFile.append("pkcs11testmodule");
|
||||
libraryFile.append(libraryName);
|
||||
ok(libraryFile.exists(), "The pkcs11testmodule file should exist");
|
||||
pkcs11.addModule("PKCS11 Test Module", libraryFile.path, 0, 0);
|
||||
loadPKCS11TestModule(false);
|
||||
}
|
||||
|
@ -59,29 +59,12 @@ function checkTestModuleExists() {
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
let libraryFile = Services.dirsvc.get("CurWorkD", Ci.nsILocalFile);
|
||||
libraryFile.append("pkcs11testmodule");
|
||||
libraryFile.append(ctypes.libraryName("pkcs11testmodule"));
|
||||
ok(libraryFile.exists(), "The pkcs11testmodule file should exist");
|
||||
|
||||
// Check that if we have never added the test module, that we don't find it
|
||||
// in the module list.
|
||||
checkTestModuleNotPresent();
|
||||
|
||||
// Check that adding the test module makes it appear in the module list.
|
||||
let pkcs11 = Cc["@mozilla.org/security/pkcs11;1"].getService(Ci.nsIPKCS11);
|
||||
do_register_cleanup(() => {
|
||||
try {
|
||||
pkcs11.deleteModule("PKCS11 Test Module");
|
||||
} catch (e) {
|
||||
// deleteModule() throws if the module we tell it to delete is missing,
|
||||
// or if some other thing went wrong. Since we're just cleaning up,
|
||||
// there's nothing to do even if the call fails. In addition, we delete
|
||||
// the test module during a normal run of this test file, so we need to
|
||||
// catch the exception that is raised to not have the test fail.
|
||||
}
|
||||
});
|
||||
pkcs11.addModule("PKCS11 Test Module", libraryFile.path, 0, 0);
|
||||
loadPKCS11TestModule(true);
|
||||
let testModule = checkTestModuleExists();
|
||||
|
||||
// Check that listing the slots for the test module works.
|
||||
@ -124,6 +107,7 @@ function run_test() {
|
||||
"Non-present 'slot' should not be findable by name via the module DB");
|
||||
|
||||
// Check that deleting the test module makes it disappear from the module list.
|
||||
let pkcs11 = Cc["@mozilla.org/security/pkcs11;1"].getService(Ci.nsIPKCS11);
|
||||
pkcs11.deleteModule("PKCS11 Test Module");
|
||||
checkTestModuleNotPresent();
|
||||
|
||||
|
@ -16,12 +16,7 @@ Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports);
|
||||
|
||||
function run_test() {
|
||||
let pkcs11 = Cc["@mozilla.org/security/pkcs11;1"].getService(Ci.nsIPKCS11);
|
||||
let libraryName = ctypes.libraryName("pkcs11testmodule");
|
||||
let libraryFile = Services.dirsvc.get("CurWorkD", Ci.nsILocalFile);
|
||||
libraryFile.append("pkcs11testmodule");
|
||||
libraryFile.append(libraryName);
|
||||
ok(libraryFile.exists(), "The pkcs11testmodule file should exist");
|
||||
pkcs11.addModule("PKCS11 Test Module", libraryFile.path, 0, 0);
|
||||
loadPKCS11TestModule(true);
|
||||
pkcs11.deleteModule("PKCS11 Test Module");
|
||||
Services.obs.addObserver(function() {
|
||||
ok(false, "smartcard-insert event should not have been emitted");
|
||||
|
@ -9,16 +9,7 @@
|
||||
do_get_profile();
|
||||
|
||||
function run_test() {
|
||||
let libraryFile = Services.dirsvc.get("CurWorkD", Ci.nsILocalFile);
|
||||
libraryFile.append("pkcs11testmodule");
|
||||
libraryFile.append(ctypes.libraryName("pkcs11testmodule"));
|
||||
ok(libraryFile.exists(), "The pkcs11testmodule file should exist");
|
||||
|
||||
let pkcs11 = Cc["@mozilla.org/security/pkcs11;1"].getService(Ci.nsIPKCS11);
|
||||
do_register_cleanup(() => {
|
||||
pkcs11.deleteModule("PKCS11 Test Module");
|
||||
});
|
||||
pkcs11.addModule("PKCS11 Test Module", libraryFile.path, 0, 0);
|
||||
loadPKCS11TestModule(false);
|
||||
|
||||
let moduleDB = Cc["@mozilla.org/security/pkcs11moduledb;1"]
|
||||
.getService(Ci.nsIPKCS11ModuleDB);
|
||||
|
Loading…
Reference in New Issue
Block a user