2008-06-18 11:54:24 -07:00
|
|
|
Cu.import("resource://weave/util.js");
|
2008-06-18 17:28:28 -07:00
|
|
|
Cu.import("resource://weave/async.js");
|
|
|
|
Cu.import("resource://weave/dav.js");
|
|
|
|
Cu.import("resource://weave/identity.js");
|
|
|
|
|
2008-06-20 15:39:07 -07:00
|
|
|
// ----------------------------------------
|
|
|
|
// Fake Data
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2008-06-18 17:28:28 -07:00
|
|
|
let __fakePasswords = {
|
|
|
|
'Mozilla Services Password': {foo: "bar"},
|
|
|
|
'Mozilla Services Encryption Passphrase': {foo: "passphrase"}
|
|
|
|
};
|
2008-06-18 11:54:24 -07:00
|
|
|
|
2008-06-19 16:03:42 -07:00
|
|
|
let __fakePrefs = {
|
|
|
|
"encryption" : "none",
|
|
|
|
"log.logger.service.crypto" : "Debug",
|
|
|
|
"log.logger.service.engine" : "Debug",
|
2008-06-20 12:24:02 -07:00
|
|
|
"log.logger.async" : "Debug"
|
2008-06-19 16:03:42 -07:00
|
|
|
};
|
|
|
|
|
2008-06-20 18:36:33 -07:00
|
|
|
let __fakeLogins = [
|
2008-06-20 15:39:07 -07:00
|
|
|
// Fake nsILoginInfo object.
|
|
|
|
{hostname: "www.boogle.com",
|
|
|
|
formSubmitURL: "http://www.boogle.com/search",
|
|
|
|
httpRealm: "",
|
|
|
|
username: "",
|
|
|
|
password: "",
|
|
|
|
usernameField: "test_person",
|
|
|
|
passwordField: "test_password"}
|
|
|
|
];
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// Test Logic
|
|
|
|
// ----------------------------------------
|
2008-06-18 17:28:28 -07:00
|
|
|
|
2008-06-20 15:39:07 -07:00
|
|
|
function run_test() {
|
2008-06-18 18:08:33 -07:00
|
|
|
ID.set('Engine:PBE:default',
|
|
|
|
new Identity('Mozilla Services Encryption Passphrase', 'foo'));
|
2008-06-18 17:28:28 -07:00
|
|
|
|
2008-06-03 18:37:36 -07:00
|
|
|
// The JS module we're testing, with all members exposed.
|
|
|
|
var passwords = loadInSandbox("resource://weave/engines/passwords.js");
|
|
|
|
|
|
|
|
// Ensure that _hashLoginInfo() works.
|
2008-06-20 18:36:33 -07:00
|
|
|
var fakeUserHash = passwords._hashLoginInfo(__fakeLogins[0]);
|
2008-06-03 18:37:36 -07:00
|
|
|
do_check_eq(typeof fakeUserHash, 'string');
|
|
|
|
do_check_eq(fakeUserHash.length, 40);
|
|
|
|
|
|
|
|
// Ensure that PasswordSyncCore._itemExists() works.
|
|
|
|
var psc = new passwords.PasswordSyncCore();
|
|
|
|
do_check_false(psc._itemExists("invalid guid"));
|
|
|
|
do_check_true(psc._itemExists(fakeUserHash));
|
2008-06-18 14:12:24 -07:00
|
|
|
|
2008-06-18 17:28:28 -07:00
|
|
|
// Make sure the engine can sync.
|
2008-06-20 15:39:07 -07:00
|
|
|
function freshEngineSync(cb) {
|
|
|
|
let engine = new passwords.PasswordEngine();
|
|
|
|
engine.sync(cb);
|
|
|
|
};
|
2008-06-19 17:04:04 -07:00
|
|
|
|
2008-06-20 15:39:07 -07:00
|
|
|
runAndEnsureSuccess("initial sync", freshEngineSync);
|
2008-06-19 17:04:04 -07:00
|
|
|
|
2008-06-20 15:39:07 -07:00
|
|
|
runAndEnsureSuccess("trivial re-sync", freshEngineSync);
|
2008-06-18 14:12:24 -07:00
|
|
|
|
2008-06-20 18:36:33 -07:00
|
|
|
fakeLoginManager.fakeLogins.push(
|
|
|
|
{hostname: "www.yoogle.com",
|
|
|
|
formSubmitURL: "http://www.yoogle.com/search",
|
|
|
|
httpRealm: "",
|
|
|
|
username: "",
|
|
|
|
password: "",
|
|
|
|
usernameField: "test_person2",
|
|
|
|
passwordField: "test_password2"}
|
|
|
|
);
|
2008-06-19 17:04:04 -07:00
|
|
|
|
2008-06-20 15:39:07 -07:00
|
|
|
runAndEnsureSuccess("add user and re-sync", freshEngineSync);
|
2008-06-20 18:04:59 -07:00
|
|
|
|
2008-06-20 18:36:33 -07:00
|
|
|
fakeLoginManager.fakeLogins.pop();
|
2008-06-20 18:04:59 -07:00
|
|
|
|
|
|
|
runAndEnsureSuccess("remove user and re-sync", freshEngineSync);
|
2008-06-20 15:39:07 -07:00
|
|
|
}
|
2008-06-20 13:58:56 -07:00
|
|
|
|
2008-06-20 15:39:07 -07:00
|
|
|
// ----------------------------------------
|
|
|
|
// Helper Functions
|
|
|
|
// ----------------------------------------
|
2008-06-20 13:58:56 -07:00
|
|
|
|
2008-06-20 15:39:07 -07:00
|
|
|
var callbackCalled = false;
|
2008-06-20 13:58:56 -07:00
|
|
|
|
2008-06-20 15:39:07 -07:00
|
|
|
function __makeCallback() {
|
|
|
|
callbackCalled = false;
|
|
|
|
return function callback() {
|
|
|
|
callbackCalled = true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function runAndEnsureSuccess(name, func) {
|
|
|
|
getTestLogger().info("Step '" + name + "' starting.");
|
|
|
|
func(__makeCallback());
|
|
|
|
while (fts.processCallback()) {}
|
|
|
|
do_check_true(callbackCalled);
|
2008-06-20 13:58:56 -07:00
|
|
|
for (name in Async.outstandingGenerators)
|
|
|
|
getTestLogger().warn("Outstanding generator exists: " + name);
|
2008-06-18 17:28:28 -07:00
|
|
|
do_check_eq(logStats.errorsLogged, 0);
|
2008-06-20 13:58:56 -07:00
|
|
|
do_check_eq(Async.outstandingGenerators.length, 0);
|
2008-06-20 15:39:07 -07:00
|
|
|
getTestLogger().info("Step '" + name + "' succeeded.");
|
2008-06-03 18:37:36 -07:00
|
|
|
}
|
2008-06-20 15:39:07 -07:00
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// Fake Infrastructure
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
var fpasses = new FakePasswordService(__fakePasswords);
|
|
|
|
var fprefs = new FakePrefService(__fakePrefs);
|
|
|
|
var fds = new FakeDAVService({});
|
|
|
|
var fts = new FakeTimerService();
|
|
|
|
var logStats = initTestLogging();
|
2008-06-20 17:47:32 -07:00
|
|
|
var ffs = new FakeFilesystemService({});
|
2008-06-20 18:25:21 -07:00
|
|
|
var fgs = new FakeGUIDService();
|
2008-06-20 18:36:33 -07:00
|
|
|
var fakeLoginManager = new FakeLoginManager(__fakeLogins);
|
2008-06-20 15:39:07 -07:00
|
|
|
|
2008-06-20 18:36:33 -07:00
|
|
|
function FakeLoginManager(fakeLogins) {
|
|
|
|
this.fakeLogins = fakeLogins;
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
|
|
|
|
Utils.getLoginManager = function fake_getLoginManager() {
|
|
|
|
// Return a fake nsILoginManager object.
|
|
|
|
return {getAllLogins: function() { return self.fakeLogins; }};
|
|
|
|
};
|
|
|
|
}
|