services/sync/tests/unit/test_sendcredentials_controller.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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/jpakeclient.js");
michael@0 6 Cu.import("resource://services-sync/service.js");
michael@0 7 Cu.import("resource://services-sync/util.js");
michael@0 8 Cu.import("resource://testing-common/services/sync/utils.js");
michael@0 9
michael@0 10 function run_test() {
michael@0 11 ensureLegacyIdentityManager();
michael@0 12 setBasicCredentials("johndoe", "ilovejane", Utils.generatePassphrase());
michael@0 13 Service.serverURL = "http://weave.server/";
michael@0 14
michael@0 15 initTestLogging("Trace");
michael@0 16 Log.repository.getLogger("Sync.SendCredentialsController").level = Log.Level.Trace;
michael@0 17 Log.repository.getLogger("Sync.SyncScheduler").level = Log.Level.Trace;
michael@0 18 run_next_test();
michael@0 19 }
michael@0 20
michael@0 21 function make_sendCredentials_test(topic) {
michael@0 22 return function test_sendCredentials() {
michael@0 23 _("Test sending credentials on " + topic + " observer notification.");
michael@0 24
michael@0 25 let sendAndCompleteCalled = false;
michael@0 26 let jpakeclient = {
michael@0 27 sendAndComplete: function sendAndComplete(data) {
michael@0 28 // Verify that the controller unregisters itself as an observer
michael@0 29 // when the exchange is complete by faking another notification.
michael@0 30 do_check_false(sendAndCompleteCalled);
michael@0 31 sendAndCompleteCalled = true;
michael@0 32
michael@0 33 // Verify it sends the correct data.
michael@0 34 do_check_eq(data.account, Service.identity.account);
michael@0 35 do_check_eq(data.password, Service.identity.basicPassword);
michael@0 36 do_check_eq(data.synckey, Service.identity.syncKey);
michael@0 37 do_check_eq(data.serverURL, Service.serverURL);
michael@0 38
michael@0 39 this.controller.onComplete();
michael@0 40 // Verify it schedules a sync for the expected interval.
michael@0 41 let expectedInterval = Service.scheduler.activeInterval;
michael@0 42 do_check_true(Service.scheduler.nextSync - Date.now() <= expectedInterval);
michael@0 43
michael@0 44 // Signal the end of another sync. We shouldn't be registered anymore,
michael@0 45 // so we shouldn't re-enter this method (cf sendAndCompleteCalled above)
michael@0 46 Svc.Obs.notify(topic);
michael@0 47
michael@0 48 Service.scheduler.setDefaults();
michael@0 49 Utils.nextTick(run_next_test);
michael@0 50 }
michael@0 51 };
michael@0 52 jpakeclient.controller = new SendCredentialsController(jpakeclient, Service);
michael@0 53 Svc.Obs.notify(topic);
michael@0 54 };
michael@0 55 }
michael@0 56
michael@0 57 add_test(make_sendCredentials_test("weave:service:sync:finish"));
michael@0 58 add_test(make_sendCredentials_test("weave:service:sync:error"));
michael@0 59
michael@0 60
michael@0 61 add_test(function test_abort() {
michael@0 62 _("Test aborting the J-PAKE exchange.");
michael@0 63
michael@0 64 let jpakeclient = {
michael@0 65 sendAndComplete: function sendAndComplete() {
michael@0 66 do_throw("Shouldn't get here!");
michael@0 67 }
michael@0 68 };
michael@0 69 jpakeclient.controller = new SendCredentialsController(jpakeclient, Service);
michael@0 70
michael@0 71 // Verify that the controller unregisters itself when the exchange
michael@0 72 // was aborted.
michael@0 73 jpakeclient.controller.onAbort(JPAKE_ERROR_USERABORT);
michael@0 74 Svc.Obs.notify("weave:service:sync:finish");
michael@0 75 Utils.nextTick(run_next_test);
michael@0 76 });
michael@0 77
michael@0 78
michael@0 79 add_test(function test_startOver() {
michael@0 80 _("Test wiping local Sync config aborts transaction.");
michael@0 81
michael@0 82 let abortCalled = false;
michael@0 83 let jpakeclient = {
michael@0 84 abort: function abort() {
michael@0 85 abortCalled = true;
michael@0 86 this.controller.onAbort(JPAKE_ERROR_USERABORT);
michael@0 87 },
michael@0 88 sendAndComplete: function sendAndComplete() {
michael@0 89 do_throw("Shouldn't get here!");
michael@0 90 }
michael@0 91 };
michael@0 92 jpakeclient.controller = new SendCredentialsController(jpakeclient, Service);
michael@0 93
michael@0 94 Svc.Obs.notify("weave:service:start-over");
michael@0 95 do_check_true(abortCalled);
michael@0 96
michael@0 97 // Ensure that the controller no longer does anything if a sync
michael@0 98 // finishes now or -- more likely -- errors out.
michael@0 99 Svc.Obs.notify("weave:service:sync:error");
michael@0 100
michael@0 101 Utils.nextTick(run_next_test);
michael@0 102 });

mercurial