services/sync/tests/unit/test_collections_recovery.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Verify that we wipe the server if we have to regenerate keys.
     5 Cu.import("resource://services-sync/service.js");
     6 Cu.import("resource://services-sync/util.js");
     7 Cu.import("resource://testing-common/services/sync/utils.js");
     9 add_identity_test(this, function test_missing_crypto_collection() {
    10   let johnHelper = track_collections_helper();
    11   let johnU      = johnHelper.with_updated_collection;
    12   let johnColls  = johnHelper.collections;
    14   let empty = false;
    15   function maybe_empty(handler) {
    16     return function (request, response) {
    17       if (empty) {
    18         let body = "{}";
    19         response.setStatusLine(request.httpVersion, 200, "OK");
    20         response.bodyOutputStream.write(body, body.length);
    21       } else {
    22         handler(request, response);
    23       }
    24     };
    25   }
    27   yield configureIdentity({username: "johndoe"});
    29   let handlers = {
    30     "/1.1/johndoe/info/collections": maybe_empty(johnHelper.handler),
    31     "/1.1/johndoe/storage/crypto/keys": johnU("crypto", new ServerWBO("keys").handler()),
    32     "/1.1/johndoe/storage/meta/global": johnU("meta",   new ServerWBO("global").handler())
    33   };
    34   let collections = ["clients", "bookmarks", "forms", "history",
    35                      "passwords", "prefs", "tabs"];
    36   for each (let coll in collections) {
    37     handlers["/1.1/johndoe/storage/" + coll] =
    38       johnU(coll, new ServerCollection({}, true).handler());
    39   }
    40   let server = httpd_setup(handlers);
    41   Service.serverURL = server.baseURI;
    43   try {
    44     let fresh = 0;
    45     let orig  = Service._freshStart;
    46     Service._freshStart = function() {
    47       _("Called _freshStart.");
    48       orig.call(Service);
    49       fresh++;
    50     };
    52     _("Startup, no meta/global: freshStart called once.");
    53     Service.sync();
    54     do_check_eq(fresh, 1);
    55     fresh = 0;
    57     _("Regular sync: no need to freshStart.");
    58     Service.sync();
    59     do_check_eq(fresh, 0);
    61     _("Simulate a bad info/collections.");
    62     delete johnColls.crypto;
    63     Service.sync();
    64     do_check_eq(fresh, 1);
    65     fresh = 0;
    67     _("Regular sync: no need to freshStart.");
    68     Service.sync();
    69     do_check_eq(fresh, 0);
    71   } finally {
    72     Svc.Prefs.resetBranch("");
    73     let deferred = Promise.defer();
    74     server.stop(deferred.resolve);
    75     yield deferred.promise;
    76   }
    77 });
    79 function run_test() {
    80   initTestLogging("Trace");
    81   run_next_test();
    82 }

mercurial