~ubuntu-branches/ubuntu/trusty/enigmail/trusty-updates

« back to all changes in this revision

Viewing changes to services/sync/tests/unit/test_service_changePassword.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2011-06-07 14:35:53 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110607143553-fbgqhhvh8g8h6j1y
Tags: 2:1.2~a2~cvs20110606t2200-0ubuntu1
* Update to latest trunk snapshot for Thunderbird beta compat

* Remove build/pgo/profileserver.py from debian/clean. The new build
  system has a target depending on this
  - update debian/clean
* Drop debian/patches/autoconf.diff, just generate this at build time
* Refresh debian/patches/build_system_dont_link_libxul.diff
* libipc seems to be renamed to libipc-pipe. Fix genxpi and chrome.manifest
  to fix this 
  - add debian/patches/ipc-pipe_rename.diff
  - update debian/patches/series
* The makefiles in extensions/enigmail/ipc have an incorrect DEPTH
  attribute. Fix this so that they can find the rest of the build system
  - add debian/patches/makefile_depth.diff
  - update debian/patches/series
* Drop debian/patches/makefile-in-empty-xpcom-fix.diff - fixed in the
  current version
* Don't register a class ID multiple times, as this breaks enigmail entirely
  - add debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Look for the Thunderbird 5 SDK
  - update debian/rules
  - update debian/control
* Run autoconf2.13 at build time
  - update debian/rules
  - update debian/control
* Add useless mesa-common-dev build-dep, just to satisfy the build system.
  We should just patch this out entirely really, but that's for another upload
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Cu.import("resource://services-sync/main.js");
 
2
Cu.import("resource://services-sync/util.js");
 
3
Cu.import("resource://services-sync/constants.js");
 
4
 
 
5
function run_test() {
 
6
  var requestBody;
 
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);
 
12
    };
 
13
  }
 
14
 
 
15
  let server;
 
16
 
 
17
  try {
 
18
 
 
19
    Weave.Service.serverURL = "http://localhost:8080/";
 
20
    Weave.Service.username = "johndoe";
 
21
    Weave.Service.password = "ilovejane";
 
22
 
 
23
    _("changePassword() returns false for a network error, the password won't change.");
 
24
    let res = Weave.Service.changePassword("ILoveJane83");
 
25
    do_check_false(res);
 
26
    do_check_eq(Weave.Service.password, "ilovejane");
 
27
 
 
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!")
 
32
    });
 
33
    do_test_pending();
 
34
 
 
35
    res = Weave.Service.changePassword("ILoveJane83");
 
36
    do_check_true(res);
 
37
    do_check_eq(Weave.Service.password, "ILoveJane83");
 
38
    do_check_eq(requestBody, "ILoveJane83");
 
39
 
 
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");
 
44
 
 
45
    _("A non-ASCII password is UTF-8 encoded.");
 
46
    res = Weave.Service.changePassword("moneyislike$\u20ac\xa5\u5143");
 
47
    do_check_true(res);
 
48
    do_check_eq(Weave.Service.password, "moneyislike$\u20ac\xa5\u5143");
 
49
    do_check_eq(requestBody, Utils.encodeUTF8("moneyislike$\u20ac\xa5\u5143"));
 
50
 
 
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");
 
56
    do_check_false(res);
 
57
    do_check_eq(Weave.Service.password, "ilovejohn");
 
58
 
 
59
  } finally {
 
60
    Weave.Svc.Prefs.resetBranch("");
 
61
    Weave.Svc.Login.removeAllLogins();
 
62
    if (server) {
 
63
      server.stop(do_test_finished);
 
64
    }
 
65
  }
 
66
}