test_fxa_service_cluster.js (1604B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const { Service } = ChromeUtils.importESModule( 5 "resource://services-sync/service.sys.mjs" 6 ); 7 const { initializeIdentityWithTokenServerResponse } = 8 ChromeUtils.importESModule( 9 "resource://testing-common/services/sync/fxa_utils.sys.mjs" 10 ); 11 12 add_task(async function test_findCluster() { 13 _("Test FxA _findCluster()"); 14 15 _("_findCluster() throws on 500 errors."); 16 initializeIdentityWithTokenServerResponse({ 17 status: 500, 18 headers: [], 19 body: "", 20 }); 21 22 await Assert.rejects( 23 Service.identity._findCluster(), 24 /TokenServerClientServerError/ 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 let cluster = await Service.identity._findCluster(); 35 Assert.strictEqual(cluster, null); 36 37 _("_findCluster() works with correct tokenserver response."); 38 let endpoint = "http://example.com/something"; 39 initializeIdentityWithTokenServerResponse({ 40 status: 200, 41 headers: { "content-type": "application/json" }, 42 body: JSON.stringify({ 43 api_endpoint: endpoint, 44 duration: 300, 45 id: "id", 46 key: "key", 47 uid: "uid", 48 }), 49 }); 50 51 cluster = await Service.identity._findCluster(); 52 // The cluster manager ensures a trailing "/" 53 Assert.strictEqual(cluster, endpoint + "/"); 54 55 for (const pref of Svc.PrefBranch.getChildList("")) { 56 Svc.PrefBranch.clearUserPref(pref); 57 } 58 });