michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Verify that we wipe the server if we have to regenerate keys. michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: Cu.import("resource://testing-common/services/sync/utils.js"); michael@0: michael@0: add_identity_test(this, function test_missing_crypto_collection() { michael@0: let johnHelper = track_collections_helper(); michael@0: let johnU = johnHelper.with_updated_collection; michael@0: let johnColls = johnHelper.collections; michael@0: michael@0: let empty = false; michael@0: function maybe_empty(handler) { michael@0: return function (request, response) { michael@0: if (empty) { michael@0: let body = "{}"; michael@0: response.setStatusLine(request.httpVersion, 200, "OK"); michael@0: response.bodyOutputStream.write(body, body.length); michael@0: } else { michael@0: handler(request, response); michael@0: } michael@0: }; michael@0: } michael@0: michael@0: yield configureIdentity({username: "johndoe"}); michael@0: michael@0: let handlers = { michael@0: "/1.1/johndoe/info/collections": maybe_empty(johnHelper.handler), michael@0: "/1.1/johndoe/storage/crypto/keys": johnU("crypto", new ServerWBO("keys").handler()), michael@0: "/1.1/johndoe/storage/meta/global": johnU("meta", new ServerWBO("global").handler()) michael@0: }; michael@0: let collections = ["clients", "bookmarks", "forms", "history", michael@0: "passwords", "prefs", "tabs"]; michael@0: for each (let coll in collections) { michael@0: handlers["/1.1/johndoe/storage/" + coll] = michael@0: johnU(coll, new ServerCollection({}, true).handler()); michael@0: } michael@0: let server = httpd_setup(handlers); michael@0: Service.serverURL = server.baseURI; michael@0: michael@0: try { michael@0: let fresh = 0; michael@0: let orig = Service._freshStart; michael@0: Service._freshStart = function() { michael@0: _("Called _freshStart."); michael@0: orig.call(Service); michael@0: fresh++; michael@0: }; michael@0: michael@0: _("Startup, no meta/global: freshStart called once."); michael@0: Service.sync(); michael@0: do_check_eq(fresh, 1); michael@0: fresh = 0; michael@0: michael@0: _("Regular sync: no need to freshStart."); michael@0: Service.sync(); michael@0: do_check_eq(fresh, 0); michael@0: michael@0: _("Simulate a bad info/collections."); michael@0: delete johnColls.crypto; michael@0: Service.sync(); michael@0: do_check_eq(fresh, 1); michael@0: fresh = 0; michael@0: michael@0: _("Regular sync: no need to freshStart."); michael@0: Service.sync(); michael@0: do_check_eq(fresh, 0); michael@0: michael@0: } finally { michael@0: Svc.Prefs.resetBranch(""); michael@0: let deferred = Promise.defer(); michael@0: server.stop(deferred.resolve); michael@0: yield deferred.promise; michael@0: } michael@0: }); michael@0: michael@0: function run_test() { michael@0: initTestLogging("Trace"); michael@0: run_next_test(); michael@0: }