Bug 1463624 - ensure sync knows there is a valid user on signin. r=eoger

MozReview-Commit-ID: 8hGU8eLYZKx

--HG--
extra : rebase_source : 227aa891910a0a3d30c910cafc9a0ce7db1368d7
This commit is contained in:
Mark Hammond 2018-05-23 17:46:38 +10:00
Родитель daad797972
Коммит 5f934337c0
2 изменённых файлов: 34 добавлений и 8 удалений

Просмотреть файл

@ -224,11 +224,6 @@ this.BrowserIDManager.prototype = {
switch (topic) { switch (topic) {
case fxAccountsCommon.ONLOGIN_NOTIFICATION: { case fxAccountsCommon.ONLOGIN_NOTIFICATION: {
this._log.info("A user has logged in"); this._log.info("A user has logged in");
// If our existing Sync state is that we needed to reauth, clear that
// state now - it will get reset back if a problem persists.
if (Weave.Status.login == LOGIN_FAILED_LOGIN_REJECTED) {
Weave.Status.login = LOGIN_SUCCEEDED;
}
this.resetCredentials(); this.resetCredentials();
let accountData = await this._fxaService.getSignedInUser(); let accountData = await this._fxaService.getSignedInUser();
this._updateSignedInUser(accountData); this._updateSignedInUser(accountData);
@ -238,6 +233,7 @@ this.BrowserIDManager.prototype = {
this._log.info("The user is not verified"); this._log.info("The user is not verified");
break; break;
} }
// intentional fall-through - the user is verified.
} }
// We've been configured with an already verified user, so fall-through. // We've been configured with an already verified user, so fall-through.
case fxAccountsCommon.ONVERIFIED_NOTIFICATION: { case fxAccountsCommon.ONVERIFIED_NOTIFICATION: {
@ -246,16 +242,18 @@ this.BrowserIDManager.prototype = {
// Set the username now - that will cause Sync to know it is configured // Set the username now - that will cause Sync to know it is configured
let accountData = await this._fxaService.getSignedInUser(); let accountData = await this._fxaService.getSignedInUser();
this.username = accountData.email; this.username = accountData.email;
Weave.Status.login = LOGIN_SUCCEEDED;
// And actually sync. If we've never synced before, we force a full sync. // And actually sync. If we've never synced before, we force a full sync.
// If we have, then we are probably just reauthenticating so it's a normal sync. // If we have, then we are probably just reauthenticating so it's a normal sync.
// We can use any pref that must be set if we've synced before. // We can use any pref that must be set if we've synced before, and check
let isFirstSync = !Svc.Prefs.get("client.syncID", null); // the sync lock state because we might already be doing that first sync.
let isFirstSync = !Weave.Service.locked && !Svc.Prefs.get("client.syncID", null);
if (isFirstSync) { if (isFirstSync) {
this._log.info("Doing initial sync actions"); this._log.info("Doing initial sync actions");
Svc.Prefs.set("firstSync", "resetClient"); Svc.Prefs.set("firstSync", "resetClient");
}
Services.obs.notifyObservers(null, "weave:service:setup-complete"); Services.obs.notifyObservers(null, "weave:service:setup-complete");
}
// There's no need to wait for sync to complete and it would deadlock // There's no need to wait for sync to complete and it would deadlock
// our AsyncObserver. // our AsyncObserver.
Weave.Service.sync({why: "login"}); Weave.Service.sync({why: "login"});

Просмотреть файл

@ -265,6 +265,34 @@ add_task(async function test_ensureLoggedIn() {
Assert.equal(Status.login, LOGIN_SUCCEEDED, "final ensureLoggedIn worked"); Assert.equal(Status.login, LOGIN_SUCCEEDED, "final ensureLoggedIn worked");
}); });
add_task(async function test_syncState() {
// Avoid polling for an unverified user.
let identityConfig = makeIdentityConfig();
let fxaInternal = makeFxAccountsInternalMock(identityConfig);
fxaInternal.startVerifiedCheck = () => {};
configureFxAccountIdentity(globalBrowseridManager, globalIdentityConfig, fxaInternal);
// arrange for no logged in user.
let fxa = globalBrowseridManager._fxaService;
let signedInUser = fxa.internal.currentAccountState.storageManager.accountData;
fxa.internal.currentAccountState.storageManager.accountData = null;
await Assert.rejects(globalBrowseridManager._ensureValidToken(true), "expecting rejection due to no user");
// Restore to an unverified user.
signedInUser.verified = false;
fxa.internal.currentAccountState.storageManager.accountData = signedInUser;
Status.login = LOGIN_FAILED_LOGIN_REJECTED;
// The browserid_identity observers are async, so call them directly.
await globalBrowseridManager.observe(null, ONLOGIN_NOTIFICATION, "");
Assert.equal(Status.login, LOGIN_FAILED_LOGIN_REJECTED,
"should not have changed the login state for an unverified user");
// now pretend the user because verified.
signedInUser.verified = true;
await globalBrowseridManager.observe(null, ONVERIFIED_NOTIFICATION, "");
Assert.equal(Status.login, LOGIN_SUCCEEDED,
"should have changed the login state to success");
});
add_task(async function test_tokenExpiration() { add_task(async function test_tokenExpiration() {
_("BrowserIDManager notices token expiration:"); _("BrowserIDManager notices token expiration:");
let bimExp = new BrowserIDManager(); let bimExp = new BrowserIDManager();