Thu, 22 Jan 2015 13:21:57 +0100
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://gre/modules/Log.jsm"); |
michael@0 | 5 | Cu.import("resource://services-sync/engines/bookmarks.js"); |
michael@0 | 6 | Cu.import("resource://services-sync/keys.js"); |
michael@0 | 7 | Cu.import("resource://services-sync/record.js"); |
michael@0 | 8 | Cu.import("resource://services-sync/service.js"); |
michael@0 | 9 | Cu.import("resource://services-sync/util.js"); |
michael@0 | 10 | Cu.import("resource://testing-common/services/sync/utils.js"); |
michael@0 | 11 | |
michael@0 | 12 | function prepareBookmarkItem(collection, id) { |
michael@0 | 13 | let b = new Bookmark(collection, id); |
michael@0 | 14 | b.cleartext.stuff = "my payload here"; |
michael@0 | 15 | return b; |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | function run_test() { |
michael@0 | 19 | ensureLegacyIdentityManager(); |
michael@0 | 20 | Service.identity.username = "john@example.com"; |
michael@0 | 21 | Service.identity.syncKey = "abcdeabcdeabcdeabcdeabcdea"; |
michael@0 | 22 | generateNewKeys(Service.collectionKeys); |
michael@0 | 23 | let keyBundle = Service.identity.syncKeyBundle; |
michael@0 | 24 | |
michael@0 | 25 | let log = Log.repository.getLogger("Test"); |
michael@0 | 26 | Log.repository.rootLogger.addAppender(new Log.DumpAppender()); |
michael@0 | 27 | |
michael@0 | 28 | log.info("Creating a record"); |
michael@0 | 29 | |
michael@0 | 30 | let u = "http://localhost:8080/storage/bookmarks/foo"; |
michael@0 | 31 | let placesItem = new PlacesItem("bookmarks", "foo", "bookmark"); |
michael@0 | 32 | let bookmarkItem = prepareBookmarkItem("bookmarks", "foo"); |
michael@0 | 33 | |
michael@0 | 34 | log.info("Checking getTypeObject"); |
michael@0 | 35 | do_check_eq(placesItem.getTypeObject(placesItem.type), Bookmark); |
michael@0 | 36 | do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark); |
michael@0 | 37 | |
michael@0 | 38 | bookmarkItem.encrypt(keyBundle); |
michael@0 | 39 | log.info("Ciphertext is " + bookmarkItem.ciphertext); |
michael@0 | 40 | do_check_true(bookmarkItem.ciphertext != null); |
michael@0 | 41 | |
michael@0 | 42 | log.info("Decrypting the record"); |
michael@0 | 43 | |
michael@0 | 44 | let payload = bookmarkItem.decrypt(keyBundle); |
michael@0 | 45 | do_check_eq(payload.stuff, "my payload here"); |
michael@0 | 46 | do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark); |
michael@0 | 47 | do_check_neq(payload, bookmarkItem.payload); // wrap.data.payload is the encrypted one |
michael@0 | 48 | } |