mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-10 05:08:36 +02:00
--HG-- rename : toolkit/mozapps/shared/CertUtils.jsm => toolkit/modules/CertUtils.jsm rename : toolkit/content/DeferredTask.jsm => toolkit/modules/DeferredTask.jsm rename : toolkit/content/Deprecated.jsm => toolkit/modules/Deprecated.jsm rename : toolkit/content/Dict.jsm => toolkit/modules/Dict.jsm rename : toolkit/mozapps/shared/FileUtils.jsm => toolkit/modules/FileUtils.jsm rename : toolkit/content/Geometry.jsm => toolkit/modules/Geometry.jsm rename : toolkit/content/InlineSpellChecker.jsm => toolkit/modules/InlineSpellChecker.jsm rename : toolkit/content/LightweightThemeConsumer.jsm => toolkit/modules/LightweightThemeConsumer.jsm rename : toolkit/content/PageMenu.jsm => toolkit/modules/PageMenu.jsm rename : toolkit/content/PopupNotifications.jsm => toolkit/modules/PopupNotifications.jsm rename : toolkit/content/PrivateBrowsingUtils.jsm => toolkit/modules/PrivateBrowsingUtils.jsm rename : toolkit/content/PropertyListUtils.jsm => toolkit/modules/PropertyListUtils.jsm rename : toolkit/content/Services.jsm => toolkit/modules/Services.jsm rename : toolkit/content/Task.jsm => toolkit/modules/Task.jsm rename : toolkit/content/Troubleshoot.jsm => toolkit/modules/Troubleshoot.jsm rename : toolkit/content/UpdateChannel.jsm => toolkit/modules/UpdateChannel.jsm rename : toolkit/content/WindowDraggingUtils.jsm => toolkit/modules/WindowDraggingUtils.jsm rename : toolkit/content/debug.js => toolkit/modules/debug.js rename : toolkit/content/tests/browser/browser_DeferredTask.js => toolkit/modules/tests/browser/browser_DeferredTask.js rename : toolkit/content/tests/browser/browser_Deprecated.js => toolkit/modules/tests/browser/browser_Deprecated.js rename : toolkit/content/tests/browser/browser_Geometry.js => toolkit/modules/tests/browser/browser_Geometry.js rename : toolkit/content/tests/browser/browser_InlineSpellChecker.js => toolkit/modules/tests/browser/browser_InlineSpellChecker.js rename : toolkit/content/tests/browser/browser_Services.js => toolkit/modules/tests/browser/browser_Services.js rename : toolkit/content/tests/browser/browser_Troubleshoot.js => toolkit/modules/tests/browser/browser_Troubleshoot.js rename : toolkit/mozapps/shared/test/chrome/Makefile.in => toolkit/modules/tests/chrome/Makefile.in rename : toolkit/mozapps/shared/test/chrome/moz.build => toolkit/modules/tests/chrome/moz.build rename : toolkit/mozapps/shared/test/chrome/test_bug544442_checkCert.xul => toolkit/modules/tests/chrome/test_bug544442_checkCert.xul rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListBinary.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListBinary.plist rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListXML.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListXML.plist rename : toolkit/mozapps/shared/test/unit/test_FileUtils.js => toolkit/modules/tests/xpcshell/test_FileUtils.js rename : toolkit/content/tests/unit/test_dict.js => toolkit/modules/tests/xpcshell/test_dict.js rename : toolkit/content/tests/unit/test_propertyListsUtils.js => toolkit/modules/tests/xpcshell/test_propertyListsUtils.js rename : toolkit/mozapps/shared/test/unit/test_readCertPrefs.js => toolkit/modules/tests/xpcshell/test_readCertPrefs.js rename : toolkit/content/tests/unit/test_task.js => toolkit/modules/tests/xpcshell/test_task.js
97 lines
2.8 KiB
JavaScript
97 lines
2.8 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
Components.utils.import("resource://gre/modules/CertUtils.jsm");
|
|
|
|
const PREF_PREFIX = "certutils.certs.";
|
|
|
|
function run_test() {
|
|
run_next_test();
|
|
}
|
|
|
|
function resetPrefs() {
|
|
var prefs = Services.prefs.getChildList(PREF_PREFIX);
|
|
prefs.forEach(Services.prefs.clearUserPref);
|
|
}
|
|
|
|
function attributes_match(aCert, aExpected) {
|
|
if (Object.keys(aCert).length != Object.keys(aExpected).length)
|
|
return false;
|
|
|
|
for (var attribute in aCert) {
|
|
if (!(attribute in aExpected))
|
|
return false;
|
|
if (aCert[attribute] != aExpected[attribute])
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function test_results(aCerts, aExpected) {
|
|
do_check_eq(aCerts.length, aExpected.length);
|
|
|
|
for (var i = 0; i < aCerts.length; i++) {
|
|
if (!attributes_match(aCerts[i], aExpected[i])) {
|
|
dump("Attributes for certificate " + (i + 1) + " did not match expected attributes\n");
|
|
dump("Saw: " + aCerts[i].toSource() + "\n");
|
|
dump("Expected: " + aExpected[i].toSource() + "\n");
|
|
do_check_true(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
add_test(function test_singleCert() {
|
|
Services.prefs.setCharPref(PREF_PREFIX + "1.attribute1", "foo");
|
|
Services.prefs.setCharPref(PREF_PREFIX + "1.attribute2", "bar");
|
|
|
|
var certs = readCertPrefs(PREF_PREFIX);
|
|
test_results(certs, [{
|
|
attribute1: "foo",
|
|
attribute2: "bar"
|
|
}]);
|
|
|
|
resetPrefs();
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_multipleCert() {
|
|
Services.prefs.setCharPref(PREF_PREFIX + "1.md5Fingerprint", "cf84a9a2a804e021f27cb5128fe151f4");
|
|
Services.prefs.setCharPref(PREF_PREFIX + "1.nickname", "1st cert");
|
|
Services.prefs.setCharPref(PREF_PREFIX + "2.md5Fingerprint", "9441051b7eb50e5ca2226095af710c1a");
|
|
Services.prefs.setCharPref(PREF_PREFIX + "2.nickname", "2nd cert");
|
|
|
|
var certs = readCertPrefs(PREF_PREFIX);
|
|
test_results(certs, [{
|
|
md5Fingerprint: "cf84a9a2a804e021f27cb5128fe151f4",
|
|
nickname: "1st cert"
|
|
}, {
|
|
md5Fingerprint: "9441051b7eb50e5ca2226095af710c1a",
|
|
nickname: "2nd cert"
|
|
}]);
|
|
|
|
resetPrefs();
|
|
run_next_test();
|
|
});
|
|
|
|
add_test(function test_skippedCert() {
|
|
Services.prefs.setCharPref(PREF_PREFIX + "1.issuerName", "Mozilla");
|
|
Services.prefs.setCharPref(PREF_PREFIX + "1.nickname", "1st cert");
|
|
Services.prefs.setCharPref(PREF_PREFIX + "2.issuerName", "Top CA");
|
|
Services.prefs.setCharPref(PREF_PREFIX + "2.nickname", "2nd cert");
|
|
Services.prefs.setCharPref(PREF_PREFIX + "4.issuerName", "Unknown CA");
|
|
Services.prefs.setCharPref(PREF_PREFIX + "4.nickname", "Ignored cert");
|
|
|
|
var certs = readCertPrefs(PREF_PREFIX);
|
|
test_results(certs, [{
|
|
issuerName: "Mozilla",
|
|
nickname: "1st cert"
|
|
}, {
|
|
issuerName: "Top CA",
|
|
nickname: "2nd cert"
|
|
}]);
|
|
|
|
resetPrefs();
|
|
run_next_test();
|
|
});
|