Bug 684798 - Part 1: Catch server errors for crypto/keys. r=rnewman

This commit is contained in:
Philipp von Weitershausen 2011-10-12 13:53:06 -07:00
Родитель a1797a6671
Коммит 05383a4e49
3 изменённых файлов: 119 добавлений и 8 удалений

Просмотреть файл

@ -569,7 +569,12 @@ let ErrorHandler = {
},
notifyOnNextTick: function notifyOnNextTick(topic) {
Utils.nextTick(function() Svc.Obs.notify(topic));
Utils.nextTick(function() {
this._log.trace("Notifying " + topic +
". Status.login is " + Status.login +
". Status.sync is " + Status.sync);
Svc.Obs.notify(topic);
}, this);
},
/**

Просмотреть файл

@ -702,8 +702,11 @@ WeaveSvc.prototype = {
return true;
}
} catch (e) {
} catch (ex) {
// 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;
}
},
@ -827,6 +830,7 @@ 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.");
@ -1679,7 +1683,6 @@ WeaveSvc.prototype = {
// Pretend we've never synced to the server and drop cached data
this.syncID = "";
Svc.Prefs.reset("lastSync");
Records.clearCache();
}))(),

Просмотреть файл

@ -20,8 +20,7 @@ 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() {
@ -937,7 +936,7 @@ add_test(function test_meta_global_login_prolonged_server_maintenance_error(){
Service.sync();
});
add_test(function test_crypto_keys_login_prolonged_server_maintenance_error(){
add_test(function test_download_crypto_keys_login_prolonged_server_maintenance_error(){
// Test crypto/keys prolonged server maintenance errors are reported.
let server = sync_httpd_setup();
setUp();
@ -971,6 +970,40 @@ add_test(function test_crypto_keys_login_prolonged_server_maintenance_error(){
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 = "foo";
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.
@ -1064,7 +1097,7 @@ add_test(function test_meta_global_login_syncAndReportErrors_server_maintenance_
ErrorHandler.syncAndReportErrors();
});
add_test(function test_crypto_keys_login_syncAndReportErrors_server_maintenance_error() {
add_test(function test_download_crypto_keys_login_syncAndReportErrors_server_maintenance_error() {
// Test crypto/keys server maintenance errors are reported
// when calling syncAndReportErrors.
let server = sync_httpd_setup();
@ -1099,6 +1132,41 @@ add_test(function test_crypto_keys_login_syncAndReportErrors_server_maintenance_
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 = "foo";
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.
@ -1192,7 +1260,7 @@ add_test(function test_meta_global_login_syncAndReportErrors_prolonged_server_ma
ErrorHandler.syncAndReportErrors();
});
add_test(function test_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() {
add_test(function test_download_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() {
// Test crypto/keys server maintenance errors are reported
// when calling syncAndReportErrors.
let server = sync_httpd_setup();
@ -1227,6 +1295,41 @@ add_test(function test_crypto_keys_login_syncAndReportErrors_prolonged_server_ma
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 = "foo";
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();