services/sync/tests/unit/test_fxa_service_cluster.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:91146fc241f8
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
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");
8
9 add_task(function test_findCluster() {
10 _("Test FxA _findCluster()");
11
12 _("_findCluster() throws on 500 errors.");
13 initializeIdentityWithTokenServerResponse({
14 status: 500,
15 headers: [],
16 body: "",
17 });
18
19 yield Service.identity.initializeWithCurrentIdentity();
20 yield Assert_rejects(Service.identity.whenReadyToAuthenticate.promise,
21 "should reject due to 500");
22
23 Assert.throws(function() {
24 Service._clusterManager._findCluster();
25 });
26
27 _("_findCluster() returns null on authentication errors.");
28 initializeIdentityWithTokenServerResponse({
29 status: 401,
30 headers: {"content-type": "application/json"},
31 body: "{}",
32 });
33
34 yield Service.identity.initializeWithCurrentIdentity();
35 yield Assert_rejects(Service.identity.whenReadyToAuthenticate.promise,
36 "should reject due to 401");
37
38 cluster = Service._clusterManager._findCluster();
39 Assert.strictEqual(cluster, null);
40
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 });
55
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 + "/");
61
62 Svc.Prefs.resetBranch("");
63 });
64
65 function run_test() {
66 initTestLogging();
67 run_next_test();
68 }

mercurial