services/sync/tests/unit/test_fxa_service_cluster.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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/service.js");
michael@0 5 Cu.import("resource://services-sync/util.js");
michael@0 6 Cu.import("resource://testing-common/services/sync/fxa_utils.js");
michael@0 7 Cu.import("resource://testing-common/services/sync/utils.js");
michael@0 8
michael@0 9 add_task(function test_findCluster() {
michael@0 10 _("Test FxA _findCluster()");
michael@0 11
michael@0 12 _("_findCluster() throws on 500 errors.");
michael@0 13 initializeIdentityWithTokenServerResponse({
michael@0 14 status: 500,
michael@0 15 headers: [],
michael@0 16 body: "",
michael@0 17 });
michael@0 18
michael@0 19 yield Service.identity.initializeWithCurrentIdentity();
michael@0 20 yield Assert_rejects(Service.identity.whenReadyToAuthenticate.promise,
michael@0 21 "should reject due to 500");
michael@0 22
michael@0 23 Assert.throws(function() {
michael@0 24 Service._clusterManager._findCluster();
michael@0 25 });
michael@0 26
michael@0 27 _("_findCluster() returns null on authentication errors.");
michael@0 28 initializeIdentityWithTokenServerResponse({
michael@0 29 status: 401,
michael@0 30 headers: {"content-type": "application/json"},
michael@0 31 body: "{}",
michael@0 32 });
michael@0 33
michael@0 34 yield Service.identity.initializeWithCurrentIdentity();
michael@0 35 yield Assert_rejects(Service.identity.whenReadyToAuthenticate.promise,
michael@0 36 "should reject due to 401");
michael@0 37
michael@0 38 cluster = Service._clusterManager._findCluster();
michael@0 39 Assert.strictEqual(cluster, null);
michael@0 40
michael@0 41 _("_findCluster() works with correct tokenserver response.");
michael@0 42 let endpoint = "http://example.com/something";
michael@0 43 initializeIdentityWithTokenServerResponse({
michael@0 44 status: 200,
michael@0 45 headers: {"content-type": "application/json"},
michael@0 46 body:
michael@0 47 JSON.stringify({
michael@0 48 api_endpoint: endpoint,
michael@0 49 duration: 300,
michael@0 50 id: "id",
michael@0 51 key: "key",
michael@0 52 uid: "uid",
michael@0 53 })
michael@0 54 });
michael@0 55
michael@0 56 yield Service.identity.initializeWithCurrentIdentity();
michael@0 57 yield Service.identity.whenReadyToAuthenticate.promise;
michael@0 58 cluster = Service._clusterManager._findCluster();
michael@0 59 // The cluster manager ensures a trailing "/"
michael@0 60 Assert.strictEqual(cluster, endpoint + "/");
michael@0 61
michael@0 62 Svc.Prefs.resetBranch("");
michael@0 63 });
michael@0 64
michael@0 65 function run_test() {
michael@0 66 initTestLogging();
michael@0 67 run_next_test();
michael@0 68 }

mercurial