services/sync/tests/unit/test_clients_escape.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

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/keys.js");
michael@0 5 Cu.import("resource://services-sync/record.js");
michael@0 6 Cu.import("resource://services-sync/service.js");
michael@0 7 Cu.import("resource://services-sync/util.js");
michael@0 8 Cu.import("resource://testing-common/services/sync/utils.js");
michael@0 9
michael@0 10 function run_test() {
michael@0 11 _("Set up test fixtures.");
michael@0 12
michael@0 13 ensureLegacyIdentityManager();
michael@0 14 Service.identity.username = "john@example.com";
michael@0 15 Service.clusterURL = "http://fakebase/";
michael@0 16 let baseUri = "http://fakebase/1.1/foo/storage/";
michael@0 17 let pubUri = baseUri + "keys/pubkey";
michael@0 18 let privUri = baseUri + "keys/privkey";
michael@0 19
michael@0 20 Service.identity.syncKey = "abcdeabcdeabcdeabcdeabcdea";
michael@0 21 let keyBundle = Service.identity.syncKeyBundle;
michael@0 22
michael@0 23 let engine = Service.clientsEngine;
michael@0 24
michael@0 25 try {
michael@0 26 _("Test that serializing client records results in uploadable ascii");
michael@0 27 engine.localID = "ascii";
michael@0 28 engine.localName = "wéävê";
michael@0 29
michael@0 30 _("Make sure we have the expected record");
michael@0 31 let record = engine._createRecord("ascii");
michael@0 32 do_check_eq(record.id, "ascii");
michael@0 33 do_check_eq(record.name, "wéävê");
michael@0 34
michael@0 35 _("Encrypting record...");
michael@0 36 record.encrypt(keyBundle);
michael@0 37 _("Encrypted.");
michael@0 38
michael@0 39 let serialized = JSON.stringify(record);
michael@0 40 let checkCount = 0;
michael@0 41 _("Checking for all ASCII:", serialized);
michael@0 42 Array.forEach(serialized, function(ch) {
michael@0 43 let code = ch.charCodeAt(0);
michael@0 44 _("Checking asciiness of '", ch, "'=", code);
michael@0 45 do_check_true(code < 128);
michael@0 46 checkCount++;
michael@0 47 });
michael@0 48
michael@0 49 _("Processed", checkCount, "characters out of", serialized.length);
michael@0 50 do_check_eq(checkCount, serialized.length);
michael@0 51
michael@0 52 _("Making sure the record still looks like it did before");
michael@0 53 record.decrypt(keyBundle);
michael@0 54 do_check_eq(record.id, "ascii");
michael@0 55 do_check_eq(record.name, "wéävê");
michael@0 56
michael@0 57 _("Sanity check that creating the record also gives the same");
michael@0 58 record = engine._createRecord("ascii");
michael@0 59 do_check_eq(record.id, "ascii");
michael@0 60 do_check_eq(record.name, "wéävê");
michael@0 61 } finally {
michael@0 62 Svc.Prefs.resetBranch("");
michael@0 63 }
michael@0 64 }

mercurial