1
Cu.import("resource://services-sync/main.js");
2
Cu.import("resource://services-sync/util.js");
3
Cu.import("resource://services-sync/constants.js");
7
function send(statusCode, status, body) {
8
return function(request, response) {
9
requestBody = readBytesFromInputStream(request.bodyInputStream);
10
response.setStatusLine(request.httpVersion, statusCode, status);
11
response.bodyOutputStream.write(body, body.length);
19
Weave.Service.serverURL = "http://localhost:8080/";
20
Weave.Service.username = "johndoe";
21
Weave.Service.password = "ilovejane";
23
_("changePassword() returns false for a network error, the password won't change.");
24
let res = Weave.Service.changePassword("ILoveJane83");
26
do_check_eq(Weave.Service.password, "ilovejane");
28
_("Let's fire up the server and actually change the password.");
29
server = httpd_setup({
30
"/user/1.0/johndoe/password": send(200, "OK", ""),
31
"/user/1.0/janedoe/password": send(401, "Unauthorized", "Forbidden!")
35
res = Weave.Service.changePassword("ILoveJane83");
37
do_check_eq(Weave.Service.password, "ILoveJane83");
38
do_check_eq(requestBody, "ILoveJane83");
40
_("Make sure the password has been persisted in the login manager.");
41
let logins = Weave.Svc.Login.findLogins({}, PWDMGR_HOST, null,
42
PWDMGR_PASSWORD_REALM);
43
do_check_eq(logins[0].password, "ILoveJane83");
45
_("A non-ASCII password is UTF-8 encoded.");
46
res = Weave.Service.changePassword("moneyislike$\u20ac\xa5\u5143");
48
do_check_eq(Weave.Service.password, "moneyislike$\u20ac\xa5\u5143");
49
do_check_eq(requestBody, Utils.encodeUTF8("moneyislike$\u20ac\xa5\u5143"));
51
_("changePassword() returns false for a server error, the password won't change.");
52
Weave.Svc.Login.removeAllLogins();
53
Weave.Service.username = "janedoe";
54
Weave.Service.password = "ilovejohn";
55
res = Weave.Service.changePassword("ILoveJohn86");
57
do_check_eq(Weave.Service.password, "ilovejohn");
60
Weave.Svc.Prefs.resetBranch("");
61
Weave.Svc.Login.removeAllLogins();
63
server.stop(do_test_finished);