gecko/services/sync/tests/unit/test_service_checkAccount.js
Philipp von Weitershausen 38347b08b2 Bug 589979 - Generate username from email address (part 2) [r=mconnor]
The Weave.Service.account property holds whatever the user entered for email address/username. If it only contains characters valid for usernames, it is assumed to be a username. Otherwise it's SHA1 hashed and base32 encoded.

The special tab mangling (to avoid broken Basic Auth headers) is now obsolete.

--HG--
rename : services/sync/tests/unit/test_service_checkUsername.js => services/sync/tests/unit/test_service_checkAccount.js
2010-09-13 17:17:37 +02:00

39 lines
1.1 KiB
JavaScript

Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/util.js");
function send(statusCode, status, body) {
return function(request, response) {
response.setStatusLine(request.httpVersion, statusCode, status);
response.bodyOutputStream.write(body, body.length);
};
}
function run_test() {
do_test_pending();
let server = httpd_setup({
"/user/1.0/johndoe": send(200, "OK", "1"),
"/user/1.0/janedoe": send(200, "OK", "0"),
// john@doe.com
"/user/1.0/7wohs32cngzuqt466q3ge7indszva4of": send(200, "OK", "0")
});
try {
Service.serverURL = "http://localhost:8080/";
_("A 404 will be recorded as 'generic-server-error'");
do_check_eq(Service.checkAccount("jimdoe"), "generic-server-error");
_("Account that's not available.");
do_check_eq(Service.checkAccount("johndoe"), "notAvailable");
_("Account that's available.");
do_check_eq(Service.checkAccount("janedoe"), "available");
_("Email address based account.");
do_check_eq(Service.checkAccount("john@doe.com"), "available");
} finally {
Svc.Prefs.resetBranch("");
server.stop(do_test_finished);
}
}