1
Cu.import("resource://services-sync/record.js");
2
Cu.import("resource://services-sync/engines/bookmarks.js");
3
Cu.import("resource://services-sync/identity.js");
4
Cu.import("resource://services-sync/log4moz.js");
5
Cu.import("resource://services-sync/util.js");
7
function prepareBookmarkItem(collection, id) {
8
let b = new Bookmark(collection, id);
9
b.cleartext.stuff = "my payload here";
14
let keyBundle = ID.set("WeaveCryptoID", new SyncKeyBundle(null, "john@example.com"));
15
keyBundle.keyStr = "abcdeabcdeabcdeabcdeabcdea";
17
CollectionKeys.generateNewKeys();
19
let log = Log4Moz.repository.getLogger("Test");
20
Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
22
log.info("Creating a record");
24
let u = "http://localhost:8080/storage/bookmarks/foo";
25
let placesItem = new PlacesItem("bookmarks", "foo", "bookmark");
26
let bookmarkItem = prepareBookmarkItem("bookmarks", "foo");
28
log.info("Checking getTypeObject");
29
do_check_eq(placesItem.getTypeObject(placesItem.type), Bookmark);
30
do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark);
32
bookmarkItem.encrypt(keyBundle);
33
log.info("Ciphertext is " + bookmarkItem.ciphertext);
34
do_check_true(bookmarkItem.ciphertext != null);
36
log.info("Decrypting the record");
38
let payload = bookmarkItem.decrypt(keyBundle);
39
do_check_eq(payload.stuff, "my payload here");
40
do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark);
41
do_check_neq(payload, bookmarkItem.payload); // wrap.data.payload is the encrypted one