зеркало из https://github.com/mozilla/gecko-dev.git
Back out bug 684798 parts 1 thru 3.
This commit is contained in:
Родитель
315945275a
Коммит
e1663a3ac0
|
@ -724,7 +724,7 @@ SyncEngine.prototype = {
|
|||
// Delete any existing data and reupload on bad version or missing meta.
|
||||
// No crypto component here...? We could regenerate per-collection keys...
|
||||
if (needsWipe) {
|
||||
this.wipeServer();
|
||||
this.wipeServer(true);
|
||||
}
|
||||
|
||||
// Save objects that need to be uploaded in this._modified. We also save
|
||||
|
@ -1248,10 +1248,7 @@ SyncEngine.prototype = {
|
|||
},
|
||||
|
||||
wipeServer: function wipeServer() {
|
||||
let response = new Resource(this.engineURL).delete();
|
||||
if (response.status != 200 && response.status != 404) {
|
||||
throw response;
|
||||
}
|
||||
new Resource(this.engineURL).delete();
|
||||
this._resetClient();
|
||||
},
|
||||
|
||||
|
|
|
@ -569,12 +569,7 @@ let ErrorHandler = {
|
|||
},
|
||||
|
||||
notifyOnNextTick: function notifyOnNextTick(topic) {
|
||||
Utils.nextTick(function() {
|
||||
this._log.trace("Notifying " + topic +
|
||||
". Status.login is " + Status.login +
|
||||
". Status.sync is " + Status.sync);
|
||||
Svc.Obs.notify(topic);
|
||||
}, this);
|
||||
Utils.nextTick(function() Svc.Obs.notify(topic));
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -702,11 +702,8 @@ WeaveSvc.prototype = {
|
|||
return true;
|
||||
}
|
||||
|
||||
} catch (ex) {
|
||||
} catch (e) {
|
||||
// This means no keys are present, or there's a network error.
|
||||
this._log.debug("Failed to fetch and verify keys: "
|
||||
+ Utils.exceptionStr(ex));
|
||||
ErrorHandler.checkServerError(ex);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
@ -830,7 +827,6 @@ WeaveSvc.prototype = {
|
|||
let uploadRes = wbo.upload(this.cryptoKeysURL);
|
||||
if (uploadRes.status != 200) {
|
||||
this._log.warn("Got status " + uploadRes.status + " uploading new keys. What to do? Throw!");
|
||||
ErrorHandler.checkServerError(uploadRes);
|
||||
throw new Error("Unable to upload symmetric keys.");
|
||||
}
|
||||
this._log.info("Got status " + uploadRes.status + " uploading keys.");
|
||||
|
@ -1372,14 +1368,7 @@ WeaveSvc.prototype = {
|
|||
}
|
||||
|
||||
// Update engines because it might change what we sync.
|
||||
try {
|
||||
this._updateEnabledEngines();
|
||||
} catch (ex) {
|
||||
this._log.debug("Updating enabled engines failed: " +
|
||||
Utils.exceptionStr(ex));
|
||||
ErrorHandler.checkServerError(ex);
|
||||
throw ex;
|
||||
}
|
||||
this._updateEnabledEngines();
|
||||
|
||||
try {
|
||||
for each (let engine in Engines.getEnabled()) {
|
||||
|
@ -1567,34 +1556,22 @@ WeaveSvc.prototype = {
|
|||
CollectionKeys.clear();
|
||||
this.upgradeSyncKey(this.syncID);
|
||||
|
||||
// Wipe the server.
|
||||
let wipeTimestamp = this.wipeServer();
|
||||
|
||||
// Upload a new meta/global record.
|
||||
let meta = new WBORecord("meta", "global");
|
||||
meta.payload.syncID = this.syncID;
|
||||
meta.payload.storageVersion = STORAGE_VERSION;
|
||||
meta.isNew = true;
|
||||
|
||||
this._log.debug("New metadata record: " + JSON.stringify(meta.payload));
|
||||
let res = new Resource(this.metaURL);
|
||||
// It would be good to set the X-If-Unmodified-Since header to `timestamp`
|
||||
// for this PUT to ensure at least some level of transactionality.
|
||||
// Unfortunately, the servers don't support it after a wipe right now
|
||||
// (bug 693893), so we're going to defer this until bug 692700.
|
||||
let resp = res.put(meta);
|
||||
if (!resp.success) {
|
||||
// If we got into a race condition, we'll abort the sync this way, too.
|
||||
// That's fine. We'll just wait till the next sync. The client that we're
|
||||
// racing is probably busy uploading stuff right now anyway.
|
||||
let resp = new Resource(this.metaURL).put(meta);
|
||||
if (!resp.success)
|
||||
throw resp;
|
||||
}
|
||||
Records.set(this.metaURL, meta);
|
||||
|
||||
// Wipe everything we know about except meta because we just uploaded it
|
||||
let collections = [Clients].concat(Engines.getAll()).map(function(engine) {
|
||||
return engine.name;
|
||||
});
|
||||
this.wipeServer(collections);
|
||||
|
||||
// Generate, upload, and download new keys. Do this last so we don't wipe
|
||||
// them...
|
||||
|
@ -1605,51 +1582,36 @@ WeaveSvc.prototype = {
|
|||
* Wipe user data from the server.
|
||||
*
|
||||
* @param collections [optional]
|
||||
* Array of collections to wipe. If not given, all collections are
|
||||
* wiped by issuing a DELETE request for `storageURL`.
|
||||
* Array of collections to wipe. If not given, all collections are wiped.
|
||||
*
|
||||
* @return the server's timestamp of the (last) DELETE.
|
||||
* @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 wipeServer(collections)
|
||||
wipeServer: function wipeServer(collections, includeKeyPairs)
|
||||
this._notify("wipe-server", "", function() {
|
||||
let response;
|
||||
if (!collections) {
|
||||
// Strip the trailing slash.
|
||||
let res = new Resource(this.storageURL.slice(0, -1));
|
||||
res.setHeader("X-Confirm-Delete", "1");
|
||||
try {
|
||||
response = res.delete();
|
||||
} catch (ex) {
|
||||
this._log.debug("Failed to wipe server: " + Utils.exceptionStr(ex));
|
||||
throw ex;
|
||||
collections = [];
|
||||
let info = new Resource(this.infoURL).get();
|
||||
for (let name in info.obj) {
|
||||
if (includeKeyPairs || (name != "keys"))
|
||||
collections.push(name);
|
||||
}
|
||||
if (response.status != 200 && response.status != 404) {
|
||||
this._log.debug("Aborting wipeServer. Server responded with " +
|
||||
response.status + " response for " + this.storageURL);
|
||||
throw response;
|
||||
}
|
||||
return response.headers["x-weave-timestamp"];
|
||||
}
|
||||
let timestamp;
|
||||
for each (let name in collections) {
|
||||
let url = this.storageURL + name;
|
||||
try {
|
||||
response = new Resource(url).delete();
|
||||
} catch (ex) {
|
||||
this._log.debug("Failed to wipe '" + name + "' collection: " +
|
||||
Utils.exceptionStr(ex));
|
||||
throw ex;
|
||||
}
|
||||
let response = new Resource(url).delete();
|
||||
if (response.status != 200 && response.status != 404) {
|
||||
this._log.debug("Aborting wipeServer. Server responded with " +
|
||||
response.status + " response for " + url);
|
||||
throw response;
|
||||
}
|
||||
if ("x-weave-timestamp" in response.headers) {
|
||||
timestamp = response.headers["x-weave-timestamp"];
|
||||
throw "Aborting wipeServer. Server responded with "
|
||||
+ response.status + " response for " + url;
|
||||
}
|
||||
}
|
||||
return timestamp;
|
||||
})(),
|
||||
|
||||
/**
|
||||
|
@ -1717,6 +1679,7 @@ WeaveSvc.prototype = {
|
|||
|
||||
// Pretend we've never synced to the server and drop cached data
|
||||
this.syncID = "";
|
||||
Svc.Prefs.reset("lastSync");
|
||||
Records.clearCache();
|
||||
}))(),
|
||||
|
||||
|
|
|
@ -10,17 +10,6 @@ function new_timestamp() {
|
|||
return Math.round(Date.now() / 10) / 100;
|
||||
}
|
||||
|
||||
function return_timestamp(request, response, timestamp) {
|
||||
if (!timestamp) {
|
||||
timestamp = new_timestamp();
|
||||
}
|
||||
let body = "" + timestamp;
|
||||
response.setHeader("X-Weave-Timestamp", body);
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
function httpd_setup (handlers) {
|
||||
let server = new nsHttpServer();
|
||||
let port = 8080;
|
||||
|
@ -619,7 +608,7 @@ SyncServer.prototype = {
|
|||
* subject to change: see Bug 650435.
|
||||
*/
|
||||
timestamp: function timestamp() {
|
||||
return new_timestamp();
|
||||
return Math.round(Date.now() / 10) / 100;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,8 @@ const NON_PROLONGED_ERROR_DURATION =
|
|||
(Svc.Prefs.get('errorhandler.networkFailureReportTimeout') / 2) * 1000;
|
||||
|
||||
function setLastSync(lastSyncValue) {
|
||||
Svc.Prefs.set("lastSync", (new Date(Date.now() - lastSyncValue)).toString());
|
||||
Svc.Prefs.set("lastSync", (new Date(Date.now() -
|
||||
lastSyncValue)).toString());
|
||||
}
|
||||
|
||||
function CatapultEngine() {
|
||||
|
@ -78,35 +79,23 @@ function sync_httpd_setup() {
|
|||
|
||||
let handler_401 = httpd_handler(401, "Unauthorized");
|
||||
return httpd_setup({
|
||||
// Normal server behaviour.
|
||||
"/1.1/johndoe/storage/meta/global": upd("meta", global.handler()),
|
||||
"/1.1/johndoe/info/collections": collectionsHelper.handler,
|
||||
"/1.1/johndoe/storage/crypto/keys":
|
||||
upd("crypto", (new ServerWBO("keys")).handler()),
|
||||
"/1.1/johndoe/storage/clients": upd("clients", clientsColl.handler()),
|
||||
|
||||
// Credentials are wrong or node reallocated.
|
||||
"/1.1/janedoe/storage/meta/global": handler_401,
|
||||
"/1.1/janedoe/info/collections": handler_401,
|
||||
|
||||
// Maintenance or overloaded (503 + Retry-After) at info/collections.
|
||||
"/maintenance/1.1/broken.info/info/collections": service_unavailable,
|
||||
"/maintenance/1.1/johnsmith/info/collections": service_unavailable,
|
||||
|
||||
// Maintenance or overloaded (503 + Retry-After) at meta/global.
|
||||
"/maintenance/1.1/broken.meta/storage/meta/global": service_unavailable,
|
||||
"/maintenance/1.1/broken.meta/info/collections": collectionsHelper.handler,
|
||||
"/maintenance/1.1/janesmith/storage/meta/global": service_unavailable,
|
||||
"/maintenance/1.1/janesmith/info/collections": collectionsHelper.handler,
|
||||
|
||||
// Maintenance or overloaded (503 + Retry-After) at crypto/keys.
|
||||
"/maintenance/1.1/broken.keys/storage/meta/global": upd("meta", global.handler()),
|
||||
"/maintenance/1.1/broken.keys/info/collections": collectionsHelper.handler,
|
||||
"/maintenance/1.1/broken.keys/storage/crypto/keys": service_unavailable,
|
||||
|
||||
// Maintenance or overloaded (503 + Retry-After) at wiping collection.
|
||||
"/maintenance/1.1/broken.wipe/info/collections": collectionsHelper.handler,
|
||||
"/maintenance/1.1/broken.wipe/storage/meta/global": upd("meta", global.handler()),
|
||||
"/maintenance/1.1/broken.wipe/storage/crypto/keys":
|
||||
upd("crypto", (new ServerWBO("keys")).handler()),
|
||||
"/maintenance/1.1/broken.wipe/storage": service_unavailable
|
||||
"/maintenance/1.1/foo/storage/meta/global": upd("meta", global.handler()),
|
||||
"/maintenance/1.1/foo/info/collections": collectionsHelper.handler,
|
||||
"/maintenance/1.1/foo/storage/crypto/keys": service_unavailable,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -744,9 +733,9 @@ add_test(function test_info_collections_login_server_maintenance_error() {
|
|||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.info";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
Service.username = "johnsmith";
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
|
@ -783,9 +772,9 @@ add_test(function test_meta_global_login_server_maintenance_error() {
|
|||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.meta";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
Service.username = "janesmith";
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
|
@ -822,8 +811,8 @@ add_test(function test_crypto_keys_login_server_maintenance_error() {
|
|||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.keys";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
Service.username = "foo";
|
||||
// Force re-download of keys
|
||||
CollectionKeys.clear();
|
||||
|
||||
|
@ -889,9 +878,9 @@ add_test(function test_info_collections_login_prolonged_server_maintenance_error
|
|||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.info";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
Service.username = "johnsmith";
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
|
@ -921,9 +910,9 @@ add_test(function test_meta_global_login_prolonged_server_maintenance_error(){
|
|||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.meta";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
Service.username = "janesmith";
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
|
@ -948,13 +937,13 @@ add_test(function test_meta_global_login_prolonged_server_maintenance_error(){
|
|||
Service.sync();
|
||||
});
|
||||
|
||||
add_test(function test_download_crypto_keys_login_prolonged_server_maintenance_error(){
|
||||
add_test(function test_crypto_keys_login_prolonged_server_maintenance_error(){
|
||||
// Test crypto/keys prolonged server maintenance errors are reported.
|
||||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.keys";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
Service.username = "foo";
|
||||
// Force re-download of keys
|
||||
CollectionKeys.clear();
|
||||
|
||||
|
@ -982,74 +971,6 @@ add_test(function test_download_crypto_keys_login_prolonged_server_maintenance_e
|
|||
Service.sync();
|
||||
});
|
||||
|
||||
add_test(function test_upload_crypto_keys_login_prolonged_server_maintenance_error(){
|
||||
// Test crypto/keys prolonged server maintenance errors are reported.
|
||||
let server = sync_httpd_setup();
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
Service.username = "broken.keys";
|
||||
Service.password = "ilovejane";
|
||||
Service.passphrase = "abcdeabcdeabcdeabcdeabcdea";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
backoffInterval = subject;
|
||||
});
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
|
||||
Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
|
||||
do_check_true(Status.enforceBackoff);
|
||||
do_check_eq(backoffInterval, 42);
|
||||
do_check_eq(Status.service, SYNC_FAILED);
|
||||
do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
|
||||
|
||||
clean();
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
do_check_false(Status.enforceBackoff);
|
||||
do_check_eq(Status.service, STATUS_OK);
|
||||
|
||||
setLastSync(PROLONGED_ERROR_DURATION);
|
||||
Service.sync();
|
||||
});
|
||||
|
||||
add_test(function test_wipeServer_login_prolonged_server_maintenance_error(){
|
||||
// Test crypto/keys prolonged server maintenance errors are reported.
|
||||
let server = sync_httpd_setup();
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
Service.username = "broken.wipe";
|
||||
Service.password = "ilovejane";
|
||||
Service.passphrase = "abcdeabcdeabcdeabcdeabcdea";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
backoffInterval = subject;
|
||||
});
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
|
||||
Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
|
||||
do_check_true(Status.enforceBackoff);
|
||||
do_check_eq(backoffInterval, 42);
|
||||
do_check_eq(Status.service, SYNC_FAILED);
|
||||
do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
|
||||
|
||||
clean();
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
do_check_false(Status.enforceBackoff);
|
||||
do_check_eq(Status.service, STATUS_OK);
|
||||
|
||||
setLastSync(PROLONGED_ERROR_DURATION);
|
||||
Service.sync();
|
||||
});
|
||||
|
||||
add_test(function test_sync_syncAndReportErrors_server_maintenance_error() {
|
||||
// Test server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
|
@ -1083,9 +1004,9 @@ add_test(function test_info_collections_login_syncAndReportErrors_server_mainten
|
|||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.info";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
Service.username = "johnsmith";
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
|
@ -1116,9 +1037,9 @@ add_test(function test_meta_global_login_syncAndReportErrors_server_maintenance_
|
|||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.meta";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
Service.username = "janesmith";
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
|
@ -1143,14 +1064,14 @@ add_test(function test_meta_global_login_syncAndReportErrors_server_maintenance_
|
|||
ErrorHandler.syncAndReportErrors();
|
||||
});
|
||||
|
||||
add_test(function test_download_crypto_keys_login_syncAndReportErrors_server_maintenance_error() {
|
||||
add_test(function test_crypto_keys_login_syncAndReportErrors_server_maintenance_error() {
|
||||
// Test crypto/keys server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.keys";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
Service.username = "foo";
|
||||
// Force re-download of keys
|
||||
CollectionKeys.clear();
|
||||
|
||||
|
@ -1178,76 +1099,6 @@ add_test(function test_download_crypto_keys_login_syncAndReportErrors_server_mai
|
|||
ErrorHandler.syncAndReportErrors();
|
||||
});
|
||||
|
||||
add_test(function test_upload_crypto_keys_login_syncAndReportErrors_server_maintenance_error() {
|
||||
// Test crypto/keys server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
Service.username = "broken.keys";
|
||||
Service.password = "ilovejane";
|
||||
Service.passphrase = "abcdeabcdeabcdeabcdeabcdea";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
backoffInterval = subject;
|
||||
});
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
|
||||
Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
|
||||
do_check_true(Status.enforceBackoff);
|
||||
do_check_eq(backoffInterval, 42);
|
||||
do_check_eq(Status.service, LOGIN_FAILED);
|
||||
do_check_eq(Status.login, SERVER_MAINTENANCE);
|
||||
|
||||
clean();
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
do_check_false(Status.enforceBackoff);
|
||||
do_check_eq(Status.service, STATUS_OK);
|
||||
|
||||
setLastSync(NON_PROLONGED_ERROR_DURATION);
|
||||
ErrorHandler.syncAndReportErrors();
|
||||
});
|
||||
|
||||
add_test(function test_wipeServer_login_syncAndReportErrors_server_maintenance_error() {
|
||||
// Test crypto/keys server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
Service.username = "broken.wipe";
|
||||
Service.password = "ilovejane";
|
||||
Service.passphrase = "abcdeabcdeabcdeabcdeabcdea";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
backoffInterval = subject;
|
||||
});
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
|
||||
Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
|
||||
do_check_true(Status.enforceBackoff);
|
||||
do_check_eq(backoffInterval, 42);
|
||||
do_check_eq(Status.service, LOGIN_FAILED);
|
||||
do_check_eq(Status.login, SERVER_MAINTENANCE);
|
||||
|
||||
clean();
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
do_check_false(Status.enforceBackoff);
|
||||
do_check_eq(Status.service, STATUS_OK);
|
||||
|
||||
setLastSync(NON_PROLONGED_ERROR_DURATION);
|
||||
ErrorHandler.syncAndReportErrors();
|
||||
});
|
||||
|
||||
add_test(function test_sync_syncAndReportErrors_prolonged_server_maintenance_error() {
|
||||
// Test prolonged server maintenance errors are
|
||||
// reported when calling syncAndReportErrors.
|
||||
|
@ -1281,9 +1132,9 @@ add_test(function test_info_collections_login_syncAndReportErrors_prolonged_serv
|
|||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.info";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
Service.username = "johnsmith";
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
|
@ -1314,9 +1165,9 @@ add_test(function test_meta_global_login_syncAndReportErrors_prolonged_server_ma
|
|||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.meta";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
Service.username = "janesmith";
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
|
@ -1341,14 +1192,14 @@ add_test(function test_meta_global_login_syncAndReportErrors_prolonged_server_ma
|
|||
ErrorHandler.syncAndReportErrors();
|
||||
});
|
||||
|
||||
add_test(function test_download_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() {
|
||||
add_test(function test_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() {
|
||||
// Test crypto/keys server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.keys";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
Service.username = "foo";
|
||||
// Force re-download of keys
|
||||
CollectionKeys.clear();
|
||||
|
||||
|
@ -1376,76 +1227,6 @@ add_test(function test_download_crypto_keys_login_syncAndReportErrors_prolonged_
|
|||
ErrorHandler.syncAndReportErrors();
|
||||
});
|
||||
|
||||
add_test(function test_upload_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() {
|
||||
// Test crypto/keys server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
Service.username = "broken.keys";
|
||||
Service.password = "ilovejane";
|
||||
Service.passphrase = "abcdeabcdeabcdeabcdeabcdea";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
backoffInterval = subject;
|
||||
});
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
|
||||
Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
|
||||
do_check_true(Status.enforceBackoff);
|
||||
do_check_eq(backoffInterval, 42);
|
||||
do_check_eq(Status.service, LOGIN_FAILED);
|
||||
do_check_eq(Status.login, SERVER_MAINTENANCE);
|
||||
|
||||
clean();
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
do_check_false(Status.enforceBackoff);
|
||||
do_check_eq(Status.service, STATUS_OK);
|
||||
|
||||
setLastSync(PROLONGED_ERROR_DURATION);
|
||||
ErrorHandler.syncAndReportErrors();
|
||||
});
|
||||
|
||||
add_test(function test_wipeServer_login_syncAndReportErrors_prolonged_server_maintenance_error() {
|
||||
// Test crypto/keys server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
Service.username = "broken.wipe";
|
||||
Service.password = "ilovejane";
|
||||
Service.passphrase = "abcdeabcdeabcdeabcdeabcdea";
|
||||
Service.clusterURL = "http://localhost:8080/maintenance/";
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
Svc.Obs.remove("weave:service:backoff:interval", observe);
|
||||
backoffInterval = subject;
|
||||
});
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
|
||||
Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
|
||||
do_check_true(Status.enforceBackoff);
|
||||
do_check_eq(backoffInterval, 42);
|
||||
do_check_eq(Status.service, LOGIN_FAILED);
|
||||
do_check_eq(Status.login, SERVER_MAINTENANCE);
|
||||
|
||||
clean();
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
do_check_false(Status.enforceBackoff);
|
||||
do_check_eq(Status.service, STATUS_OK);
|
||||
|
||||
setLastSync(PROLONGED_ERROR_DURATION);
|
||||
ErrorHandler.syncAndReportErrors();
|
||||
});
|
||||
|
||||
add_test(function test_sync_engine_generic_fail() {
|
||||
let server = sync_httpd_setup();
|
||||
|
||||
|
|
|
@ -29,28 +29,7 @@ function run_test() {
|
|||
let cryptoColl = new ServerCollection({keys: keysWBO});
|
||||
let metaColl = new ServerCollection({global: meta_global});
|
||||
do_test_pending();
|
||||
|
||||
/**
|
||||
* Handle the bulk DELETE request sent by wipeServer.
|
||||
*/
|
||||
function storageHandler(request, response) {
|
||||
do_check_eq("DELETE", request.method);
|
||||
do_check_true(request.hasHeader("X-Confirm-Delete"));
|
||||
|
||||
_("Wiping out all collections.");
|
||||
cryptoColl.delete({});
|
||||
clients.delete({});
|
||||
metaColl.delete({});
|
||||
|
||||
let ts = new_timestamp();
|
||||
collectionsHelper.update_collection("crypto", ts);
|
||||
collectionsHelper.update_collection("clients", ts);
|
||||
collectionsHelper.update_collection("meta", ts);
|
||||
return_timestamp(request, response, ts);
|
||||
}
|
||||
|
||||
let server = httpd_setup({
|
||||
"/1.1/johndoe/storage": storageHandler,
|
||||
"/1.1/johndoe/storage/crypto/keys": upd("crypto", keysWBO.handler()),
|
||||
"/1.1/johndoe/storage/crypto": upd("crypto", cryptoColl.handler()),
|
||||
"/1.1/johndoe/storage/clients": upd("clients", clients.handler()),
|
||||
|
|
|
@ -3,11 +3,9 @@ Cu.import("resource://services-sync/engines/clients.js");
|
|||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://services-sync/constants.js");
|
||||
Cu.import("resource://services-sync/record.js");
|
||||
Cu.import("resource://services-sync/status.js");
|
||||
|
||||
Svc.DefaultPrefs.set("registerEngines", "");
|
||||
Cu.import("resource://services-sync/service.js");
|
||||
Cu.import("resource://services-sync/policies.js");
|
||||
|
||||
initTestLogging();
|
||||
|
||||
|
@ -68,30 +66,13 @@ function sync_httpd_setup(handlers) {
|
|||
function setUp() {
|
||||
Service.username = "johndoe";
|
||||
Service.password = "ilovejane";
|
||||
Service.passphrase = "abcdeabcdeabcdeabcdeabcdea";
|
||||
Service.passphrase = "sekrit";
|
||||
Service.clusterURL = "http://localhost:8080/";
|
||||
// So that we can poke at meta/global.
|
||||
new FakeCryptoService();
|
||||
|
||||
// Ensure that the server has valid keys so that logging in will work and not
|
||||
// result in a server wipe, rendering many of these tests useless.
|
||||
generateNewKeys();
|
||||
let serverKeys = CollectionKeys.asWBO("crypto", "keys");
|
||||
serverKeys.encrypt(Service.syncKeyBundle);
|
||||
return serverKeys.upload(Service.cryptoKeysURL).success;
|
||||
}
|
||||
|
||||
const PAYLOAD = 42;
|
||||
|
||||
|
||||
function run_test() {
|
||||
initTestLogging("Trace");
|
||||
Log4Moz.repository.getLogger("Sync.Service").level = Log4Moz.Level.Trace;
|
||||
Log4Moz.repository.getLogger("Sync.ErrorHandler").level = Log4Moz.Level.Trace;
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_test(function test_newAccount() {
|
||||
_("Test: New account does not disable locally enabled engines.");
|
||||
let engine = Engines.get("steam");
|
||||
|
@ -108,6 +89,7 @@ add_test(function test_newAccount() {
|
|||
Service._ignorePrefObserver = false;
|
||||
|
||||
_("Sync.");
|
||||
Weave.Service.login();
|
||||
Weave.Service.sync();
|
||||
|
||||
_("Engine continues to be enabled.");
|
||||
|
@ -136,6 +118,7 @@ add_test(function test_enabledLocally() {
|
|||
engine.enabled = true;
|
||||
|
||||
_("Sync.");
|
||||
Weave.Service.login();
|
||||
Weave.Service.sync();
|
||||
|
||||
_("Meta record now contains the new engine.");
|
||||
|
@ -160,7 +143,6 @@ add_test(function test_disabledLocally() {
|
|||
version: engine.version}}
|
||||
});
|
||||
let steamCollection = new ServerWBO("steam", PAYLOAD);
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/johndoe/storage/meta/global": metaWBO.handler(),
|
||||
"/1.1/johndoe/storage/steam": steamCollection.handler()
|
||||
|
@ -175,6 +157,7 @@ add_test(function test_disabledLocally() {
|
|||
engine.enabled = false;
|
||||
|
||||
_("Sync.");
|
||||
Weave.Service.login();
|
||||
Weave.Service.sync();
|
||||
|
||||
_("Meta record no longer contains engine.");
|
||||
|
@ -191,50 +174,6 @@ add_test(function test_disabledLocally() {
|
|||
}
|
||||
});
|
||||
|
||||
add_test(function test_disabledLocally_wipe503() {
|
||||
_("Test: Engine is enabled on remote clients and disabled locally");
|
||||
Service.syncID = "abcdefghij";
|
||||
let engine = Engines.get("steam");
|
||||
let metaWBO = new ServerWBO("global", {
|
||||
syncID: Service.syncID,
|
||||
storageVersion: STORAGE_VERSION,
|
||||
engines: {steam: {syncID: engine.syncID,
|
||||
version: engine.version}}
|
||||
});
|
||||
let steamCollection = new ServerWBO("steam", PAYLOAD);
|
||||
|
||||
function service_unavailable(request, response) {
|
||||
let body = "Service Unavailable";
|
||||
response.setStatusLine(request.httpVersion, 503, "Service Unavailable");
|
||||
response.setHeader("Retry-After", "23");
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/johndoe/storage/meta/global": metaWBO.handler(),
|
||||
"/1.1/johndoe/storage/steam": service_unavailable
|
||||
});
|
||||
setUp();
|
||||
|
||||
_("Disable engine locally.");
|
||||
Service._ignorePrefObserver = true;
|
||||
engine.enabled = true;
|
||||
Service._ignorePrefObserver = false;
|
||||
engine.enabled = false;
|
||||
|
||||
Svc.Obs.add("weave:ui:sync:error", function onSyncError() {
|
||||
Svc.Obs.remove("weave:ui:sync:error", onSyncError);
|
||||
|
||||
do_check_eq(Status.sync, SERVER_MAINTENANCE);
|
||||
|
||||
Service.startOver();
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
_("Sync.");
|
||||
ErrorHandler.syncAndReportErrors();
|
||||
});
|
||||
|
||||
add_test(function test_enabledRemotely() {
|
||||
_("Test: Engine is disabled locally and enabled on a remote client");
|
||||
Service.syncID = "abcdefghij";
|
||||
|
@ -266,6 +205,7 @@ add_test(function test_enabledRemotely() {
|
|||
do_check_false(engine.enabled);
|
||||
|
||||
_("Sync.");
|
||||
Weave.Service.login();
|
||||
Weave.Service.sync();
|
||||
|
||||
_("Engine is enabled.");
|
||||
|
@ -302,6 +242,7 @@ add_test(function test_disabledRemotelyTwoClients() {
|
|||
Service._ignorePrefObserver = false;
|
||||
|
||||
_("Sync.");
|
||||
Weave.Service.login();
|
||||
Weave.Service.sync();
|
||||
|
||||
_("Disable engine by deleting from meta/global.");
|
||||
|
@ -343,6 +284,7 @@ add_test(function test_disabledRemotely() {
|
|||
Service._ignorePrefObserver = false;
|
||||
|
||||
_("Sync.");
|
||||
Weave.Service.login();
|
||||
Weave.Service.sync();
|
||||
|
||||
_("Engine is not disabled: only one client.");
|
||||
|
@ -374,6 +316,7 @@ add_test(function test_dependentEnginesEnabledLocally() {
|
|||
steamEngine.enabled = true;
|
||||
|
||||
_("Sync.");
|
||||
Weave.Service.login();
|
||||
Weave.Service.sync();
|
||||
|
||||
_("Meta record now contains the new engines.");
|
||||
|
@ -405,7 +348,6 @@ add_test(function test_dependentEnginesDisabledLocally() {
|
|||
|
||||
let steamCollection = new ServerWBO("steam", PAYLOAD);
|
||||
let stirlingCollection = new ServerWBO("stirling", PAYLOAD);
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/johndoe/storage/meta/global": metaWBO.handler(),
|
||||
"/1.1/johndoe/storage/steam": steamCollection.handler(),
|
||||
|
@ -423,6 +365,7 @@ add_test(function test_dependentEnginesDisabledLocally() {
|
|||
do_check_false(stirlingEngine.enabled);
|
||||
|
||||
_("Sync.");
|
||||
Weave.Service.login();
|
||||
Weave.Service.sync();
|
||||
|
||||
_("Meta record no longer contains engines.");
|
||||
|
@ -441,3 +384,7 @@ add_test(function test_dependentEnginesDisabledLocally() {
|
|||
server.stop(run_next_test);
|
||||
}
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
|
|
@ -13,19 +13,22 @@ FakeCollection.prototype = {
|
|||
let self = this;
|
||||
return function(request, response) {
|
||||
let body = "";
|
||||
self.timestamp = new_timestamp();
|
||||
let timestamp = "" + self.timestamp;
|
||||
if (request.method == "DELETE") {
|
||||
body = timestamp;
|
||||
body = JSON.stringify(Date.now() / 1000);
|
||||
self.deleted = true;
|
||||
}
|
||||
response.setHeader("X-Weave-Timestamp", timestamp);
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
function serviceUnavailable(request, response) {
|
||||
let body = "Service Unavailable";
|
||||
response.setStatusLine(request.httpVersion, 503, "Service Unavailable");
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
function setUpTestFixtures() {
|
||||
let cryptoService = new FakeCryptoService();
|
||||
|
||||
|
@ -34,13 +37,7 @@ function setUpTestFixtures() {
|
|||
Service.passphrase = "aabcdeabcdeabcdeabcdeabcde";
|
||||
}
|
||||
|
||||
|
||||
function run_test() {
|
||||
initTestLogging("Trace");
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_test(function test_wipeServer_list_success() {
|
||||
function test_withCollectionList_fail() {
|
||||
_("Service.wipeServer() deletes collections given as argument.");
|
||||
|
||||
let steam_coll = new FakeCollection();
|
||||
|
@ -48,42 +45,10 @@ add_test(function test_wipeServer_list_success() {
|
|||
|
||||
let server = httpd_setup({
|
||||
"/1.1/johndoe/storage/steam": steam_coll.handler(),
|
||||
"/1.1/johndoe/storage/diesel": diesel_coll.handler(),
|
||||
"/1.1/johndoe/storage/petrol": httpd_handler(404, "Not Found")
|
||||
});
|
||||
|
||||
try {
|
||||
setUpTestFixtures();
|
||||
|
||||
_("Confirm initial environment.");
|
||||
do_check_false(steam_coll.deleted);
|
||||
do_check_false(diesel_coll.deleted);
|
||||
|
||||
_("wipeServer() will happily ignore the non-existent collection and use the timestamp of the last DELETE that was successful.");
|
||||
let timestamp = Service.wipeServer(["steam", "diesel", "petrol"]);
|
||||
do_check_eq(timestamp, diesel_coll.timestamp);
|
||||
|
||||
_("wipeServer stopped deleting after encountering an error with the 'petrol' collection, thus only 'steam' has been deleted.");
|
||||
do_check_true(steam_coll.deleted);
|
||||
do_check_true(diesel_coll.deleted);
|
||||
|
||||
} finally {
|
||||
server.stop(run_next_test);
|
||||
Svc.Prefs.resetBranch("");
|
||||
}
|
||||
});
|
||||
|
||||
add_test(function test_wipeServer_list_503() {
|
||||
_("Service.wipeServer() deletes collections given as argument.");
|
||||
|
||||
let steam_coll = new FakeCollection();
|
||||
let diesel_coll = new FakeCollection();
|
||||
|
||||
let server = httpd_setup({
|
||||
"/1.1/johndoe/storage/steam": steam_coll.handler(),
|
||||
"/1.1/johndoe/storage/petrol": httpd_handler(503, "Service Unavailable"),
|
||||
"/1.1/johndoe/storage/petrol": serviceUnavailable,
|
||||
"/1.1/johndoe/storage/diesel": diesel_coll.handler()
|
||||
});
|
||||
do_test_pending();
|
||||
|
||||
try {
|
||||
setUpTestFixtures();
|
||||
|
@ -96,126 +61,84 @@ add_test(function test_wipeServer_list_503() {
|
|||
let error;
|
||||
try {
|
||||
Service.wipeServer(["non-existent", "steam", "petrol", "diesel"]);
|
||||
do_throw("Should have thrown!");
|
||||
} catch(ex) {
|
||||
error = ex;
|
||||
}
|
||||
_("wipeServer() threw this exception: " + error);
|
||||
do_check_eq(error.status, 503);
|
||||
do_check_true(error != undefined);
|
||||
|
||||
_("wipeServer stopped deleting after encountering an error with the 'petrol' collection, thus only 'steam' has been deleted.");
|
||||
do_check_true(steam_coll.deleted);
|
||||
do_check_false(diesel_coll.deleted);
|
||||
|
||||
} finally {
|
||||
server.stop(run_next_test);
|
||||
server.stop(do_test_finished);
|
||||
Svc.Prefs.resetBranch("");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
add_test(function test_wipeServer_all_success() {
|
||||
_("Service.wipeServer() deletes all the things.");
|
||||
function test_wipeServer_leaves_collections() {
|
||||
_("Service.wipeServer() deletes everything but keys.");
|
||||
|
||||
/**
|
||||
* Handle the bulk DELETE request sent by wipeServer.
|
||||
*/
|
||||
let deleted = false;
|
||||
let serverTimestamp;
|
||||
function storageHandler(request, response) {
|
||||
do_check_eq("DELETE", request.method);
|
||||
do_check_true(request.hasHeader("X-Confirm-Delete"));
|
||||
deleted = true;
|
||||
serverTimestamp = return_timestamp(request, response);
|
||||
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.1/johndoe/storage": storageHandler
|
||||
"/1.1/johndoe/storage/steam": steam_coll.handler(),
|
||||
"/1.1/johndoe/storage/diesel": diesel_coll.handler(),
|
||||
"/1.1/johndoe/storage/keys": keys_coll.handler(),
|
||||
"/1.1/johndoe/info/collections": info_collections
|
||||
});
|
||||
setUpTestFixtures();
|
||||
do_test_pending();
|
||||
|
||||
_("Try deletion.");
|
||||
let returnedTimestamp = Service.wipeServer();
|
||||
do_check_true(deleted);
|
||||
do_check_eq(returnedTimestamp, serverTimestamp);
|
||||
|
||||
server.stop(run_next_test);
|
||||
Svc.Prefs.resetBranch("");
|
||||
});
|
||||
|
||||
add_test(function test_wipeServer_all_404() {
|
||||
_("Service.wipeServer() accepts a 404.");
|
||||
|
||||
/**
|
||||
* Handle the bulk DELETE request sent by wipeServer. Returns a 404.
|
||||
*/
|
||||
let deleted = false;
|
||||
let serverTimestamp;
|
||||
function storageHandler(request, response) {
|
||||
do_check_eq("DELETE", request.method);
|
||||
do_check_true(request.hasHeader("X-Confirm-Delete"));
|
||||
deleted = true;
|
||||
serverTimestamp = new_timestamp();
|
||||
response.setHeader("X-Weave-Timestamp", "" + serverTimestamp);
|
||||
response.setStatusLine(request.httpVersion, 404, "Not Found");
|
||||
}
|
||||
|
||||
let server = httpd_setup({
|
||||
"/1.1/johndoe/storage": storageHandler
|
||||
});
|
||||
setUpTestFixtures();
|
||||
|
||||
_("Try deletion.");
|
||||
let returnedTimestamp = Service.wipeServer();
|
||||
do_check_true(deleted);
|
||||
do_check_eq(returnedTimestamp, serverTimestamp);
|
||||
|
||||
server.stop(run_next_test);
|
||||
Svc.Prefs.resetBranch("");
|
||||
});
|
||||
|
||||
add_test(function test_wipeServer_all_503() {
|
||||
_("Service.wipeServer() throws if it encounters a non-200/404 response.");
|
||||
|
||||
/**
|
||||
* Handle the bulk DELETE request sent by wipeServer. Returns a 503.
|
||||
*/
|
||||
function storageHandler(request, response) {
|
||||
do_check_eq("DELETE", request.method);
|
||||
do_check_true(request.hasHeader("X-Confirm-Delete"));
|
||||
response.setStatusLine(request.httpVersion, 503, "Service Unavailable");
|
||||
}
|
||||
|
||||
let server = httpd_setup({
|
||||
"/1.1/johndoe/storage": storageHandler
|
||||
});
|
||||
setUpTestFixtures();
|
||||
|
||||
_("Try deletion.");
|
||||
let error;
|
||||
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();
|
||||
do_throw("Should have thrown!");
|
||||
} catch (ex) {
|
||||
error = ex;
|
||||
_("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("");
|
||||
}
|
||||
do_check_eq(error.status, 503);
|
||||
}
|
||||
|
||||
server.stop(run_next_test);
|
||||
Svc.Prefs.resetBranch("");
|
||||
});
|
||||
|
||||
add_test(function test_wipeServer_all_connectionRefused() {
|
||||
_("Service.wipeServer() throws if it encounters a network problem.");
|
||||
setUpTestFixtures();
|
||||
|
||||
_("Try deletion.");
|
||||
try {
|
||||
Service.wipeServer();
|
||||
do_throw("Should have thrown!");
|
||||
} catch (ex) {
|
||||
do_check_eq(ex.result, Cr.NS_ERROR_CONNECTION_REFUSED);
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
Svc.Prefs.resetBranch("");
|
||||
});
|
||||
function run_test() {
|
||||
initTestLogging("Trace");
|
||||
test_withCollectionList_fail();
|
||||
test_wipeServer_leaves_collections();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче