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://services-sync/constants.js"); |
michael@0 | 5 | Cu.import("resource://services-sync/service.js"); |
michael@0 | 6 | Cu.import("resource://services-sync/util.js"); |
michael@0 | 7 | Cu.import("resource://testing-common/services/sync/utils.js"); |
michael@0 | 8 | |
michael@0 | 9 | // Test upgrade of a dashed old-style sync key. |
michael@0 | 10 | function run_test() { |
michael@0 | 11 | const PBKDF2_KEY_BYTES = 16; |
michael@0 | 12 | initTestLogging("Trace"); |
michael@0 | 13 | ensureLegacyIdentityManager(); |
michael@0 | 14 | |
michael@0 | 15 | let passphrase = "abcde-abcde-abcde-abcde"; |
michael@0 | 16 | do_check_false(Utils.isPassphrase(passphrase)); |
michael@0 | 17 | |
michael@0 | 18 | let normalized = Utils.normalizePassphrase(passphrase); |
michael@0 | 19 | _("Normalized: " + normalized); |
michael@0 | 20 | |
michael@0 | 21 | // Still not a modern passphrase... |
michael@0 | 22 | do_check_false(Utils.isPassphrase(normalized)); |
michael@0 | 23 | |
michael@0 | 24 | // ... but different. |
michael@0 | 25 | do_check_neq(normalized, passphrase); |
michael@0 | 26 | do_check_eq(normalized, "abcdeabcdeabcdeabcde"); |
michael@0 | 27 | |
michael@0 | 28 | // Now run through the upgrade. |
michael@0 | 29 | Service.identity.account = "johndoe"; |
michael@0 | 30 | Service.syncID = "1234567890"; |
michael@0 | 31 | Service.identity.syncKey = normalized; // UI normalizes. |
michael@0 | 32 | do_check_false(Utils.isPassphrase(Service.identity.syncKey)); |
michael@0 | 33 | Service.upgradeSyncKey(Service.syncID); |
michael@0 | 34 | let upgraded = Service.identity.syncKey; |
michael@0 | 35 | _("Upgraded: " + upgraded); |
michael@0 | 36 | do_check_true(Utils.isPassphrase(upgraded)); |
michael@0 | 37 | |
michael@0 | 38 | // Now let's verify that it's been derived correctly, from the normalized |
michael@0 | 39 | // version, and the encoded sync ID. |
michael@0 | 40 | _("Sync ID: " + Service.syncID); |
michael@0 | 41 | let derivedKeyStr = |
michael@0 | 42 | Utils.derivePresentableKeyFromPassphrase(normalized, |
michael@0 | 43 | btoa(Service.syncID), |
michael@0 | 44 | PBKDF2_KEY_BYTES, true); |
michael@0 | 45 | _("Derived: " + derivedKeyStr); |
michael@0 | 46 | |
michael@0 | 47 | // Success! |
michael@0 | 48 | do_check_eq(derivedKeyStr, upgraded); |
michael@0 | 49 | } |