Bug 288040 – convert signons3.txt to mozstorage. r=dolske, r=sdwilsh

--HG--
rename : storage/test/unit/corruptDB.sqlite => toolkit/components/passwordmgr/test/unit/data/corruptDB.sqlite
This commit is contained in:
Paul O'Shannessy 2008-08-15 15:41:22 -07:00
parent a3d15d68b0
commit 348021ae37
12 changed files with 2497 additions and 9 deletions

View File

@ -2611,7 +2611,7 @@ pref("signon.rememberSignons", true);
pref("signon.expireMasterPassword", false);
pref("signon.SignonFileName", "signons.txt"); // obsolete
pref("signon.SignonFileName2", "signons2.txt"); // obsolete
pref("signon.SignonFileName3", "signons3.txt");
pref("signon.SignonFileName3", "signons3.txt"); // obsolete
pref("signon.autofillForms", true);
pref("signon.debug", false); // logs to Error Console

View File

@ -48,6 +48,7 @@ EXTRA_COMPONENTS = \
nsLoginManagerPrompter.js \
nsLoginInfo.js \
storage-Legacy.js \
storage-mozStorage.js \
$(NULL)

View File

@ -97,7 +97,7 @@ LoginManager.prototype = {
get _storage() {
if (!this.__storage) {
var contractID = "@mozilla.org/login-manager/storage/legacy;1";
var contractID = "@mozilla.org/login-manager/storage/mozStorage;1";
try {
var catMan = Cc["@mozilla.org/categorymanager;1"].
getService(Ci.nsICategoryManager);

File diff suppressed because it is too large Load Diff

View File

@ -47,15 +47,18 @@ const LoginTest = {
aOutputPathName, aOutputFileName, aExpectedError) {
var err = null;
var inputFile = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsILocalFile);
inputFile.initWithPath(aInputPathName);
inputFile.append(aInputFileName);
var inputFile = null;
if (aInputFileName) {
var inputFile = Cc["@mozilla.org/file/local;1"].
createInstance(Ci.nsILocalFile);
inputFile.initWithPath(aInputPathName);
inputFile.append(aInputFileName);
}
var outputFile = null;
if (aOutputFileName) {
var outputFile = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsILocalFile);
var outputFile = Cc["@mozilla.org/file/local;1"].
createInstance(Ci.nsILocalFile);
outputFile.initWithPath(aOutputPathName);
outputFile.append(aOutputFileName);
}
@ -158,6 +161,23 @@ const LoginTest = {
lineCount++;
return lineCount;
},
newMozStorage : function () {
var storage = Cc["@mozilla.org/login-manager/storage/mozStorage;1"].
createInstance(Ci.nsILoginManagerStorage);
if (!storage)
throw "Couldn't create storage instance.";
return storage;
},
deleteFile : function (pathname, filename) {
var file = Cc["@mozilla.org/file/local;1"].
createInstance(Ci.nsILocalFile);
file.initWithPath(pathname);
file.append(filename);
if (file.exists())
file.remove(false);
}
};

View File

@ -389,13 +389,42 @@ LoginTest.initStorage(storage, INDIR, "signons-2d-10.txt");
LoginTest.checkStorageData(storage, [], [testuser1, testuser2]);
/* ========== 22 ========== */
testnum++;
testdesc = "Initialize with signons-06.txt (1 disabled, 1 login); test removeLogin";
testuser1.init("http://dummyhost.mozilla.org", "", null,
"dummydude", "itsasecret", "put_user_here", "put_pw_here");
testuser2.init("http://dummyhost.mozilla.org", "", null,
"dummydude2", "itsasecret2", "put_user2_here", "put_pw2_here");
LoginTest.initStorage(storage, INDIR, "signons-06.txt", OUTDIR, "signons-06-2.txt");
LoginTest.checkStorageData(storage, ["https://www.site.net"], [testuser1]);
testdesc = "test removeLogin";
storage.removeLogin(testuser1);
LoginTest.checkStorageData(storage, ["https://www.site.net"], []);
/* ========== 23 ========== */
testnum++;
testdesc = "Initialize with signons-06.txt (1 disabled, 1 login); test modifyLogin";
LoginTest.initStorage(storage, INDIR, "signons-06.txt", OUTDIR, "signons-06-3.txt");
LoginTest.checkStorageData(storage, ["https://www.site.net"], [testuser1]);
testdesc = "test modifyLogin";
storage.modifyLogin(testuser1, testuser2);
LoginTest.checkStorageData(storage, ["https://www.site.net"], [testuser2]);
/*
* ---------------------- Bug 427033 ----------------------
* Check migration of logins stored with a JS formSubmitURL
*/
/* ========== 22 ========== */
/* ========== 24 ========== */
testnum++;
testdesc = "checking import of JS formSubmitURL entries"

View File

@ -0,0 +1,274 @@
/*
* Test suite for storage-mozStorage.js -- exercises reading from on-disk storage.
*
* This test interfaces directly with the mozStorage password storage module,
* bypassing the normal password manager usage.
*
*/
function run_test() {
try {
var testnum = 0;
var testdesc = "Setup of nsLoginInfo test-users";
var nsLoginInfo = new Components.Constructor(
"@mozilla.org/login-manager/loginInfo;1",
Components.interfaces.nsILoginInfo);
do_check_true(nsLoginInfo != null);
var testuser1 = new nsLoginInfo;
testuser1.init("http://dummyhost.mozilla.org", "", null,
"dummydude", "itsasecret", "put_user_here", "put_pw_here");
var testuser2 = new nsLoginInfo;
testuser2.init("http://dummyhost.mozilla.org", "", null,
"dummydude2", "itsasecret2", "put_user2_here", "put_pw2_here");
/* ========== 1 ========== */
var testnum = 1;
var testdesc = "Initial connection to storage module"
var storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt", OUTDIR, "signons-empty.sqlite");
storage.getAllLogins({});
var testdesc = "[ensuring file exists]"
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(OUTDIR);
file.append("signons-empty.sqlite");
do_check_true(file.exists());
LoginTest.deleteFile(OUTDIR, "signons-empty.sqlite");
/* ========== 2 ========== */
testnum++;
testdesc = "[ensuring file doesn't exist]";
storage = LoginTest.newMozStorage();
var filename="this-file-does-not-exist-"+Math.floor(Math.random() * 10000);
file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(OUTDIR);
file.append(filename);
var exists = file.exists();
if (exists) {
// Go ahead and remove the file, so that this failure doesn't
// repeat itself w/o intervention.
file.remove(false);
do_check_false(exists); // fail on purpose
}
testdesc = "Initialize with a non-existant data file";
LoginTest.initStorage(storage, null, null, OUTDIR, filename);
LoginTest.checkStorageData(storage, [], []);
if (file.exists())
file.remove(false);
/* ========== 3 ========== */
testnum++;
testdesc = "Initialize with signons-02.txt (valid, but empty)";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-02.txt", OUTDIR, "signons-02.sqlite");
LoginTest.checkStorageData(storage, [], []);
LoginTest.deleteFile(OUTDIR, "signons-02.sqlite");
/* ========== 4 ========== */
testnum++;
testdesc = "Initialize with signons-03.txt (1 disabled, 0 logins)";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-03.txt", OUTDIR, "signons-03.sqlite");
LoginTest.checkStorageData(storage, ["http://www.disabled.com"], []);
LoginTest.deleteFile(OUTDIR, "signons-03.sqlite");
/* ========== 5 ========== */
testnum++;
testdesc = "Initialize with signons-04.txt (1 disabled, 0 logins, extra '.')";
storage = LoginTest.newMozStorage();
// Mozilla code should never have generated the extra ".", but it's possible
// someone writing an external utility might have generated it, since it
// would seem consistant with the format.
LoginTest.initStorage(storage, INDIR, "signons-04.txt", OUTDIR, "signons-04.sqlite");
LoginTest.checkStorageData(storage, ["http://www.disabled.com"], []);
LoginTest.deleteFile(OUTDIR, "signons-04.sqlite");
/* ========== 6 ========== */
testnum++;
testdesc = "Initialize with signons-05.txt (0 disabled, 1 login)";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-05.txt", OUTDIR, "signons-05.sqlite");
LoginTest.checkStorageData(storage, [], [testuser1]);
// counting logins matching host
do_check_eq(1, storage.countLogins("http://dummyhost.mozilla.org", "", null));
// counting logins matching host (login has blank actionURL)
do_check_eq(1, storage.countLogins("http://dummyhost.mozilla.org", "foo", null));
// counting logins (don't match form login for HTTP search)
do_check_eq(0, storage.countLogins("http://dummyhost.mozilla.org", null, ""));
// counting logins (don't match a bogus hostname)
do_check_eq(0, storage.countLogins("blah", "", ""));
// counting all logins (empty hostname)
do_check_eq(1, storage.countLogins("", "", null));
// counting all logins (empty hostname)
do_check_eq(1, storage.countLogins("", "foo", null));
// counting no logins (null hostname)
do_check_eq(0, storage.countLogins(null, "", null));
do_check_eq(0, storage.countLogins(null, null, ""));
do_check_eq(0, storage.countLogins(null, "", ""));
do_check_eq(0, storage.countLogins(null, null, null));
LoginTest.deleteFile(OUTDIR, "signons-05.sqlite");
/* ========== 7 ========== */
testnum++;
testdesc = "Initialize with signons-06.txt (1 disabled, 1 login)";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-06.txt", OUTDIR, "signons-06.sqlite");
LoginTest.checkStorageData(storage, ["https://www.site.net"], [testuser1]);
LoginTest.deleteFile(OUTDIR, "signons-06.sqlite");
/* ========== 8 ========== */
testnum++;
testdesc = "Initialize with signons-07.txt (0 disabled, 2 logins on same host)";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-07.txt", OUTDIR, "signons-07.sqlite");
LoginTest.checkStorageData(storage, [], [testuser1, testuser2]);
// counting logins matching host
do_check_eq(2, storage.countLogins("http://dummyhost.mozilla.org", "", null));
// counting logins matching host (login has blank actionURL)
do_check_eq(2, storage.countLogins("http://dummyhost.mozilla.org", "foo", null));
// counting logins (don't match form login for HTTP search)
do_check_eq(0, storage.countLogins("http://dummyhost.mozilla.org", null, ""));
// counting logins (don't match a bogus hostname)
do_check_eq(0, storage.countLogins("blah", "", ""));
LoginTest.deleteFile(OUTDIR, "signons-07.sqlite");
/* ========== 9 ========== */
testnum++;
testdesc = "Initialize with signons-08.txt (500 disabled, 500 logins)";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-08.txt", OUTDIR, "signons-08.sqlite");
var disabledHosts = [];
for (var i = 1; i <= 500; i++) {
disabledHosts.push("http://host-" + i + ".site.com");
}
var bulkLogin, logins = [];
for (i = 1; i <= 250; i++) {
bulkLogin = new nsLoginInfo;
bulkLogin.init("http://dummyhost.site.org", "http://cgi.site.org", null,
"dummydude", "itsasecret", "usernameField-" + i, "passwordField-" + i);
logins.push(bulkLogin);
}
for (i = 1; i <= 250; i++) {
bulkLogin = new nsLoginInfo;
bulkLogin.init("http://dummyhost-" + i + ".site.org", "http://cgi.site.org", null,
"dummydude", "itsasecret", "usernameField", "passwordField");
logins.push(bulkLogin);
}
LoginTest.checkStorageData(storage, disabledHosts, logins);
// counting all logins for dummyhost
do_check_eq(250, storage.countLogins("http://dummyhost.site.org", "", ""));
do_check_eq(250, storage.countLogins("http://dummyhost.site.org", "", null));
do_check_eq(0, storage.countLogins("http://dummyhost.site.org", null, ""));
// counting all logins for dummyhost-1
do_check_eq(1, storage.countLogins("http://dummyhost-1.site.org", "", ""));
do_check_eq(1, storage.countLogins("http://dummyhost-1.site.org", "", null));
do_check_eq(0, storage.countLogins("http://dummyhost-1.site.org", null, ""));
// counting logins for all hosts
do_check_eq(500, storage.countLogins("", "", ""));
do_check_eq(500, storage.countLogins("", "http://cgi.site.org", ""));
do_check_eq(500, storage.countLogins("", "http://cgi.site.org", null));
do_check_eq(0, storage.countLogins("", "blah", ""));
do_check_eq(0, storage.countLogins("", "", "blah"));
// counting logins for no hosts
do_check_eq(0, storage.countLogins(null, "", ""));
do_check_eq(0, storage.countLogins(null, "http://cgi.site.org", ""));
do_check_eq(0, storage.countLogins(null, "http://cgi.site.org", null));
do_check_eq(0, storage.countLogins(null, null, null));
LoginTest.deleteFile(OUTDIR, "signons-08.sqlite");
/* ========== 10 ========== */
testnum++;
testdesc = "Initialize with signons-06.txt (1 disabled, 1 login); test removeLogin";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-06.txt", OUTDIR, "signons-06-2.sqlite");
LoginTest.checkStorageData(storage, ["https://www.site.net"], [testuser1]);
storage.removeLogin(testuser1);
LoginTest.checkStorageData(storage, ["https://www.site.net"], []);
LoginTest.deleteFile(OUTDIR, "signons-06-2.sqlite");
/* ========== 11 ========== */
testnum++;
testdesc = "Initialize with signons-06.txt (1 disabled, 1 login); test modifyLogin";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-06.txt", OUTDIR, "signons-06-3.sqlite");
LoginTest.checkStorageData(storage, ["https://www.site.net"], [testuser1]);
storage.modifyLogin(testuser1, testuser2);
LoginTest.checkStorageData(storage, ["https://www.site.net"], [testuser2]);
LoginTest.deleteFile(OUTDIR, "signons-06-3.sqlite");
/*
* ---------------------- Bug 427033 ----------------------
* Check migration of logins stored with a JS formSubmitURL
*/
/* ========== 12 ========== */
testnum++;
testdesc = "checking import of JS formSubmitURL entries"
testuser1.init("http://jstest.site.org", "javascript:", null,
"dummydude", "itsasecret", "put_user_here", "put_pw_here");
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-427033-1.txt",
OUTDIR, "signons-427033-1.sqlite");
LoginTest.checkStorageData(storage, [], [testuser1]);
testdesc = "[flush and reload for verification]"
LoginTest.initStorage(storage, null, null, OUTDIR, "signons-427033-1.sqlite");
LoginTest.checkStorageData(storage, [], [testuser1]);
LoginTest.deleteFile(OUTDIR, "signons-427033-1.sqlite");
} catch (e) {
throw "FAILED in test #" + testnum + " -- " + testdesc + ": " + e;
}
};

View File

@ -0,0 +1,284 @@
/*
* Test suite for storage-mozStorage.js -- exercises writing to on-disk storage.
*
* This test interfaces directly with the mozStorage login storage module,
* bypassing the normal login manager usage.
*
*/
function run_test() {
try {
/* ========== 0 ========== */
var testnum = 0;
var testdesc = "Initial connection to storage module"
var storage = LoginTest.newMozStorage();
if (!storage)
throw "Couldn't create storage instance.";
/* ========== 1 ========== */
testnum++;
var testdesc = "Create nsILoginInfo instances for testing with"
var dummyuser1 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var dummyuser2 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var dummyuser3 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
dummyuser1.init( "http://dummyhost.mozilla.org", "", null,
"dummydude", "itsasecret", "put_user_here", "put_pw_here");
dummyuser2.init("http://dummyhost2.mozilla.org", "http://cgi.site.com", null,
"dummydude2", "itsasecret2", "put_user2_here", "put_pw2_here");
dummyuser3.init("http://dummyhost2.mozilla.org", "http://cgi.site.com", null,
"dummydude3", "itsasecret3", "put_user3_here", "put_pw3_here");
/* ========== 2 ========== */
testnum++;
testdesc = "[ensuring file doesn't exist]";
storage = LoginTest.newMozStorage();
var filename="non-existant-file-"+Math.floor(Math.random() * 10000);
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(OUTDIR);
file.append(filename);
var exists = file.exists();
if (exists) {
// Go ahead and remove the file, so that this failure
// doesn't repeat itself w/o intervention.
file.remove(false);
do_check_false(exists); // fail on purpose
}
testdesc = "Initialize with no existing file";
LoginTest.initStorage(storage, null, null, OUTDIR, filename);
LoginTest.checkStorageData(storage, [], []);
testdesc = "Add 1 disabled host only";
storage.setLoginSavingEnabled("http://www.nsa.gov", false);
LoginTest.checkStorageData(storage, ["http://www.nsa.gov"], []);
file.remove(false);
/* ========== 3 ========== */
testnum++;
testdesc = "Initialize with existing file (valid, but empty)";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-01.sqlite");
LoginTest.checkStorageData(storage, [], []);
testdesc = "Add 1 disabled host only";
storage.setLoginSavingEnabled("http://www.nsa.gov", false);
LoginTest.checkStorageData(storage, ["http://www.nsa.gov"], []);
testdesc = "Remove disabled host only";
storage.setLoginSavingEnabled("http://www.nsa.gov", true);
LoginTest.checkStorageData(storage, [], []);
LoginTest.deleteFile(OUTDIR, "output-01.sqlite");
/* ========== 4 ========== */
testnum++;
testdesc = "[clear data and reinitialize with signons-empty.txt]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-02.sqlite");
// Previous tests made sure we can write to an existing file, so now just
// tweak component to output elsewhere.
testdesc = "Add 1 login only";
storage.addLogin(dummyuser1);
testdesc = "[flush and reload for verification]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-02.sqlite");
testdesc = "Verify output-02.sqlite";
LoginTest.checkStorageData(storage, [], [dummyuser1]);
LoginTest.deleteFile(OUTDIR, "output-02.sqlite");
/* ========== 5 ========== */
testnum++;
testdesc = "[clear data and reinitialize with signons-empty.txt]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-03.sqlite");
testdesc = "Add 1 disabled host only";
storage.setLoginSavingEnabled("http://www.nsa.gov", false);
testdesc = "[flush and reload for verification]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-03.sqlite");
testdesc = "Verify output-03.sqlite";
LoginTest.checkStorageData(storage, ["http://www.nsa.gov"], []);
LoginTest.deleteFile(OUTDIR, "output-03.sqlite");
/* ========== 6 ========== */
testnum++;
testdesc = "[clear data and reinitialize with signons-empty.txt]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-04.sqlite");
testdesc = "Add 1 disabled host and 1 login";
storage.setLoginSavingEnabled("http://www.nsa.gov", false);
storage.addLogin(dummyuser1);
testdesc = "[flush and reload for verification]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-04.sqlite");
testdesc = "Verify output-04.sqlite";
LoginTest.checkStorageData(storage, ["http://www.nsa.gov"], [dummyuser1]);
LoginTest.deleteFile(OUTDIR, "output-04.sqlite");
/* ========== 7 ========== */
testnum++;
testdesc = "[clear data and reinitialize with signons-empty.txt]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-03-2.sqlite");
testdesc = "Add 2 logins (to different hosts)";
storage.addLogin(dummyuser1);
storage.addLogin(dummyuser2);
testdesc = "[flush and reload for verification]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-03-2.sqlite");
testdesc = "Verify output-03-2.sqlite";
LoginTest.checkStorageData(storage, [], [dummyuser2, dummyuser1]);
LoginTest.deleteFile(OUTDIR, "output-03-2.sqlite");
/* ========== 8 ========== */
testnum++;
testdesc = "[clear data and reinitialize with signons-empty.txt]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-04-2.sqlite");
testdesc = "Add 2 logins (to same host)";
storage.addLogin(dummyuser2);
storage.addLogin(dummyuser3);
testdesc = "[flush and reload for verification]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-04-2.sqlite");
testdesc = "Verify output-04-2.sqlite";
LoginTest.checkStorageData(storage, [], [dummyuser3, dummyuser2]);
LoginTest.deleteFile(OUTDIR, "output-04-2.sqlite");
/* ========== 9 ========== */
testnum++;
testdesc = "[clear data and reinitialize with signons-empty.txt]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-05.sqlite");
testdesc = "Add 3 logins (2 to same host)";
storage.addLogin(dummyuser3);
storage.addLogin(dummyuser1);
storage.addLogin(dummyuser2);
testdesc = "[flush and reload for verification]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-05.sqlite");
testdesc = "Verify output-05.sqlite";
LoginTest.checkStorageData(storage, [], [dummyuser1, dummyuser2, dummyuser3]);
// count dummyhost2 logins
do_check_eq(2, storage.countLogins("http://dummyhost2.mozilla.org", "", ""));
// count dummyhost logins
do_check_eq(1, storage.countLogins("http://dummyhost.mozilla.org", "", ""));
// count dummyhost2 logins w/ specific formSubmitURL
do_check_eq(2, storage.countLogins("http://dummyhost2.mozilla.org", "http://cgi.site.com", ""));
LoginTest.deleteFile(OUTDIR, "output-05.sqlite");
/* ========== 10 ========== */
testnum++;
testdesc = "[init with 1 login, 1 disabled host]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-06.txt",
OUTDIR, "output-06.sqlite");
// storage.removeAllLogins();
var oldfile1 = PROFDIR.clone();
oldfile1.append("signons.txt");
// Shouldn't exist, but if a previous run failed it could be left over
if (oldfile1.exists())
oldfile1.remove(false);
oldfile1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
do_check_true(oldfile1.exists());
var oldfile2 = PROFDIR.clone();
oldfile2.append("signons2.txt");
// Shouldn't exist, but if a previous run failed it could be left over
if (oldfile2.exists())
oldfile2.remove(false);
oldfile2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
do_check_true(oldfile2.exists());
var oldfile3 = PROFDIR.clone();
oldfile3.append("signons3.txt");
// Shouldn't exist, but if a previous run failed it could be left over
if (oldfile3.exists())
oldfile3.remove(false);
oldfile3.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
do_check_true(oldfile3.exists());
testdesc = "Ensure old files are deleted when removeAllLogins is called";
storage.removeAllLogins();
LoginTest.checkStorageData(storage, ["https://www.site.net"], []);
do_check_false(oldfile1.exists());
do_check_false(oldfile2.exists());
do_check_false(oldfile3.exists());
LoginTest.deleteFile(OUTDIR, "output-06.sqlite");
} catch (e) {
throw ("FAILED in test #" + testnum + " -- " + testdesc + ": " + e);
}
};

