services/sync/tests/unit/test_fxa_service_cluster.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial