1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/services/sync/tests/unit/test_collections_recovery.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Verify that we wipe the server if we have to regenerate keys. 1.8 +Cu.import("resource://services-sync/service.js"); 1.9 +Cu.import("resource://services-sync/util.js"); 1.10 +Cu.import("resource://testing-common/services/sync/utils.js"); 1.11 + 1.12 +add_identity_test(this, function test_missing_crypto_collection() { 1.13 + let johnHelper = track_collections_helper(); 1.14 + let johnU = johnHelper.with_updated_collection; 1.15 + let johnColls = johnHelper.collections; 1.16 + 1.17 + let empty = false; 1.18 + function maybe_empty(handler) { 1.19 + return function (request, response) { 1.20 + if (empty) { 1.21 + let body = "{}"; 1.22 + response.setStatusLine(request.httpVersion, 200, "OK"); 1.23 + response.bodyOutputStream.write(body, body.length); 1.24 + } else { 1.25 + handler(request, response); 1.26 + } 1.27 + }; 1.28 + } 1.29 + 1.30 + yield configureIdentity({username: "johndoe"}); 1.31 + 1.32 + let handlers = { 1.33 + "/1.1/johndoe/info/collections": maybe_empty(johnHelper.handler), 1.34 + "/1.1/johndoe/storage/crypto/keys": johnU("crypto", new ServerWBO("keys").handler()), 1.35 + "/1.1/johndoe/storage/meta/global": johnU("meta", new ServerWBO("global").handler()) 1.36 + }; 1.37 + let collections = ["clients", "bookmarks", "forms", "history", 1.38 + "passwords", "prefs", "tabs"]; 1.39 + for each (let coll in collections) { 1.40 + handlers["/1.1/johndoe/storage/" + coll] = 1.41 + johnU(coll, new ServerCollection({}, true).handler()); 1.42 + } 1.43 + let server = httpd_setup(handlers); 1.44 + Service.serverURL = server.baseURI; 1.45 + 1.46 + try { 1.47 + let fresh = 0; 1.48 + let orig = Service._freshStart; 1.49 + Service._freshStart = function() { 1.50 + _("Called _freshStart."); 1.51 + orig.call(Service); 1.52 + fresh++; 1.53 + }; 1.54 + 1.55 + _("Startup, no meta/global: freshStart called once."); 1.56 + Service.sync(); 1.57 + do_check_eq(fresh, 1); 1.58 + fresh = 0; 1.59 + 1.60 + _("Regular sync: no need to freshStart."); 1.61 + Service.sync(); 1.62 + do_check_eq(fresh, 0); 1.63 + 1.64 + _("Simulate a bad info/collections."); 1.65 + delete johnColls.crypto; 1.66 + Service.sync(); 1.67 + do_check_eq(fresh, 1); 1.68 + fresh = 0; 1.69 + 1.70 + _("Regular sync: no need to freshStart."); 1.71 + Service.sync(); 1.72 + do_check_eq(fresh, 0); 1.73 + 1.74 + } finally { 1.75 + Svc.Prefs.resetBranch(""); 1.76 + let deferred = Promise.defer(); 1.77 + server.stop(deferred.resolve); 1.78 + yield deferred.promise; 1.79 + } 1.80 +}); 1.81 + 1.82 +function run_test() { 1.83 + initTestLogging("Trace"); 1.84 + run_next_test(); 1.85 +}