|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
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"); |
|
8 |
|
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; |
|
13 |
|
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 } |
|
26 |
|
27 yield configureIdentity({username: "johndoe"}); |
|
28 |
|
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; |
|
42 |
|
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 }; |
|
51 |
|
52 _("Startup, no meta/global: freshStart called once."); |
|
53 Service.sync(); |
|
54 do_check_eq(fresh, 1); |
|
55 fresh = 0; |
|
56 |
|
57 _("Regular sync: no need to freshStart."); |
|
58 Service.sync(); |
|
59 do_check_eq(fresh, 0); |
|
60 |
|
61 _("Simulate a bad info/collections."); |
|
62 delete johnColls.crypto; |
|
63 Service.sync(); |
|
64 do_check_eq(fresh, 1); |
|
65 fresh = 0; |
|
66 |
|
67 _("Regular sync: no need to freshStart."); |
|
68 Service.sync(); |
|
69 do_check_eq(fresh, 0); |
|
70 |
|
71 } finally { |
|
72 Svc.Prefs.resetBranch(""); |
|
73 let deferred = Promise.defer(); |
|
74 server.stop(deferred.resolve); |
|
75 yield deferred.promise; |
|
76 } |
|
77 }); |
|
78 |
|
79 function run_test() { |
|
80 initTestLogging("Trace"); |
|
81 run_next_test(); |
|
82 } |