View File

@ -0,0 +1,554 @@
/*
* Test suite for storage-mozStorage.js -- various bug fixes.
*
* This test interfaces directly with the mozStorage login storage module,
* bypassing the normal login manager usage.
*
*/
function run_test() {
try {
/* ========== 0 ========== */
var testnum = 0;
var testdesc = "Initial connection to storage module"
var storage = LoginTest.newMozStorage();
if (!storage)
throw "Couldn't create storage instance.";
/* ========== 1 ========== */
testnum++;
var testdesc = "Create nsILoginInfo instances for testing with"
var dummyuser1 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var dummyuser2 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var dummyuser3 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
dummyuser1.init("http://dummyhost.mozilla.org", "", null,
"testuser1", "testpass1", "put_user_here", "put_pw_here");
dummyuser2.init("http://dummyhost2.mozilla.org", "", null,
"testuser2", "testpass2", "put_user2_here", "put_pw2_here");
dummyuser3.init("http://dummyhost2.mozilla.org", "", null,
"testuser3", "testpass3", "put_user3_here", "put_pw3_here");
LoginTest.deleteFile(OUTDIR, "signons.sqlite");
/*
* ---------------------- Bug 380961 ----------------------
* Need to support decoding the mime64-obscured format still
* used by SeaMonkey.
*/
/* ========== 2 ========== */
testnum++;
testdesc = "checking import of mime64-obscured entries"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-380961-1.txt",
OUTDIR, "output-380961-1.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser1]);
testdesc = "[flush and reload for verification]"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-380961-1.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser1]);
LoginTest.deleteFile(OUTDIR, "output-380961-1.sqlite");
/* ========== 3 ========== */
testnum++;
testdesc = "testing import of multiple mime-64 entries for a host"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-380961-2.txt",
OUTDIR, "output-380961-2.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser2, dummyuser3]);
testdesc = "[flush and reload for verification]"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-380961-2.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser2, dummyuser3]);
LoginTest.deleteFile(OUTDIR, "output-380961-2.sqlite");
/* ========== 4 ========== */
testnum++;
testdesc = "testing import of mixed encrypted and mime-64 entries."
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-380961-3.txt",
OUTDIR, "output-380961-3.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser1, dummyuser2, dummyuser3]);
testdesc = "[flush and reload for verification]"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-380961-3.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser1, dummyuser2, dummyuser3]);
LoginTest.deleteFile(OUTDIR, "output-380961-3.sqlite");
/*
* ---------------------- Bug 381262 ----------------------
* The SecretDecoderRing can't handle UCS2, failure to
* convert to UTF8 garbles the result.
*
* Note: dump()ing to the console on OS X (at least) outputs
* garbage, whereas the "bad" UCS2 looks ok!
*/
/* ========== 5 ========== */
testnum++;
testdesc = "initializing login with non-ASCII data."
var dummyuser4 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
dummyuser4.hostname = "https://site.org";
dummyuser4.username = String.fromCharCode(
355, 277, 349, 357, 533, 537, 101, 345, 185);
// "testuser1" using similar-looking glyphs
dummyuser4.usernameField = "username";
dummyuser4.password = "testpa" + String.fromCharCode(223) + "1";
// "ss" replaced with German eszett.
dummyuser4.passwordField = "password";
dummyuser4.formSubmitURL = "https://site.org";
dummyuser4.httpRealm = null;
/* ========== 6 ========== */
testnum++;
testdesc = "testing import of non-ascii username and password."
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-381262.txt",
OUTDIR, "output-381262-1.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser4]);
testdesc = "[flush and reload for verification]"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-381262-1.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser4]);
LoginTest.deleteFile(OUTDIR, "output-381262-1.sqlite");
/* ========== 7 ========== */
testnum++;
testdesc = "testing storage of non-ascii username and password."
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-381262-2.sqlite");
LoginTest.checkStorageData(storage, [], []);
storage.addLogin(dummyuser4);
LoginTest.checkStorageData(storage, [], [dummyuser4]);
testdesc = "[flush and reload for verification]"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-381262-2.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser4]);
LoginTest.deleteFile(OUTDIR, "output-381262-2.sqlite");
/*
* ---------------------- Bug 400751 ----------------------
* Migrating from existing mime64 encoded format causes
* errors in storage legacy's code
*/
/* ========== 8 ========== */
testnum++;
testdesc = "checking double reading of mime64-obscured entries";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-380961-1.txt",
OUTDIR, "output-400751-0.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser1]);
testdesc = "checking double reading of mime64-obscured entries part 2";
LoginTest.checkStorageData(storage, [], [dummyuser1]);
LoginTest.deleteFile(OUTDIR, "output-400751-0.sqlite");
/* ========== 9 ========== */
testnum++;
testdesc = "checking correct storage of mime64 converted entries";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-380961-1.txt",
OUTDIR, "output-400751-1.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser1]);
LoginTest.checkStorageData(storage, [], [dummyuser1]);
storage.addLogin(dummyuser2); // trigger a write
LoginTest.checkStorageData(storage, [], [dummyuser1, dummyuser2]);
testdesc = "[flush and reload for verification]";
LoginTest.initStorage(storage, null, null, OUTDIR, "output-400751-1.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser1, dummyuser2]);
LoginTest.deleteFile(OUTDIR, "output-400751-1.sqlite");
/*
* ---------------------- Bug 394610 ----------------------
* Ensure input which might mess with the format or structure of
* the store file is appropriately filtered.
*/
/* ========== 10 ========== */
testnum++;
function tryAddUser(storage, aUser, aExpectedError) {
var err = null;
try {
storage.addLogin(aUser);
} catch (e) {
err = e;
}
LoginTest.checkExpectedError(aExpectedError, err);
}
testdesc = "preparting to try logins with bogus values";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-394610-1.sqlite");
LoginTest.checkStorageData(storage, [], []);
var failUser = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
// init with legal values, we'll change on-the-fly
failUser.init("http://failure.site.org",
"http://failure.site.org", null,
"username", "password", "uname", "pword");
testdesc = "storing data values with embedded newlines."
// newline in "never for this site" address.
var failHost = "http://new\nline.never.net";
var error = null;
try {
storage.setLoginSavingEnabled(failHost, false);
} catch (e) {
error = e;
}
LoginTest.checkExpectedError(/Invalid hostname/, error);
// CR in "never for this site" address.
failHost = "http://new\rline.never.net";
error = null;
try {
storage.setLoginSavingEnabled(failHost, false);
} catch (e) {
error = e;
}
LoginTest.checkExpectedError(/Invalid hostname/, error);
// check hostname
failUser.hostname = "http://fail\nure.site.org";
tryAddUser(storage, failUser, /login values can't contain newlines/);
failUser.hostname = "http://fail\rure.site.org";
tryAddUser(storage, failUser, /login values can't contain newlines/);
failUser.hostname = "http://failure.site.org";
// check httpRealm and formSubmitURL
failUser.httpRealm = "http://fail\nure.site.org";
failUser.formSubmitURL = null;
tryAddUser(storage, failUser, /login values can't contain newlines/);
failUser.httpRealm = "http://fail\rure.site.org";
failUser.formSubmitURL = null;
tryAddUser(storage, failUser, /login values can't contain newlines/);
failUser.formSubmitURL = "http://fail\nure.site.org";
failUser.httpRealm = null;
tryAddUser(storage, failUser, /login values can't contain newlines/);
failUser.formSubmitURL = "http://fail\rure.site.org";
failUser.httpRealm = null;
tryAddUser(storage, failUser, /login values can't contain newlines/);
failUser.formSubmitURL = "http://failure.site.org";
// check usernameField
failUser.usernameField = "u\nname";
tryAddUser(storage, failUser, /login values can't contain newlines/);
failUser.usernameField = "u\rname";
tryAddUser(storage, failUser, /login values can't contain newlines/);
failUser.usernameField = "uname";
// check passwordField
failUser.passwordField = "p\nword";
tryAddUser(storage, failUser, /login values can't contain newlines/);
failUser.passwordField = "p\rword";
tryAddUser(storage, failUser, /login values can't contain newlines/);
failUser.passwordField = "pword";
// check username and password, which are OK with embedded newlines.
failUser.username = "user\r\nname";
failUser.password = "pass\r\nword";
tryAddUser(storage, failUser, null);
testdesc = "[flush and reload for verification]"
LoginTest.initStorage(storage, OUTDIR, "output-394610-1.txt");
LoginTest.checkStorageData(storage, [], [failUser]);
failUser.username = "username";
failUser.password = "password";
LoginTest.deleteFile(OUTDIR, "output-394610-1.sqlite");
/* ========== 11 ========== */
testnum++;
testdesc = "storing data values with special period-only value"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-394610-2.sqlite");
LoginTest.checkStorageData(storage, [], []);
failHost = ".";
error = null;
try {
storage.setLoginSavingEnabled(failHost, false);
} catch (e) {
error = e;
}
LoginTest.checkExpectedError(/Invalid hostname/, error);
// check usernameField
failUser.usernameField = ".";
tryAddUser(storage, failUser, /login values can't be periods/);
failUser.usernameField = "uname";
// check formSubmitURL
failUser.usernameField = ".";
tryAddUser(storage, failUser, /login values can't be periods/);
failUser.formSubmitURL = "http://failure.site.org";
testdesc = "check added data"
LoginTest.checkStorageData(storage, [], []);
testdesc = "[flush and reload for verification]"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-394610-2.sqlite");
LoginTest.checkStorageData(storage, [], []);
LoginTest.deleteFile(OUTDIR, "output-394610-2.sqlite");
/* ========== 12 ========== */
testnum++;
testdesc = "create logins with parens in host/httpRealm"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-394610-3.sqlite");
LoginTest.checkStorageData(storage, [], []);
var parenUser1 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var parenUser2 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var parenUser3 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var parenUser4 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var parenUser5 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var parenUser6 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var parenUser7 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var parenUser8 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var parenUser9 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
// realm as "(realm", "realm)", "(realm)", ")realm("
parenUser1.init("http://parens.site.org", null, "(realm",
"user1", "pass1", "uname", "pword");
parenUser2.init("http://parens.site.org", null, "realm)",
"user2", "pass2", "uname", "pword");
parenUser3.init("http://parens.site.org", null, "(realm)",
"user3", "pass3", "uname", "pword");
parenUser4.init("http://parens.site.org", null, ")realm(",
"user4", "pass4", "uname", "pword");
// hostname as "xx(xx", "xx)xx", "xx()xx", "xx)(xx"
parenUser5.init("http://parens(yay.site.org", null, "realm",
"user5", "pass5", "uname", "pword");
parenUser6.init("http://parens)yay.site.org", null, "realm",
"user6", "pass6", "uname", "pword");
parenUser7.init("http://parens(yay).site.org", null, "realm",
"user7", "pass7", "uname", "pword");
parenUser8.init("http://parens)yay(.site.org", null, "realm",
"user8", "pass8", "uname", "pword");
// "xx (xx" as a special case
parenUser9.init("http://parens (.site.org", null, "realm",
"user9", "pass9", "uname", "pword");
testdesc = "add logins with parens in host/httpRealm"
tryAddUser(storage, parenUser1, null);
tryAddUser(storage, parenUser2, null);
tryAddUser(storage, parenUser3, null);
tryAddUser(storage, parenUser4, null);
tryAddUser(storage, parenUser5, null);
tryAddUser(storage, parenUser6, null);
tryAddUser(storage, parenUser7, null);
tryAddUser(storage, parenUser8, null);
// we expect this one to fail.
tryAddUser(storage, parenUser9, /bad parens in hostname/);
var parenLogins = [
parenUser1, parenUser2, parenUser3, parenUser4,
parenUser5, parenUser6, parenUser7, parenUser8
];
testdesc = "check added data"
LoginTest.checkStorageData(storage, [], parenLogins);
testdesc = "[flush and reload for verification]"
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-394610-3.sqlite");
LoginTest.checkStorageData(storage, [], parenLogins);
LoginTest.deleteFile(OUTDIR, "output-394610-3.sqlite");
/* ========== 13 ========== */
testnum++;
testdesc = "storing data values with embedded nulls."
// sanity check
do_check_eq( "foo\0bar", "foo\0bar");
do_check_neq("foo\0bar", "foobar");
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-empty.txt",
OUTDIR, "output-394610-4.sqlite");
LoginTest.checkStorageData(storage, [], []);
var nullUser = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
nullUser.init("http://null.site.org",
"http://null.site.org", null,
"username", "password", "usernull", "passnull");
// null in "never for this site" address.
var nullHost = "http://never\0X.sit.org";
error = null;
try {
storage.setLoginSavingEnabled(nullHost, false);
} catch (e) {
error = e;
}
LoginTest.checkExpectedError(/Invalid hostname/, error);
// check hostname
nullUser.hostname = "http://null\0X.site.org";
tryAddUser(storage, nullUser, /login values can't contain nulls/);
nullUser.hostname = "http://null.site.org";
// check httpRealm and formSubmitURL
nullUser.httpRealm = "http://null\0X.site.org";
nullUser.formSubmitURL = null;
tryAddUser(storage, nullUser, /login values can't contain nulls/);
nullUser.formSubmitURL = "http://null\0X.site.org";
nullUser.httpRealm = null;
tryAddUser(storage, nullUser, /login values can't contain nulls/);
nullUser.formSubmitURL = "http://null.site.org";
// check usernameField
nullUser.usernameField = "usernull\0X";
tryAddUser(storage, nullUser, /login values can't contain nulls/);
nullUser.usernameField = "usernull";
// check usernameField with a special case value
nullUser.usernameField = ".\0";
tryAddUser(storage, nullUser, /login values can't contain nulls/);
nullUser.usernameField = "usernull";
// check passwordField
nullUser.passwordField = "passnull\0X";
tryAddUser(storage, nullUser, /login values can't contain nulls/);
nullUser.passwordField = "passnull";
// check username with null
nullUser.username = "user\0name";
tryAddUser(storage, nullUser, /login values can't contain nulls/);
nullUser.username = "username";
// check password with null
nullUser.password = "pass\0word";
tryAddUser(storage, nullUser, /login values can't contain nulls/);
nullUser.password = "password";
// Final sanity check, to make sure we didn't store anything unexpected.
LoginTest.checkStorageData(storage, [], []);
testdesc = "[flush and reload for verification]";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, "output-394610-4.sqlite");
LoginTest.checkStorageData(storage, [], []);
nullUser.username = "username";
nullUser.password = "password";
LoginTest.deleteFile(OUTDIR, "output-394610-4.sqlite");
/* ========== end ========== */
} catch (e) {
throw ("FAILED in test #" + testnum + " -- " + testdesc + ": " + e);
}
};

View File

@ -0,0 +1,136 @@
/*
* Test suite for storage-mozStorage.js -- mailnews specific tests.
*
* This test interfaces directly with the mozStorage login storage module,
* bypassing the normal login manager usage.
*
*/
const Cm = Components.manager;
const BASE_CONTRACTID = "@mozilla.org/network/protocol;1?name=";
const LDAPPH_CID = Components.ID("{08eebb58-8d1a-4ab5-9fca-e35372697828}");
const MAILBOXPH_CID = Components.ID("{edb1dea3-b226-405a-b93d-2a678a68a198}");
function genericProtocolHandler(scheme, defaultPort) {
this.scheme = scheme;
this.defaultPort = defaultPort;
}
genericProtocolHandler.prototype = {
scheme: "",
defaultPort: 0,
QueryInterface: function gph_QueryInterface(aIID) {
if (!aIID.equals(Ci.nsISupports) &&
!aIID.equals(Ci.nsIProtocolHandler)) {
throw Cr.NS_ERROR_NO_INTERFACE;
}
return this;
},
get protocolFlags() {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
newURI: function gph_newURI(aSpec, anOriginalCharset, aBaseURI) {
var uri = Components.classes["@mozilla.org/network/standard-url;1"].
createInstance(Ci.nsIStandardURL);
uri.init(Ci.nsIStandardURL.URLTYPE_STANDARD, this.defaultPort, aSpec,
anOriginalCharset, aBaseURI);
return uri;
},
newChannel: function gph_newChannel(aUri) {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
allowPort: function gph_allowPort(aPort, aScheme) {
return false;
}
}
function generateFactory(protocol, defaultPort)
{
return {
createInstance: function (outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return (new genericProtocolHandler(protocol, defaultPort)).
QueryInterface(iid);
}
};
}
function run_test() {
Cm.nsIComponentRegistrar.registerFactory(LDAPPH_CID, "LDAPProtocolFactory",
BASE_CONTRACTID + "ldap",
generateFactory("ldap", 389));
Cm.nsIComponentRegistrar.registerFactory(MAILBOXPH_CID,
"MailboxProtocolFactory",
BASE_CONTRACTID + "mailbox",
generateFactory("mailbox", 0));
try {
/* ========== 0 ========== */
var testnum = 0;
var testdesc = "Initial connection to storage module"
var storage = LoginTest.newMozStorage();
if (!storage)
throw "Couldn't create storage instance.";
// Create a couple of dummy users to match what we expect to be translated
// from the input file.
var dummyuser1 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var dummyuser2 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
var dummyuser3 = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
dummyuser1.init("mailbox://localhost", null, "mailbox://localhost",
"bugzilla", "testpass1", "", "");
dummyuser2.init("ldap://localhost1", null,
"ldap://localhost1/dc=test",
"", "testpass2", "", "");
dummyuser3.init("http://dummyhost.mozilla.org", "", null,
"testuser1", "testpass1", "put_user_here", "put_pw_here");
LoginTest.deleteFile(OUTDIR, "signons.sqlite");
/*
* ---------------------- Bug 403790 ----------------------
* Migrating mailnews style username/passwords
*/
/* ========== 1 ========== */
testnum++;
testdesc = "checking reading of mailnews-like old logins";
storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, INDIR, "signons-403790.txt",
OUTDIR, "output-403790.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser1, dummyuser2]);
storage.addLogin(dummyuser3); // trigger a write
LoginTest.checkStorageData(storage, [], [dummyuser1, dummyuser2, dummyuser3]);
testdesc = "[flush and reload for verification]";
LoginTest.initStorage(storage, null, null, OUTDIR, "output-403790.sqlite");
LoginTest.checkStorageData(storage, [], [dummyuser1, dummyuser2, dummyuser3]);
LoginTest.deleteFile(OUTDIR, "output-403790.sqlite");
/* ========== end ========== */
} catch (e) {
throw ("FAILED in test #" + testnum + " -- " + testdesc + ": " + e);
}
};

View File

@ -0,0 +1,123 @@
/*
* Test suite for storage-mozStorage.js -- expected initialization errors & fixes
* and database corruption.
*
* This test interfaces directly with the mozStorage login storage module,
* bypassing the normal login manager usage.
*
*/
function run_test() {
try {
/* ========== 0 ========== */
var testnum = 0;
var testdesc = "Initial connection to storage module"
var storage = LoginTest.newMozStorage();
if (!storage)
throw "Couldn't create storage instance.";
/* ========== 1 ========== */
testnum++;
var testdesc = "Create nsILoginInfo instances for testing with"
var nsLoginInfo = new Components.Constructor(
"@mozilla.org/login-manager/loginInfo;1",
Components.interfaces.nsILoginInfo);
var testuser1 = new nsLoginInfo;
testuser1.init("http://dummyhost.mozilla.org", "", null,
"dummydude", "itsasecret", "put_user_here", "put_pw_here");
LoginTest.deleteFile(OUTDIR, "signons.sqlite");
/*
* ---------------------- Initialization ----------------------
* Pass in a legacy file that has problems (bad header). On call to
* getAllLogins should throw "Initialization failed". We replace the bad file
* with a good one, and call getAllLogins again, which will attempt to import
* again and should succeed because it has a good file now.
*/
/* ========== 2 ========== */
testnum++;
var testdesc = "Initialization, reinitialization, & importing"
var storage = LoginTest.newMozStorage();
// signons-00.txt has bad header; use signons.sqlite
LoginTest.initStorage(storage, INDIR, "signons-00.txt");
try {
storage.getAllLogins({});
} catch (e) {
var error = e;
}
LoginTest.checkExpectedError(/Initialization failed/, error);
// Since initWithFile will not replace the DB if not passed one, we can just
// call LoginTest.initStorage with with signons-06.txt (1 disabled, 1 login).
// storage is already defined, so this is acceptable use (a bit hacky though)
LoginTest.initStorage(storage, INDIR, "signons-06.txt");
LoginTest.checkStorageData(storage, ["https://www.site.net"], [testuser1]);
LoginTest.deleteFile(OUTDIR, "signons.sqlite");
/*
* ---------------------- DB Corruption ----------------------
* Try to initialize with a corrupt database file. This should create a backup
* file, then upon next use create a new database file.
*/
/* ========== 3 ========== */
testnum++;
var testdesc = "Corrupt database and backup"
var filename = "signons-c";
// copy corrupt db to output directory
var corruptDB = do_get_file("toolkit/components/passwordmgr/test/unit/data/" +
"corruptDB.sqlite");
corruptDB.copyTo(PROFDIR, filename)
do_check_true(corruptDB.exists());
// will init mozStorage module with default filename.
var storage = LoginTest.newMozStorage();
LoginTest.initStorage(storage, null, null, OUTDIR, filename);
try {
storage.getAllLogins({});
} catch (e) {
var error = e;
}
LoginTest.checkExpectedError(/Initialization failed/, error);
// check that the backup file exists
var buFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
buFile.initWithPath(OUTDIR);
buFile.append(filename + ".corrupt");
do_check_true(buFile.exists());
// use the storage module again, should work now
storage.addLogin(testuser1);
LoginTest.checkStorageData(storage, [], [testuser1]);
// check the file exists
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(OUTDIR);
file.append(filename);
do_check_true(file.exists());
LoginTest.deleteFile(OUTDIR, filename + ".corrupt");
LoginTest.deleteFile(OUTDIR, filename);
/* ========== end ========== */
} catch (e) {
throw ("FAILED in test #" + testnum + " -- " + testdesc + ": " + e);
}
};