mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 587027 - Use as little memory as possible (part 4)
Refactor Service._checkSetup() to Status.checkSetup(). Also move the test fixture for WeaveCryptoID to the individual tests that need it.
This commit is contained in:
parent
7af078555f
commit
a39bd93a56
@ -267,11 +267,14 @@ WeaveSvc.prototype = {
|
||||
this._log.info("Weave Sync disabled");
|
||||
|
||||
// Create Weave identities (for logging in, and for encryption)
|
||||
ID.set('WeaveID', new Identity(PWDMGR_PASSWORD_REALM, this.username));
|
||||
Auth.defaultAuthenticator = new BasicAuthenticator(ID.get('WeaveID'));
|
||||
let id = ID.get("WeaveID");
|
||||
if (!id)
|
||||
id = ID.set("WeaveID", new Identity(PWDMGR_PASSWORD_REALM, this.username));
|
||||
Auth.defaultAuthenticator = new BasicAuthenticator(id);
|
||||
|
||||
ID.set('WeaveCryptoID',
|
||||
new Identity(PWDMGR_PASSPHRASE_REALM, this.username));
|
||||
if (!ID.get("WeaveCryptoID"))
|
||||
ID.set("WeaveCryptoID",
|
||||
new Identity(PWDMGR_PASSPHRASE_REALM, this.username));
|
||||
|
||||
this._updateCachedURLs();
|
||||
|
||||
@ -293,25 +296,9 @@ WeaveSvc.prototype = {
|
||||
},
|
||||
|
||||
_checkSetup: function WeaveSvc__checkSetup() {
|
||||
if (!this.enabled) {
|
||||
Status.service = STATUS_DISABLED;
|
||||
}
|
||||
else if (!this.username) {
|
||||
this._log.debug("checkSetup: no username set");
|
||||
Status.login = LOGIN_FAILED_NO_USERNAME;
|
||||
}
|
||||
else if (!Utils.mpLocked() && !this.password) {
|
||||
this._log.debug("checkSetup: no password set");
|
||||
Status.login = LOGIN_FAILED_NO_PASSWORD;
|
||||
}
|
||||
else if (!Utils.mpLocked() && !this.passphrase) {
|
||||
this._log.debug("checkSetup: no passphrase set");
|
||||
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
|
||||
}
|
||||
else
|
||||
Status.service = STATUS_OK;
|
||||
|
||||
return Status.service;
|
||||
if (!this.enabled)
|
||||
return Status.service = STATUS_DISABLED;
|
||||
return Status.checkSetup();
|
||||
},
|
||||
|
||||
_migratePrefs: function _migratePrefs() {
|
||||
|
@ -70,6 +70,45 @@ let Status = {
|
||||
this.service = SYNC_FAILED_PARTIAL;
|
||||
},
|
||||
|
||||
checkSetup: function checkSetup() {
|
||||
// Check whether we have a username without importing The World(tm).
|
||||
let prefs = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService)
|
||||
.getBranch(PREFS_BRANCH);
|
||||
let username;
|
||||
try {
|
||||
username = prefs.getCharPref("username");
|
||||
} catch(ex) {}
|
||||
if (!username) {
|
||||
Status.login = LOGIN_FAILED_NO_USERNAME;
|
||||
return Status.service;
|
||||
}
|
||||
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://services-sync/identity.js");
|
||||
if (!Utils.mpLocked()) {
|
||||
let id = ID.get("WeaveID");
|
||||
if (!id)
|
||||
id = ID.set("WeaveID", new Identity(PWDMGR_PASSWORD_REALM, username));
|
||||
|
||||
if (!id.password) {
|
||||
Status.login = LOGIN_FAILED_NO_PASSWORD;
|
||||
return Status.service;
|
||||
}
|
||||
|
||||
id = ID.get("WeaveCryptoID");
|
||||
if (!id)
|
||||
id = ID.set("WeaveCryptoID",
|
||||
new Identity(PWDMGR_PASSPHRASE_REALM, username));
|
||||
|
||||
if (!id.password) {
|
||||
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
|
||||
return Status.service;
|
||||
}
|
||||
}
|
||||
return Status.service = STATUS_OK;
|
||||
},
|
||||
|
||||
resetBackoff: function resetBackoff() {
|
||||
this.enforceBackoff = false;
|
||||
this.backoffInterval = 0;
|
||||
|
@ -410,6 +410,4 @@ let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" "));
|
||||
|
||||
_("Setting the identity for passphrase");
|
||||
Cu.import("resource://services-sync/identity.js");
|
||||
let passphrase = ID.set("WeaveCryptoID", new Identity());
|
||||
passphrase.password = "passphrase";
|
||||
|
||||
|
@ -2,6 +2,7 @@ Cu.import("resource://services-sync/base_records/crypto.js");
|
||||
Cu.import("resource://services-sync/base_records/keys.js");
|
||||
Cu.import("resource://services-sync/engines/clients.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://services-sync/identity.js");
|
||||
|
||||
function run_test() {
|
||||
let baseUri = "http://fakebase/";
|
||||
@ -9,6 +10,9 @@ function run_test() {
|
||||
let privUri = baseUri + "privkey";
|
||||
let cryptoUri = baseUri + "crypto";
|
||||
|
||||
let passphrase = ID.set("WeaveCryptoID", new Identity());
|
||||
passphrase.password = "passphrase";
|
||||
|
||||
_("Setting up fake pub/priv keypair and symkey for encrypt/decrypt");
|
||||
PubKeys.defaultKeyUri = baseUri + "pubkey";
|
||||
let {pubkey, privkey} = PubKeys.createKeypair(passphrase, pubUri, privUri);
|
||||
|
@ -39,6 +39,9 @@ function run_test() {
|
||||
let server;
|
||||
do_test_pending();
|
||||
|
||||
let passphrase = ID.set("WeaveCryptoID", new Identity());
|
||||
passphrase.password = "passphrase";
|
||||
|
||||
try {
|
||||
let log = Log4Moz.repository.getLogger("Test");
|
||||
Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
|
||||
|
@ -1,8 +1,12 @@
|
||||
Cu.import("resource://services-sync/base_records/crypto.js");
|
||||
Cu.import("resource://services-sync/base_records/keys.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://services-sync/base_records/identity.js");
|
||||
|
||||
function run_test() {
|
||||
let passphrase = ID.set("WeaveCryptoID", new Identity());
|
||||
passphrase.password = "passphrase";
|
||||
|
||||
_("Generating keypair to encrypt/decrypt symkeys");
|
||||
let {pubkey, privkey} = PubKeys.createKeypair(
|
||||
passphrase,
|
||||
|
45
services/sync/tests/unit/test_status_checkSetup.js
Normal file
45
services/sync/tests/unit/test_status_checkSetup.js
Normal file
@ -0,0 +1,45 @@
|
||||
Cu.import("resource://services-sync/constants.js");
|
||||
Cu.import("resource://services-sync/identity.js");
|
||||
Cu.import("resource://services-sync/status.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
|
||||
function run_test() {
|
||||
try {
|
||||
_("Verify initial setup.");
|
||||
do_check_eq(ID.get("WeaveID"), null);
|
||||
do_check_eq(ID.get("WeaveCryptoID"), null);
|
||||
|
||||
_("Fresh setup, we're not configured.");
|
||||
do_check_eq(Status.checkSetup(), CLIENT_NOT_CONFIGURED);
|
||||
do_check_eq(Status.login, LOGIN_FAILED_NO_USERNAME);
|
||||
Status.resetSync();
|
||||
|
||||
_("Let's provide a username.");
|
||||
Svc.Prefs.set("username", "johndoe");
|
||||
do_check_eq(Status.checkSetup(), CLIENT_NOT_CONFIGURED);
|
||||
do_check_eq(Status.login, LOGIN_FAILED_NO_PASSWORD);
|
||||
Status.resetSync();
|
||||
|
||||
_("checkSetup() created a WeaveID identity.");
|
||||
let id = ID.get("WeaveID");
|
||||
do_check_true(!!id);
|
||||
|
||||
_("Let's provide a password.");
|
||||
id.password = "carotsalad";
|
||||
do_check_eq(Status.checkSetup(), CLIENT_NOT_CONFIGURED);
|
||||
do_check_eq(Status.login, LOGIN_FAILED_NO_PASSPHRASE);
|
||||
Status.resetSync();
|
||||
|
||||
_("checkSetup() created a WeaveCryptoID identity");
|
||||
id = ID.get("WeaveCryptoID");
|
||||
do_check_true(!!id);
|
||||
|
||||
_("Let's provide a passphrase");
|
||||
id.password = "chickeninacan";
|
||||
do_check_eq(Status.checkSetup(), STATUS_OK);
|
||||
Status.resetSync();
|
||||
|
||||
} finally {
|
||||
Svc.Prefs.resetBranch("");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user