From d9997307e29cf509bac7dd346265734d9faa5135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Mon, 13 Jul 2009 13:35:55 -0700 Subject: [PATCH] Bug 500822 - Importing passwords to mozstorage can fail when signons3.txt is corrupted, r=dolske --- .../passwordmgr/src/storage-mozStorage.js | 9 +++-- .../test/unit/data/signons-500822-1.txt | 33 +++++++++++++++++++ .../test/unit/test_storage_mozStorage_1.js | 28 ++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 toolkit/components/passwordmgr/test/unit/data/signons-500822-1.txt diff --git a/toolkit/components/passwordmgr/src/storage-mozStorage.js b/toolkit/components/passwordmgr/src/storage-mozStorage.js index 65fc72b4ae95..a4ba233ae005 100644 --- a/toolkit/components/passwordmgr/src/storage-mozStorage.js +++ b/toolkit/components/passwordmgr/src/storage-mozStorage.js @@ -1015,8 +1015,13 @@ LoginManagerStorage_mozStorage.prototype = { // Wrap in a transaction for better performance. this._dbConnection.beginTransaction(); - for each (let login in logins) - this._addLogin(login, true); + for each (let login in logins) { + try { + this._addLogin(login, true); + } catch (e) { + this.log("_importLegacySignons failed to add login: " + e); + } + } let disabledHosts = legacy.getAllDisabledHosts({}); for each (let hostname in disabledHosts) this.setLoginSavingEnabled(hostname, false); diff --git a/toolkit/components/passwordmgr/test/unit/data/signons-500822-1.txt b/toolkit/components/passwordmgr/test/unit/data/signons-500822-1.txt new file mode 100644 index 000000000000..35579bac18ab --- /dev/null +++ b/toolkit/components/passwordmgr/test/unit/data/signons-500822-1.txt @@ -0,0 +1,33 @@ +#2e +. +http://dummyhost.mozilla.org +put_user_here +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X +*put_pw_here +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR + +. +http://dummyhost2.mozilla.org +put_user_here2 +*MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X +*put_pw_here2 +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR +--- +put_user_here3 +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X +*put_pw_here3 +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR + +put_user_here +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X +*put_pw_here4 +*MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR +. +http://dummyhost4.mozilla.org + +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X +*password +MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR + +. diff --git a/toolkit/components/passwordmgr/test/unit/test_storage_mozStorage_1.js b/toolkit/components/passwordmgr/test/unit/test_storage_mozStorage_1.js index fbdac9550e02..33ecd8e0a5b8 100644 --- a/toolkit/components/passwordmgr/test/unit/test_storage_mozStorage_1.js +++ b/toolkit/components/passwordmgr/test/unit/test_storage_mozStorage_1.js @@ -266,6 +266,34 @@ LoginTest.checkStorageData(storage, [], [testuser1]); LoginTest.deleteFile(OUTDIR, "signons-427033-1.sqlite"); +/* + * ---------------------- Bug 500822 ---------------------- + * Importing passwords to mozstorage can fail when signons3.txt is corrupted. + */ + + +/* ========== 13 ========== */ +testnum++; + +testdesc = "checking import of partially corrupted signons3.txt" + +testuser1.init("http://dummyhost.mozilla.org", "", null, + "dummydude", "itsasecret", "put_user_here", "put_pw_here"); +storage = LoginTest.initStorage(INDIR, "signons-500822-1.txt", + OUTDIR, "signons-500822-1.sqlite"); + +// Using searchLogins to check that we have the correct first entry. Tests for +// searchLogin are in test_storage_mozStorage_7.js. Other entries may be +// corrupted, but we need to check for one valid login. +let matchData = Cc["@mozilla.org/hash-property-bag;1"].createInstance(Ci.nsIWritablePropertyBag2); +matchData.setPropertyAsAString("hostname", "http://dummyhost.mozilla.org"); +matchData.setPropertyAsAString("usernameField", "put_user_here"); +logins = storage.searchLogins({}, matchData); +do_check_eq(1, logins.length, "should match 1 login"); + +LoginTest.deleteFile(OUTDIR, "signons-500822-1.sqlite"); + + } catch (e) { throw "FAILED in test #" + testnum + " -- " + testdesc + ": " + e; }