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