Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | Cu.import("resource://services-sync/util.js"); |
michael@0 | 5 | Cu.import("resource://services-sync/service.js"); |
michael@0 | 6 | Cu.import("resource://testing-common/services/sync/utils.js"); |
michael@0 | 7 | |
michael@0 | 8 | function run_test() { |
michael@0 | 9 | initTestLogging("Trace"); |
michael@0 | 10 | |
michael@0 | 11 | let requestBody; |
michael@0 | 12 | let secretHeader; |
michael@0 | 13 | function send(statusCode, status, body) { |
michael@0 | 14 | return function(request, response) { |
michael@0 | 15 | requestBody = readBytesFromInputStream(request.bodyInputStream); |
michael@0 | 16 | if (request.hasHeader("X-Weave-Secret")) { |
michael@0 | 17 | secretHeader = request.getHeader("X-Weave-Secret"); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | response.setStatusLine(request.httpVersion, statusCode, status); |
michael@0 | 21 | response.bodyOutputStream.write(body, body.length); |
michael@0 | 22 | }; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | do_test_pending(); |
michael@0 | 26 | let server = httpd_setup({ |
michael@0 | 27 | // john@doe.com |
michael@0 | 28 | "/user/1.0/7wohs32cngzuqt466q3ge7indszva4of": send(200, "OK", "0"), |
michael@0 | 29 | // jane@doe.com |
michael@0 | 30 | "/user/1.0/vuuf3eqgloxpxmzph27f5a6ve7gzlrms": send(400, "Bad Request", "2"), |
michael@0 | 31 | // jim@doe.com |
michael@0 | 32 | "/user/1.0/vz6fhecgw5t3sgx3a4cektoiokyczkqd": send(500, "Server Error", "Server Error") |
michael@0 | 33 | }); |
michael@0 | 34 | try { |
michael@0 | 35 | Service.serverURL = server.baseURI; |
michael@0 | 36 | |
michael@0 | 37 | _("Create an account."); |
michael@0 | 38 | let res = Service.createAccount("john@doe.com", "mysecretpw", |
michael@0 | 39 | "challenge", "response"); |
michael@0 | 40 | do_check_eq(res, null); |
michael@0 | 41 | let payload = JSON.parse(requestBody); |
michael@0 | 42 | do_check_eq(payload.password, "mysecretpw"); |
michael@0 | 43 | do_check_eq(payload.email, "john@doe.com"); |
michael@0 | 44 | do_check_eq(payload["captcha-challenge"], "challenge"); |
michael@0 | 45 | do_check_eq(payload["captcha-response"], "response"); |
michael@0 | 46 | |
michael@0 | 47 | _("A non-ASCII password is UTF-8 encoded."); |
michael@0 | 48 | const moneyPassword = "moneyislike$£¥"; |
michael@0 | 49 | res = Service.createAccount("john@doe.com", moneyPassword, |
michael@0 | 50 | "challenge", "response"); |
michael@0 | 51 | do_check_eq(res, null); |
michael@0 | 52 | payload = JSON.parse(requestBody); |
michael@0 | 53 | do_check_eq(payload.password, Utils.encodeUTF8(moneyPassword)); |
michael@0 | 54 | |
michael@0 | 55 | _("Invalid captcha or other user-friendly error."); |
michael@0 | 56 | res = Service.createAccount("jane@doe.com", "anothersecretpw", |
michael@0 | 57 | "challenge", "response"); |
michael@0 | 58 | do_check_eq(res, "invalid-captcha"); |
michael@0 | 59 | |
michael@0 | 60 | _("Generic server error."); |
michael@0 | 61 | res = Service.createAccount("jim@doe.com", "preciousss", |
michael@0 | 62 | "challenge", "response"); |
michael@0 | 63 | do_check_eq(res, "generic-server-error"); |
michael@0 | 64 | |
michael@0 | 65 | _("Admin secret preference is passed as HTTP header token."); |
michael@0 | 66 | Svc.Prefs.set("admin-secret", "my-server-secret"); |
michael@0 | 67 | res = Service.createAccount("john@doe.com", "mysecretpw", |
michael@0 | 68 | "challenge", "response"); |
michael@0 | 69 | do_check_eq(secretHeader, "my-server-secret"); |
michael@0 | 70 | |
michael@0 | 71 | } finally { |
michael@0 | 72 | Svc.Prefs.resetBranch(""); |
michael@0 | 73 | server.stop(do_test_finished); |
michael@0 | 74 | } |
michael@0 | 75 | } |