зеркало из https://github.com/mozilla/gecko-dev.git
Bug 614737: detecting upgrade, being nice to old clients. r=philikon
This commit is contained in:
Родитель
f0b19a496e
Коммит
f35aba613e
|
@ -1699,14 +1699,26 @@ WeaveSvc.prototype = {
|
|||
*
|
||||
* @param collections [optional]
|
||||
* Array of collections to wipe. If not given, all collections are wiped.
|
||||
*
|
||||
* @param includeKeys [optional]
|
||||
* If true, keys/pubkey and keys/privkey are deleted from the server.
|
||||
* This is false by default, which will cause the usual upgrade paths
|
||||
* to leave those keys on the server. This is to solve Bug 614737: old
|
||||
* clients check for keys *before* checking storage versions.
|
||||
*
|
||||
* Note that this parameter only has an effect if `collections` is not
|
||||
* passed. If you explicitly pass a list of collections, they will be
|
||||
* processed regardless of the value of `includeKeys`.
|
||||
*/
|
||||
wipeServer: function WeaveSvc_wipeServer(collections)
|
||||
wipeServer: function wipeServer(collections, includeKeyPairs)
|
||||
this._notify("wipe-server", "", function() {
|
||||
if (!collections) {
|
||||
collections = [];
|
||||
let info = new Resource(this.infoURL).get();
|
||||
for (let name in info.obj)
|
||||
collections.push(name);
|
||||
for (let name in info.obj) {
|
||||
if (includeKeyPairs || (name != "keys"))
|
||||
collections.push(name);
|
||||
}
|
||||
}
|
||||
for each (let name in collections) {
|
||||
let url = this.storageURL + name;
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
Cu.import("resource://services-sync/main.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://services-sync/status.js");
|
||||
Cu.import("resource://services-sync/constants.js");
|
||||
Cu.import("resource://services-sync/base_records/wbo.js"); // For Records.
|
||||
Cu.import("resource://services-sync/base_records/crypto.js"); // For CollectionKeys.
|
||||
Cu.import("resource://services-sync/log4moz.js");
|
||||
|
||||
function run_test() {
|
||||
let passphrase = "abcdeabcdeabcdeabcdeabcdea";
|
||||
let logger = Log4Moz.repository.rootLogger;
|
||||
Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
|
||||
|
||||
let clients = new ServerCollection();
|
||||
let meta_global = new ServerWBO('global');
|
||||
|
||||
let collections = {};
|
||||
function info_collections(request, response) {
|
||||
let body = JSON.stringify(collections);
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
do_test_pending();
|
||||
let server = httpd_setup({
|
||||
"/1.0/johndoe/storage/crypto/keys": new ServerWBO().handler(),
|
||||
"/1.0/johndoe/storage/clients": clients.handler(),
|
||||
"/1.0/johndoe/storage/meta/global": meta_global.handler(),
|
||||
"/1.0/johndoe/info/collections": info_collections
|
||||
});
|
||||
|
||||
try {
|
||||
Weave.Service.serverURL = "http://localhost:8080/";
|
||||
Weave.Service.clusterURL = "http://localhost:8080/";
|
||||
|
||||
Weave.Service.login("johndoe", "ilovejane", passphrase);
|
||||
do_check_true(Weave.Service.isLoggedIn);
|
||||
Weave.Service.verifyAndFetchSymmetricKeys();
|
||||
do_check_true(Weave.Service._remoteSetup());
|
||||
|
||||
function test_out_of_date() {
|
||||
_("meta_global: " + JSON.stringify(meta_global));
|
||||
meta_global.payload = {"syncID": "foooooooooooooooooooooooooo",
|
||||
"storageVersion": STORAGE_VERSION + 1};
|
||||
_("meta_global: " + JSON.stringify(meta_global));
|
||||
Records.set(Weave.Service.metaURL, meta_global);
|
||||
try {
|
||||
Weave.Service.sync();
|
||||
}
|
||||
catch (ex) {
|
||||
}
|
||||
do_check_eq(Status.sync, VERSION_OUT_OF_DATE);
|
||||
}
|
||||
|
||||
// See what happens when we bump the storage version.
|
||||
_("Syncing after server has been upgraded.");
|
||||
test_out_of_date();
|
||||
|
||||
// Same should happen after a wipe.
|
||||
_("Syncing after server has been upgraded and wiped.");
|
||||
Weave.Service.wipeServer();
|
||||
test_out_of_date();
|
||||
|
||||
} finally {
|
||||
Weave.Svc.Prefs.resetBranch("");
|
||||
server.stop(do_test_finished);
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ function setUpTestFixtures() {
|
|||
|
||||
Service.clusterURL = "http://localhost:8080/";
|
||||
Service.username = "johndoe";
|
||||
Service.passphrase = "secret";
|
||||
Service.passphrase = "aabcdeabcdeabcdeabcdeabcde";
|
||||
}
|
||||
|
||||
function test_withCollectionList_fail() {
|
||||
|
@ -77,6 +77,68 @@ function test_withCollectionList_fail() {
|
|||
}
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
test_withCollectionList_fail();
|
||||
function test_wipeServer_leaves_collections() {
|
||||
_("Service.wipeServer() deletes everything but keys.");
|
||||
|
||||
let steam_coll = new FakeCollection();
|
||||
let diesel_coll = new FakeCollection();
|
||||
let keys_coll = new FakeCollection();
|
||||
|
||||
function info_collections(request, response) {
|
||||
let collections = {};
|
||||
let timestamp = Date.now() / 1000;
|
||||
if (!steam_coll.deleted)
|
||||
collections.steam = timestamp
|
||||
if (!diesel_coll.deleted)
|
||||
collections.diesel = timestamp;
|
||||
if (!keys_coll.deleted)
|
||||
collections.keys = timestamp;
|
||||
let body = JSON.stringify(collections);
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
let server = httpd_setup({
|
||||
"/1.0/johndoe/storage/steam": steam_coll.handler(),
|
||||
"/1.0/johndoe/storage/diesel": diesel_coll.handler(),
|
||||
"/1.0/johndoe/storage/keys": keys_coll.handler(),
|
||||
"/1.0/johndoe/info/collections": info_collections
|
||||
});
|
||||
do_test_pending();
|
||||
|
||||
try {
|
||||
setUpTestFixtures();
|
||||
_("Info URL: " + Service.infoURL);
|
||||
|
||||
_("Confirm initial environment.");
|
||||
do_check_false(steam_coll.deleted);
|
||||
do_check_false(diesel_coll.deleted);
|
||||
do_check_false(keys_coll.deleted);
|
||||
|
||||
_("Collections: " + new Resource(Service.infoURL).get());
|
||||
_("Try deletion.");
|
||||
Service.wipeServer();
|
||||
_("Collections: " + new Resource(Service.infoURL).get());
|
||||
|
||||
_("Make sure keys is still present.");
|
||||
do_check_true(steam_coll.deleted);
|
||||
do_check_true(diesel_coll.deleted);
|
||||
do_check_false(keys_coll.deleted);
|
||||
|
||||
_("Delete everything.");
|
||||
Service.wipeServer(null, true);
|
||||
do_check_true(steam_coll.deleted);
|
||||
do_check_true(diesel_coll.deleted);
|
||||
do_check_true(keys_coll.deleted);
|
||||
|
||||
} finally {
|
||||
server.stop(do_test_finished);
|
||||
Svc.Prefs.resetBranch("");
|
||||
}
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
initTestLogging("Trace");
|
||||
test_withCollectionList_fail();
|
||||
test_wipeServer_leaves_collections();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче