michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://gre/modules/Log.jsm"); michael@0: Cu.import("resource://services-sync/engines/bookmarks.js"); michael@0: Cu.import("resource://services-sync/keys.js"); michael@0: Cu.import("resource://services-sync/record.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: Cu.import("resource://testing-common/services/sync/utils.js"); michael@0: michael@0: function prepareBookmarkItem(collection, id) { michael@0: let b = new Bookmark(collection, id); michael@0: b.cleartext.stuff = "my payload here"; michael@0: return b; michael@0: } michael@0: michael@0: function run_test() { michael@0: ensureLegacyIdentityManager(); michael@0: Service.identity.username = "john@example.com"; michael@0: Service.identity.syncKey = "abcdeabcdeabcdeabcdeabcdea"; michael@0: generateNewKeys(Service.collectionKeys); michael@0: let keyBundle = Service.identity.syncKeyBundle; michael@0: michael@0: let log = Log.repository.getLogger("Test"); michael@0: Log.repository.rootLogger.addAppender(new Log.DumpAppender()); michael@0: michael@0: log.info("Creating a record"); michael@0: michael@0: let u = "http://localhost:8080/storage/bookmarks/foo"; michael@0: let placesItem = new PlacesItem("bookmarks", "foo", "bookmark"); michael@0: let bookmarkItem = prepareBookmarkItem("bookmarks", "foo"); michael@0: michael@0: log.info("Checking getTypeObject"); michael@0: do_check_eq(placesItem.getTypeObject(placesItem.type), Bookmark); michael@0: do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark); michael@0: michael@0: bookmarkItem.encrypt(keyBundle); michael@0: log.info("Ciphertext is " + bookmarkItem.ciphertext); michael@0: do_check_true(bookmarkItem.ciphertext != null); michael@0: michael@0: log.info("Decrypting the record"); michael@0: michael@0: let payload = bookmarkItem.decrypt(keyBundle); michael@0: do_check_eq(payload.stuff, "my payload here"); michael@0: do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark); michael@0: do_check_neq(payload, bookmarkItem.payload); // wrap.data.payload is the encrypted one michael@0: }