--- a/toolkit/components/passwordmgr/test/unit/test_storage_mozStorage.js
+++ b/toolkit/components/passwordmgr/test/unit/test_storage_mozStorage.js
@@ -1,20 +1,21 @@
/*
* This test interfaces directly with the mozStorage password storage module,
* bypassing the normal password manager usage.
*/
const ENCTYPE_BASE64 = 0;
const ENCTYPE_SDR = 1;
+const PERMISSION_TYPE_LOGIN = "login-saved";
// Current schema version used by storage-mozStorage.js. This will need to be
// kept in sync with the version there (or else the tests fail).
-const CURRENT_SCHEMA = 5;
+const CURRENT_SCHEMA = 6;
function* copyFile(aLeafName)
{
yield OS.File.copy(OS.Path.join(do_get_file("data").path, aLeafName),
OS.Path.join(OS.Constants.Path.profileDir, aLeafName));
}
function openDB(aLeafName)
@@ -124,17 +125,19 @@ testdesc = "Test downgrade from v999 sto
yield* copyFile("signons-v999.sqlite");
// Verify the schema version in the test file.
dbConnection = openDB("signons-v999.sqlite");
do_check_eq(999, dbConnection.schemaVersion);
dbConnection.close();
storage = reloadStorage(OUTDIR, "signons-v999.sqlite");
+storage.setLoginSavingEnabled("https://disabled.net", false);
checkStorageData(storage, ["https://disabled.net"], [testuser1]);
+storage.setLoginSavingEnabled("https://disabled.net", true);
// Check to make sure we downgraded the schema version.
dbConnection = openDB("signons-v999.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
dbConnection.close();
deleteFile(OUTDIR, "signons-v999.sqlite");
@@ -165,17 +168,19 @@ testdesc = "Test upgrade from v1->v2 sto
yield* copyFile("signons-v1.sqlite");
// Sanity check the test file.
dbConnection = openDB("signons-v1.sqlite");
do_check_eq(1, dbConnection.schemaVersion);
dbConnection.close();
storage = reloadStorage(OUTDIR, "signons-v1.sqlite");
+storage.setLoginSavingEnabled("https://disabled.net", false);
checkStorageData(storage, ["https://disabled.net"], [testuser1, testuser2]);
+storage.setLoginSavingEnabled("https://disabled.net", true);
// Check to see that we added a GUIDs to the logins.
dbConnection = openDB("signons-v1.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
var guid = getGUIDforID(dbConnection, 1);
do_check_true(isGUID.test(guid));
guid = getGUIDforID(dbConnection, 2);
do_check_true(isGUID.test(guid));
@@ -192,22 +197,26 @@ testdesc = "Test upgrade v2->v1 storage"
yield* copyFile("signons-v1v2.sqlite");
// Sanity check the test file.
dbConnection = openDB("signons-v1v2.sqlite");
do_check_eq(1, dbConnection.schemaVersion);
dbConnection.close();
storage = reloadStorage(OUTDIR, "signons-v1v2.sqlite");
+storage.setLoginSavingEnabled("https://disabled.net", false);
checkStorageData(storage, ["https://disabled.net"], [testuser1, testuser2, testuser3]);
+storage.setLoginSavingEnabled("https://disabled.net", true);
// While we're here, try modifying a login, to ensure that doing so doesn't
// change the existing GUID.
storage.modifyLogin(testuser1, testuser1B);
+storage.setLoginSavingEnabled("https://disabled.net", false);
checkStorageData(storage, ["https://disabled.net"], [testuser1B, testuser2, testuser3]);
+storage.setLoginSavingEnabled("https://disabled.net", true);
// Check the GUIDs. Logins 1 and 2 should retain their original GUID, login 3
// should have one created (because it didn't have one previously).
dbConnection = openDB("signons-v1v2.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
guid = getGUIDforID(dbConnection, 1);
do_check_eq("{655c7358-f1d6-6446-adab-53f98ac5d80f}", guid);
guid = getGUIDforID(dbConnection, 2);
@@ -233,18 +242,20 @@ storage = reloadStorage(OUTDIR, "signons
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
var encTypes = [ENCTYPE_BASE64, ENCTYPE_SDR, ENCTYPE_BASE64, ENCTYPE_BASE64];
for (let i = 0; i < encTypes.length; i++)
do_check_eq(encTypes[i], getEncTypeForID(dbConnection, i + 1));
dbConnection.close();
// There are 4 logins, but 3 will be invalid because we can no longer decrypt
// base64-encoded items. (testuser1/4/5)
+storage.setLoginSavingEnabled("https://disabled.net", false);
checkStorageData(storage, ["https://disabled.net"],
[testuser2]);
+storage.setLoginSavingEnabled("https://disabled.net", true);
deleteFile(OUTDIR, "signons-v2.sqlite");
/* ========== 6 ========== */
testnum++;
testdesc = "Test upgrade v3->v2 storage";
// This is the case where a v3 DB has been accessed with v2 code, and now we
// are upgrading it again. Any logins added by the v2 code must be properly
@@ -264,17 +275,19 @@ do_check_eq(CURRENT_SCHEMA, dbConnection
encTypes = [ENCTYPE_BASE64, ENCTYPE_SDR, ENCTYPE_BASE64, ENCTYPE_BASE64, ENCTYPE_SDR];
for (let i = 0; i < encTypes.length; i++)
do_check_eq(encTypes[i], getEncTypeForID(dbConnection, i + 1));
// Sanity check that the data gets migrated
// There are 5 logins, but 3 will be invalid because we can no longer decrypt
// base64-encoded items. (testuser1/4/5). We no longer reencrypt with SDR.
+storage.setLoginSavingEnabled("https://disabled.net", false);
checkStorageData(storage, ["https://disabled.net"], [testuser2, testuser3]);
+storage.setLoginSavingEnabled("https://disabled.net", true);
encTypes = [ENCTYPE_BASE64, ENCTYPE_SDR, ENCTYPE_BASE64, ENCTYPE_BASE64, ENCTYPE_SDR];
for (let i = 0; i < encTypes.length; i++)
do_check_eq(encTypes[i], getEncTypeForID(dbConnection, i + 1));
dbConnection.close();
deleteFile(OUTDIR, "signons-v2v3.sqlite");
@@ -366,33 +379,64 @@ yield copyFile("signons-v4v5.sqlite");
dbConnection = openDB("signons-v4v5.sqlite");
do_check_eq(4, dbConnection.schemaVersion);
do_check_true(dbConnection.tableExists("moz_deleted_logins"));
storage = reloadStorage(OUTDIR, "signons-v4v5.sqlite");
do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
do_check_true(dbConnection.tableExists("moz_deleted_logins"));
+/* ========== 11 ========== */
+testnum++;
+testdesc = "Test upgrade from v4->v6 storage" // TODO: Should be v5->v6
-/* ========== 11 ========== */
+yield* copyFile("signons-v4.sqlite");
+
+// Sanity check the test file.
+dbConnection = openDB("signons-v4.sqlite");
+do_check_eq(4, dbConnection.schemaVersion);
+do_check_true(dbConnection.tableExists("moz_disabledHosts"));
+
+storage = reloadStorage(OUTDIR, "signons-v4.sqlite");
+do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
+do_check_true(dbConnection.tableExists("moz_disabledHosts"));
+
+let dummyURL = "http://dummy.mozilla.org"
+let dummyURL2 = "http://dummy2.mozilla.org"
+
+storage.setLoginSavingEnabled(dummyURL, false);
+storage.setLoginSavingEnabled(dummyURL2, false);
+do_check_false(storage.getLoginSavingEnabled(dummyURL));
+do_check_false(storage.getLoginSavingEnabled(dummyURL2));
+
+LoginTestUtils.assertDisabledHostsEqual(storage.getAllDisabledHosts(),
+ [dummyURL, dummyURL2]);
+
+storage.setLoginSavingEnabled(dummyURL, true);
+storage.setLoginSavingEnabled(dummyURL2, true);
+do_check_true(storage.getLoginSavingEnabled(dummyURL));
+do_check_true(storage.getLoginSavingEnabled(dummyURL2));
+
+
+/* ========== 12 ========== */
testnum++;
testdesc = "Create nsILoginInfo instances for testing with"
testuser1 = new nsLoginInfo;
testuser1.init("http://dummyhost.mozilla.org", "", null,
"dummydude", "itsasecret", "put_user_here", "put_pw_here");
/*
* ---------------------- 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.
*/
-/* ========== 12 ========== */
+/* ========== 13 ========== */
testnum++;
testdesc = "Corrupt database and backup"
const filename = "signons-c.sqlite";
const filepath = OS.Path.join(OS.Constants.Path.profileDir, filename);
yield OS.File.copy(do_get_file("data/corruptDB.sqlite").path, filepath);