From 79b588a085e1e911237e23285d8f79cceb1b949d Mon Sep 17 00:00:00 2001 From: Philipp von Weitershausen Date: Fri, 4 Jun 2010 14:44:04 +0100 Subject: [PATCH] Bug 569730 - Can't log in a 2nd computer [r=Mardak] Fix a regression introduced with the status.js refactoring (bug 557590). --- services/sync/modules/service.js | 4 +- .../sync/tests/unit/test_service_login.js | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 services/sync/tests/unit/test_service_login.js diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index e78a93dda537..c35e706507f5 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -333,7 +333,9 @@ WeaveSvc.prototype = { this._log.debug("checkSetup: no passphrase set"); Status.login = LOGIN_FAILED_NO_PASSPHRASE; } - + else + Status.service = STATUS_OK; + return Status.service; }, diff --git a/services/sync/tests/unit/test_service_login.js b/services/sync/tests/unit/test_service_login.js new file mode 100644 index 000000000000..851dd28c51dc --- /dev/null +++ b/services/sync/tests/unit/test_service_login.js @@ -0,0 +1,52 @@ +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/"; + + _("Try logging in. It wont' work because we're not configured yet."); + do_check_eq(Status.service, CLIENT_NOT_CONFIGURED); + Weave.Service.login(); + do_check_false(Weave.Service.isLoggedIn); + + _("Try again with username and password set."); + Weave.Service.username = "johndoe"; + Weave.Service.password = "ilovejane"; + // We need a non-empty passphrase for login to work. Even the + // setup wizard just sets this to 'foo' if there isn't a + // passphrase yet. + Weave.Service.passphrase = "foo"; + Weave.Service.login(); + do_check_true(Weave.Service.isLoggedIn); + + } finally { + Svc.Prefs.resetBranch(""); + server.stop(function() {}); + } +}