~ubuntu-branches/ubuntu/trusty/enigmail/trusty-security

« back to all changes in this revision

Viewing changes to services/sync/tests/unit/test_bookmark_record.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2011-08-12 12:25:06 UTC
  • mfrom: (0.12.4 upstream)
  • Revision ID: package-import@ubuntu.com-20110812122506-zko6c7zfexvyg71q
Tags: 2:1.2.1-0ubuntu1
* New upstream release
* Drop fix_install_rdf_xml_errors.diff - fixed upstream
* Refresh port_to_latest_thunderbird.diff
* Add a proper get-orig-source target which pulls the build system from
  lp:~mozillateam/mozilla-build-system/beta, now that we don't have the old
  build-system.tar.gz from xulrunner

Show diffs side-by-side

added added

removed removed

Lines of Context:
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");
6
 
  
7
 
function prepareBookmarkItem(collection, id) {
8
 
  let b = new Bookmark(collection, id);
9
 
  b.cleartext.stuff = "my payload here";
10
 
  return b;
11
 
}
12
 
 
13
 
function run_test() {
14
 
  let keyBundle = ID.set("WeaveCryptoID", new SyncKeyBundle(null, "john@example.com"));
15
 
  keyBundle.keyStr = "abcdeabcdeabcdeabcdeabcdea";
16
 
  
17
 
  CollectionKeys.generateNewKeys();
18
 
  
19
 
  let log = Log4Moz.repository.getLogger("Test");
20
 
  Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
21
 
 
22
 
  log.info("Creating a record");
23
 
 
24
 
  let u = "http://localhost:8080/storage/bookmarks/foo";
25
 
  let placesItem = new PlacesItem("bookmarks", "foo", "bookmark");
26
 
  let bookmarkItem = prepareBookmarkItem("bookmarks", "foo");
27
 
  
28
 
  log.info("Checking getTypeObject");
29
 
  do_check_eq(placesItem.getTypeObject(placesItem.type), Bookmark);
30
 
  do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark);
31
 
  
32
 
  bookmarkItem.encrypt(keyBundle);
33
 
  log.info("Ciphertext is " + bookmarkItem.ciphertext);
34
 
  do_check_true(bookmarkItem.ciphertext != null);
35
 
  
36
 
  log.info("Decrypting the record");
37
 
 
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
42
 
}