Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 Cu.import("resource://gre/modules/Log.jsm");
5 Cu.import("resource://services-sync/engines/bookmarks.js");
6 Cu.import("resource://services-sync/keys.js");
7 Cu.import("resource://services-sync/record.js");
8 Cu.import("resource://services-sync/service.js");
9 Cu.import("resource://services-sync/util.js");
10 Cu.import("resource://testing-common/services/sync/utils.js");
12 function prepareBookmarkItem(collection, id) {
13 let b = new Bookmark(collection, id);
14 b.cleartext.stuff = "my payload here";
15 return b;
16 }
18 function run_test() {
19 ensureLegacyIdentityManager();
20 Service.identity.username = "john@example.com";
21 Service.identity.syncKey = "abcdeabcdeabcdeabcdeabcdea";
22 generateNewKeys(Service.collectionKeys);
23 let keyBundle = Service.identity.syncKeyBundle;
25 let log = Log.repository.getLogger("Test");
26 Log.repository.rootLogger.addAppender(new Log.DumpAppender());
28 log.info("Creating a record");
30 let u = "http://localhost:8080/storage/bookmarks/foo";
31 let placesItem = new PlacesItem("bookmarks", "foo", "bookmark");
32 let bookmarkItem = prepareBookmarkItem("bookmarks", "foo");
34 log.info("Checking getTypeObject");
35 do_check_eq(placesItem.getTypeObject(placesItem.type), Bookmark);
36 do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark);
38 bookmarkItem.encrypt(keyBundle);
39 log.info("Ciphertext is " + bookmarkItem.ciphertext);
40 do_check_true(bookmarkItem.ciphertext != null);
42 log.info("Decrypting the record");
44 let payload = bookmarkItem.decrypt(keyBundle);
45 do_check_eq(payload.stuff, "my payload here");
46 do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark);
47 do_check_neq(payload, bookmarkItem.payload); // wrap.data.payload is the encrypted one
48 }