Bug 1162205 - Don't import encrypted cookies from Chrome. r=mak a=lmandel
Includes https://hg.mozilla.org/mozilla-central/raw-diff/0ac453f0a1f6/browser/components/migration/tests/unit/head_migration.js
This commit is contained in:
@@ -307,8 +307,11 @@ function GetCookiesResource(aProfileFolder) {
|
||||
|
||||
migrate: function(aCallback) {
|
||||
let dbConn = Services.storage.openUnsharedDatabase(cookiesFile);
|
||||
let stmt = dbConn.createAsyncStatement(
|
||||
"SELECT host_key, path, name, value, secure, httponly, expires_utc FROM cookies");
|
||||
// We don't support decrypting cookies yet so only import plaintext ones.
|
||||
let stmt = dbConn.createAsyncStatement(`
|
||||
SELECT host_key, name, value, path, expires_utc, secure, httponly, encrypted_value
|
||||
FROM cookies
|
||||
WHERE length(encrypted_value) = 0`);
|
||||
|
||||
stmt.executeAsync({
|
||||
handleResult : function(aResults) {
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"profile" : {
|
||||
"info_cache" : {
|
||||
"Default" : {
|
||||
"active_time" : 1430950755.65137,
|
||||
"is_using_default_name" : true,
|
||||
"is_ephemeral" : false,
|
||||
"is_omitted_from_profile_list" : false,
|
||||
"user_name" : "",
|
||||
"background_apps" : false,
|
||||
"is_using_default_avatar" : true,
|
||||
"avatar_icon" : "chrome://theme/IDR_PROFILE_AVATAR_0",
|
||||
"name" : "Person 1"
|
||||
}
|
||||
},
|
||||
"profiles_created" : 1,
|
||||
"last_used" : "Default",
|
||||
"last_active_profiles" : [
|
||||
"Default"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,10 @@ updateAppInfo();
|
||||
/**
|
||||
* Migrates the requested resource and waits for the migration to be complete.
|
||||
*/
|
||||
function promiseMigration(migrator, resourceType) {
|
||||
function promiseMigration(migrator, resourceType, aProfile = null) {
|
||||
// Ensure resource migration is available.
|
||||
let availableSources = migrator.getMigrateData(null, false);
|
||||
Assert.ok((availableSources & resourceType) > 0);
|
||||
let availableSources = migrator.getMigrateData(aProfile, false);
|
||||
Assert.ok((availableSources & resourceType) > 0, "Resource supported by migrator");
|
||||
|
||||
return new Promise (resolve => {
|
||||
Services.obs.addObserver(function onMigrationEnded() {
|
||||
@@ -32,6 +32,29 @@ function promiseMigration(migrator, resourceType) {
|
||||
resolve();
|
||||
}, "Migration:Ended", false);
|
||||
|
||||
migrator.migrate(resourceType, null, null);
|
||||
migrator.migrate(resourceType, null, aProfile);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces a directory service entry with a given nsIFile.
|
||||
*/
|
||||
function registerFakePath(key, file) {
|
||||
// Register our own provider for the Library directory.
|
||||
let provider = {
|
||||
getFile(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == key) {
|
||||
return file;
|
||||
}
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: XPCOMUtils.generateQI([ Ci.nsIDirectoryServiceProvider ])
|
||||
};
|
||||
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService)
|
||||
.registerProvider(provider);
|
||||
do_register_cleanup(() => {
|
||||
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService)
|
||||
.unregisterProvider(provider);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
Cu.import("resource://gre/modules/ForgetAboutSite.jsm");
|
||||
|
||||
add_task(function* () {
|
||||
registerFakePath("ULibDir", do_get_file("Library/"));
|
||||
let migrator = MigrationUtils.getMigrator("chrome");
|
||||
|
||||
Assert.ok(migrator.sourceExists, "Sanity check the source exists");
|
||||
|
||||
const COOKIE = {
|
||||
expiry: 2145934800,
|
||||
host: "unencryptedcookie.invalid",
|
||||
isHttpOnly: false,
|
||||
isSession: false,
|
||||
name: "testcookie",
|
||||
path: "/",
|
||||
value: "testvalue",
|
||||
};
|
||||
|
||||
// Sanity check.
|
||||
Assert.equal(Services.cookies.countCookiesFromHost(COOKIE.host), 0,
|
||||
"There are no cookies initially");
|
||||
|
||||
const PROFILE = {
|
||||
id: "Default",
|
||||
name: "Person 1",
|
||||
};
|
||||
|
||||
// Migrate unencrypted cookies.
|
||||
yield promiseMigration(migrator, MigrationUtils.resourceTypes.COOKIES, PROFILE);
|
||||
|
||||
do_register_cleanup(() => {
|
||||
ForgetAboutSite.removeDataFromDomain(COOKIE.host);
|
||||
Assert.equal(Services.cookies.countCookiesFromHost(COOKIE.host), 0,
|
||||
"There are no cookies after cleanup");
|
||||
});
|
||||
Assert.equal(Services.cookies.countCookiesFromHost(COOKIE.host), 1,
|
||||
"Migrated the expected number of unencrypted cookies");
|
||||
Assert.equal(Services.cookies.countCookiesFromHost("encryptedcookie.invalid"), 0,
|
||||
"Migrated the expected number of encrypted cookies");
|
||||
|
||||
// Now check the cookie details.
|
||||
let enumerator = Services.cookies.getCookiesFromHost(COOKIE.host);
|
||||
Assert.ok(enumerator.hasMoreElements(), "Cookies available");
|
||||
let foundCookie = enumerator.getNext().QueryInterface(Ci.nsICookie2);
|
||||
|
||||
for (let prop of Object.keys(COOKIE)) {
|
||||
Assert.equal(foundCookie[prop], COOKIE[prop], "Check cookie " + prop);
|
||||
}
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
@@ -3,7 +3,11 @@ head = head_migration.js
|
||||
tail =
|
||||
firefox-appdir = browser
|
||||
skip-if = toolkit == 'android' || toolkit == 'gonk'
|
||||
support-files =
|
||||
Library/**
|
||||
|
||||
[test_Chrome_cookies.js]
|
||||
skip-if = os != "mac" # Relies on ULibDir
|
||||
[test_fx_fhr.js]
|
||||
[test_IE_bookmarks.js]
|
||||
skip-if = os != "win"
|
||||
|
||||
Reference in New Issue
Block a user