зеркало из https://github.com/mozilla/pjs.git
Bug 570180 - Setup wizard sets passphrase='foo' [r=mconnor]
Promote _verifyLogin to a public method so we have a way to query login status even with a non-existent or invalid passphrase.
This commit is contained in:
Родитель
2a116ee59d
Коммит
67eff5457d
|
@ -534,7 +534,7 @@ WeaveSvc.prototype = {
|
|||
return false;
|
||||
},
|
||||
|
||||
_verifyLogin: function _verifyLogin()
|
||||
verifyLogin: function verifyLogin()
|
||||
this._notify("verify-login", "", function() {
|
||||
// Make sure we have a cluster to verify against
|
||||
// this is a little weird, if we don't get a node we pretend
|
||||
|
@ -545,11 +545,22 @@ WeaveSvc.prototype = {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!this.username) {
|
||||
Status.login = LOGIN_FAILED_NO_USERNAME;
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
let test = new Resource(this.infoURL).get();
|
||||
switch (test.status) {
|
||||
case 200:
|
||||
// The user is authenticated, so check the passphrase now
|
||||
// The user is authenticated.
|
||||
if (!this.passphrase) {
|
||||
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
|
||||
return false;
|
||||
}
|
||||
|
||||
// We also have a passphrase, so check it now.
|
||||
if (!this._verifyPassphrase()) {
|
||||
Status.login = LOGIN_FAILED_INVALID_PASSPHRASE;
|
||||
return false;
|
||||
|
@ -563,7 +574,7 @@ WeaveSvc.prototype = {
|
|||
case 404:
|
||||
// Check that we're verifying with the correct cluster
|
||||
if (this._setCluster())
|
||||
return this._verifyLogin();
|
||||
return this.verifyLogin();
|
||||
|
||||
// We must have the right cluster, but the server doesn't expect us
|
||||
Status.login = LOGIN_FAILED_LOGIN_REJECTED;
|
||||
|
@ -721,7 +732,7 @@ WeaveSvc.prototype = {
|
|||
|
||||
this._log.info("Logging in user " + this.username);
|
||||
|
||||
if (!this._verifyLogin()) {
|
||||
if (!this.verifyLogin()) {
|
||||
// verifyLogin sets the failure states here.
|
||||
throw "Login failed: " + Status.login;
|
||||
}
|
||||
|
@ -901,7 +912,7 @@ WeaveSvc.prototype = {
|
|||
Sync.sleep(15000);
|
||||
|
||||
// bug 545725 - re-verify creds and fail sanely
|
||||
if (!this._verifyLogin()) {
|
||||
if (!this.verifyLogin()) {
|
||||
Status.sync = CREDENTIALS_CHANGED;
|
||||
this._log.info("Credentials have changed, aborting sync and forcing re-login.");
|
||||
return false;
|
||||
|
|
|
@ -29,6 +29,7 @@ function run_test() {
|
|||
try {
|
||||
Weave.Service.serverURL = "http://localhost:8080/";
|
||||
Weave.Service.clusterURL = "http://localhost:8080/";
|
||||
Svc.Prefs.set("autoconnect", false);
|
||||
|
||||
_("Initial state is ok.");
|
||||
do_check_eq(Status.service, STATUS_OK);
|
||||
|
@ -38,6 +39,7 @@ function run_test() {
|
|||
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
|
||||
do_check_eq(Status.login, LOGIN_FAILED_NO_USERNAME);
|
||||
do_check_false(Weave.Service.isLoggedIn);
|
||||
do_check_false(Svc.Prefs.get("autoconnect"));
|
||||
|
||||
_("Try again with username and password set.");
|
||||
Weave.Service.username = "johndoe";
|
||||
|
@ -46,6 +48,7 @@ function run_test() {
|
|||
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
|
||||
do_check_eq(Status.login, LOGIN_FAILED_NO_PASSPHRASE);
|
||||
do_check_false(Weave.Service.isLoggedIn);
|
||||
do_check_false(Svc.Prefs.get("autoconnect"));
|
||||
|
||||
_("Success if passphrase is set.");
|
||||
Weave.Service.passphrase = "foo";
|
||||
|
@ -53,6 +56,7 @@ function run_test() {
|
|||
do_check_eq(Status.service, STATUS_OK);
|
||||
do_check_eq(Status.login, LOGIN_SUCCEEDED);
|
||||
do_check_true(Weave.Service.isLoggedIn);
|
||||
do_check_true(Svc.Prefs.get("autoconnect"));
|
||||
|
||||
} finally {
|
||||
Svc.Prefs.resetBranch("");
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
Cu.import("resource://weave/log4moz.js");
|
||||
Cu.import("resource://weave/service.js");
|
||||
Cu.import("resource://weave/status.js");
|
||||
Cu.import("resource://weave/constants.js");
|
||||
Cu.import("resource://weave/util.js");
|
||||
|
||||
function login_handler(request, response) {
|
||||
// btoa('johndoe:ilovejane') == am9obmRvZTppbG92ZWphbmU=
|
||||
let body;
|
||||
if (request.hasHeader("Authorization") &&
|
||||
request.getHeader("Authorization") == "Basic am9obmRvZTppbG92ZWphbmU=") {
|
||||
body = "{}";
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
} else {
|
||||
body = "Unauthorized";
|
||||
response.setStatusLine(request.httpVersion, 401, "Unauthorized");
|
||||
}
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
let logger = Log4Moz.repository.rootLogger;
|
||||
Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
|
||||
|
||||
let server = httpd_setup({
|
||||
"/1.0/johndoe/info/collections": login_handler
|
||||
});
|
||||
|
||||
try {
|
||||
Weave.Service.serverURL = "http://localhost:8080/";
|
||||
Weave.Service.clusterURL = "http://localhost:8080/";
|
||||
|
||||
_("Initial state is ok.");
|
||||
do_check_eq(Status.service, STATUS_OK);
|
||||
|
||||
_("Credentials won't check out because we're not configured yet.");
|
||||
do_check_false(Weave.Service.verifyLogin());
|
||||
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
|
||||
do_check_eq(Status.login, LOGIN_FAILED_NO_USERNAME);
|
||||
|
||||
_("Try again with username and password set.");
|
||||
Weave.Service.username = "johndoe";
|
||||
Weave.Service.password = "ilovejane";
|
||||
do_check_false(Weave.Service.verifyLogin());
|
||||
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
|
||||
do_check_eq(Status.login, LOGIN_FAILED_NO_PASSPHRASE);
|
||||
|
||||
_("Success if passphrase is set.");
|
||||
Weave.Service.passphrase = "foo";
|
||||
Weave.Service.login();
|
||||
do_check_eq(Status.service, STATUS_OK);
|
||||
do_check_eq(Status.login, LOGIN_SUCCEEDED);
|
||||
do_check_true(Weave.Service.isLoggedIn);
|
||||
|
||||
} finally {
|
||||
Svc.Prefs.resetBranch("");
|
||||
server.stop(function() {});
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче