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