test_clients_escape.js (1751B)
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 8 add_task(async function test_clients_escape() { 9 _("Set up test fixtures."); 10 11 await configureIdentity(); 12 let keyBundle = Service.identity.syncKeyBundle; 13 14 let engine = Service.clientsEngine; 15 16 try { 17 _("Test that serializing client records results in uploadable ascii"); 18 engine.localID = "ascii"; 19 engine.localName = "wéävê"; 20 21 _("Make sure we have the expected record"); 22 let record = await engine._createRecord("ascii"); 23 Assert.equal(record.id, "ascii"); 24 Assert.equal(record.name, "wéävê"); 25 26 _("Encrypting record..."); 27 await record.encrypt(keyBundle); 28 _("Encrypted."); 29 30 let serialized = JSON.stringify(record); 31 let checkCount = 0; 32 _("Checking for all ASCII:", serialized); 33 for (let ch of serialized) { 34 let code = ch.charCodeAt(0); 35 _("Checking asciiness of '", ch, "'=", code); 36 Assert.less(code, 128); 37 checkCount++; 38 } 39 40 _("Processed", checkCount, "characters out of", serialized.length); 41 Assert.equal(checkCount, serialized.length); 42 43 _("Making sure the record still looks like it did before"); 44 await record.decrypt(keyBundle); 45 Assert.equal(record.id, "ascii"); 46 Assert.equal(record.name, "wéävê"); 47 48 _("Sanity check that creating the record also gives the same"); 49 record = await engine._createRecord("ascii"); 50 Assert.equal(record.id, "ascii"); 51 Assert.equal(record.name, "wéävê"); 52 } finally { 53 for (const pref of Svc.PrefBranch.getChildList("")) { 54 Svc.PrefBranch.clearUserPref(pref); 55 } 56 } 57 });