~ubuntu-branches/ubuntu/trusty/enigmail/trusty-updates

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2011-06-07 14:35:53 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110607143553-fbgqhhvh8g8h6j1y
Tags: 2:1.2~a2~cvs20110606t2200-0ubuntu1
* Update to latest trunk snapshot for Thunderbird beta compat

* Remove build/pgo/profileserver.py from debian/clean. The new build
  system has a target depending on this
  - update debian/clean
* Drop debian/patches/autoconf.diff, just generate this at build time
* Refresh debian/patches/build_system_dont_link_libxul.diff
* libipc seems to be renamed to libipc-pipe. Fix genxpi and chrome.manifest
  to fix this 
  - add debian/patches/ipc-pipe_rename.diff
  - update debian/patches/series
* The makefiles in extensions/enigmail/ipc have an incorrect DEPTH
  attribute. Fix this so that they can find the rest of the build system
  - add debian/patches/makefile_depth.diff
  - update debian/patches/series
* Drop debian/patches/makefile-in-empty-xpcom-fix.diff - fixed in the
  current version
* Don't register a class ID multiple times, as this breaks enigmail entirely
  - add debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Look for the Thunderbird 5 SDK
  - update debian/rules
  - update debian/control
* Run autoconf2.13 at build time
  - update debian/rules
  - update debian/control
* Add useless mesa-common-dev build-dep, just to satisfy the build system.
  We should just patch this out entirely really, but that's for another upload
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Cu.import("resource://services-sync/util.js");
 
2
 
 
3
function run_test() {
 
4
  // Testing byte array manipulation.
 
5
  do_check_eq("FOOBAR", Utils.byteArrayToString([70, 79, 79, 66, 65, 82]));
 
6
  do_check_eq("", Utils.byteArrayToString([]));
 
7
  
 
8
  _("Testing encoding...");
 
9
  // Test vectors from RFC 4648
 
10
  do_check_eq(Utils.encodeBase32(""), "");
 
11
  do_check_eq(Utils.encodeBase32("f"), "MY======");
 
12
  do_check_eq(Utils.encodeBase32("fo"), "MZXQ====");
 
13
  do_check_eq(Utils.encodeBase32("foo"), "MZXW6===");
 
14
  do_check_eq(Utils.encodeBase32("foob"), "MZXW6YQ=");
 
15
  do_check_eq(Utils.encodeBase32("fooba"), "MZXW6YTB");
 
16
  do_check_eq(Utils.encodeBase32("foobar"), "MZXW6YTBOI======");
 
17
 
 
18
  do_check_eq(Utils.encodeBase32("Bacon is a vegetable."),
 
19
              "IJQWG33OEBUXGIDBEB3GKZ3FORQWE3DFFY======");
 
20
 
 
21
  _("Checking assumptions...");
 
22
  for (let i = 0; i <= 255; ++i)
 
23
    do_check_eq(undefined | i, i);
 
24
 
 
25
  _("Testing decoding...");
 
26
  do_check_eq(Utils.decodeBase32(""), "");
 
27
  do_check_eq(Utils.decodeBase32("MY======"), "f");
 
28
  do_check_eq(Utils.decodeBase32("MZXQ===="), "fo");
 
29
  do_check_eq(Utils.decodeBase32("MZXW6YTB"), "fooba");
 
30
  do_check_eq(Utils.decodeBase32("MZXW6YTBOI======"), "foobar");
 
31
 
 
32
  // Same with incorrect or missing padding.
 
33
  do_check_eq(Utils.decodeBase32("MZXW6YTBOI=="), "foobar");
 
34
  do_check_eq(Utils.decodeBase32("MZXW6YTBOI"), "foobar");
 
35
 
 
36
  let encoded = Utils.encodeBase32("Bacon is a vegetable.");
 
37
  _("Encoded to " + JSON.stringify(encoded));
 
38
  do_check_eq(Utils.decodeBase32(encoded), "Bacon is a vegetable.");
 
39
 
 
40
  // Test failure.
 
41
  let err;
 
42
  try {
 
43
    Utils.decodeBase32("000");
 
44
  } catch (ex) {
 
45
    err = ex;
 
46
  }
 
47
  do_check_eq(err, "Unknown character in base32: 0");
 
48
  
 
49
  // Testing our own variant.
 
50
  do_check_eq(Utils.encodeKeyBase32("foobarbafoobarba"), "mzxw6ytb9jrgcztpn5rgc4tcme");
 
51
  do_check_eq(Utils.decodeKeyBase32("mzxw6ytb9jrgcztpn5rgc4tcme"), "foobarbafoobarba");
 
52
  do_check_eq(
 
53
      Utils.encodeKeyBase32("\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"),
 
54
      "aeaqcaibaeaqcaibaeaqcaibae");
 
55
  do_check_eq(
 
56
      Utils.decodeKeyBase32("aeaqcaibaeaqcaibaeaqcaibae"),
 
57
      "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01");
 
58
}