Commit e0405287 authored by MozLando's avatar MozLando
Browse files

Merge #5920



5920: Closes #5606: Re-use sessionToken during FxA migration r=pocmo a=grigoryk
Co-authored-by: default avatarGrisha Kruglov <gkruglov@mozilla.com>
parents 71ce81c1 4a02b577
......@@ -264,14 +264,14 @@ open class FxaAccountManager(
* user input. Once sign-in completes, any registered [AccountObserver.onAuthenticated] listeners
* will be notified and [authenticatedAccount] will refer to the new account.
* This may fail in case of network errors, or if provided credentials are not valid.
* @param reuseAccount Whether or not to reuse existing session token (which is part of the [ShareableAccount].
* @param reuseSessionToken Whether or not to reuse existing session token (which is part of the [ShareableAccount].
* @return A deferred boolean flag indicating success (if true) of the sign-in operation.
*/
fun signInWithShareableAccountAsync(
fromAccount: ShareableAccount,
reuseAccount: Boolean = false
reuseSessionToken: Boolean = false
): Deferred<SignInWithShareableAccountResult> {
val stateMachineTransition = processQueueAsync(Event.SignInShareableAccount(fromAccount, reuseAccount))
val stateMachineTransition = processQueueAsync(Event.SignInShareableAccount(fromAccount, reuseSessionToken))
val result = CompletableDeferred<SignInWithShareableAccountResult>()
CoroutineScope(coroutineContext).launch {
stateMachineTransition.await()
......
......@@ -483,7 +483,7 @@ class FxaAccountManagerTest {
account.migrationResult = SignInWithShareableAccountResult.Failure
assertEquals(
SignInWithShareableAccountResult.Failure,
manager.signInWithShareableAccountAsync(migratableAccount, reuseAccount = true).await()
manager.signInWithShareableAccountAsync(migratableAccount, reuseSessionToken = true).await()
)
assertEquals("session", account.latestMigrateAuthInfo?.sessionToken)
......@@ -503,7 +503,7 @@ class FxaAccountManagerTest {
assertEquals(
SignInWithShareableAccountResult.Success,
manager.signInWithShareableAccountAsync(migratableAccount, reuseAccount = true).await()
manager.signInWithShareableAccountAsync(migratableAccount, reuseSessionToken = true).await()
)
assertEquals("session2", account.latestMigrateAuthInfo?.sessionToken)
......@@ -552,7 +552,7 @@ class FxaAccountManagerTest {
account.migrationResult = SignInWithShareableAccountResult.WillRetry
assertEquals(
SignInWithShareableAccountResult.WillRetry,
manager.signInWithShareableAccountAsync(migratableAccount, reuseAccount = true).await()
manager.signInWithShareableAccountAsync(migratableAccount, reuseSessionToken = true).await()
)
assertEquals("session", account.latestMigrateAuthInfo?.sessionToken)
......
......@@ -158,7 +158,12 @@ private object AuthenticatedAccountProcessor {
authInfo = fennecAuthInfo
)
return when (accountManager.signInWithShareableAccountAsync(shareableAccount, reuseAccount = false).await()) {
val signInResult = accountManager.signInWithShareableAccountAsync(
shareableAccount,
reuseSessionToken = true
).await()
return when (signInResult) {
SignInWithShareableAccountResult.Failure -> {
Result.Failure(
FxaMigrationException(Failure.FailedToSignIntoAuthenticatedAccount(
......
......@@ -82,7 +82,7 @@ class FennecFxaMigrationTest {
val fxaPath = File(getTestPath("fxa"), "married-v4.json")
val accountManager: FxaAccountManager = mock()
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(false))).thenReturn(
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(true))).thenReturn(
CompletableDeferred(SignInWithShareableAccountResult.Success)
)
......@@ -92,7 +92,7 @@ class FennecFxaMigrationTest {
assertEquals("Married", (this.value as FxaMigrationResult.Success.SignedInIntoAuthenticatedAccount).stateLabel)
val captor = argumentCaptor<ShareableAccount>()
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(false))
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(true))
assertEquals("test@example.com", captor.value.email)
assertEquals("252fsvj8932vj32movj97325hjfksdhfjstrg23yurt267r23", captor.value.authInfo.kSync)
......@@ -106,7 +106,7 @@ class FennecFxaMigrationTest {
val fxaPath = File(getTestPath("fxa"), "cohabiting-v4.json")
val accountManager: FxaAccountManager = mock()
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(false))).thenReturn(
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(true))).thenReturn(
CompletableDeferred(SignInWithShareableAccountResult.Success)
)
......@@ -116,7 +116,7 @@ class FennecFxaMigrationTest {
assertEquals("Cohabiting", (this.value as FxaMigrationResult.Success.SignedInIntoAuthenticatedAccount).stateLabel)
val captor = argumentCaptor<ShareableAccount>()
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(false))
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(true))
assertEquals("test@example.com", captor.value.email)
assertEquals("252bc4ccc3a239fsdfsdf32fg32wf3w4e3472d41d1a204890", captor.value.authInfo.kSync)
......@@ -130,7 +130,7 @@ class FennecFxaMigrationTest {
val fxaPath = File(getTestPath("fxa"), "cohabiting-v4.json")
val accountManager: FxaAccountManager = mock()
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(false))).thenReturn(
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(true))).thenReturn(
CompletableDeferred(SignInWithShareableAccountResult.WillRetry)
)
......@@ -140,7 +140,7 @@ class FennecFxaMigrationTest {
assertEquals("Cohabiting", (this.value as FxaMigrationResult.Success.WillAutoRetrySignInLater).stateLabel)
val captor = argumentCaptor<ShareableAccount>()
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(false))
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(true))
assertEquals("test@example.com", captor.value.email)
assertEquals("252bc4ccc3a239fsdfsdf32fg32wf3w4e3472d41d1a204890", captor.value.authInfo.kSync)
......@@ -154,7 +154,7 @@ class FennecFxaMigrationTest {
val fxaPath = File(getTestPath("fxa"), "married-v4.json")
val accountManager: FxaAccountManager = mock()
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(false))).thenReturn(
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(true))).thenReturn(
CompletableDeferred(SignInWithShareableAccountResult.Failure)
)
......@@ -166,7 +166,7 @@ class FennecFxaMigrationTest {
assertEquals("Married", (unwrapped.failure as FxaMigrationResult.Failure.FailedToSignIntoAuthenticatedAccount).stateLabel)
val captor = argumentCaptor<ShareableAccount>()
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(false))
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(true))
assertEquals("test@example.com", captor.value.email)
assertEquals("252fsvj8932vj32movj97325hjfksdhfjstrg23yurt267r23", captor.value.authInfo.kSync)
......@@ -222,7 +222,7 @@ class FennecFxaMigrationTest {
val fxaPath = File(getTestPath("fxa"), "cohabiting-v4.json")
val accountManager: FxaAccountManager = mock()
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(false))).thenReturn(
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(true))).thenReturn(
CompletableDeferred(SignInWithShareableAccountResult.Failure)
)
......@@ -234,7 +234,7 @@ class FennecFxaMigrationTest {
assertEquals("Cohabiting", unwrappedFailure.stateLabel)
val captor = argumentCaptor<ShareableAccount>()
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(false))
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(true))
assertEquals("test@example.com", captor.value.email)
assertEquals("252bc4ccc3a239fsdfsdf32fg32wf3w4e3472d41d1a204890", captor.value.authInfo.kSync)
......
......@@ -575,7 +575,7 @@ class FennecMigratorTest {
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
.build()
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(false))).thenReturn(
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(true))).thenReturn(
CompletableDeferred(SignInWithShareableAccountResult.Success)
)
......@@ -586,7 +586,7 @@ class FennecMigratorTest {
}
val captor = argumentCaptor<ShareableAccount>()
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(false))
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(true))
assertEquals("test@example.com", captor.value.email)
// This is going to be package name (org.mozilla.firefox) in actual builds.
......@@ -614,7 +614,7 @@ class FennecMigratorTest {
.setBrowserDbPath(File(getTestPath("combined"), "basic/browser.db").absolutePath)
.build()
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(false))).thenReturn(
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(true))).thenReturn(
CompletableDeferred(SignInWithShareableAccountResult.WillRetry)
)
......@@ -625,7 +625,7 @@ class FennecMigratorTest {
}
val captor = argumentCaptor<ShareableAccount>()
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(false))
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(true))
assertEquals("test@example.com", captor.value.email)
// This is going to be package name (org.mozilla.firefox) in actual builds.
......@@ -654,7 +654,7 @@ class FennecMigratorTest {
.build()
// For now, we don't treat sign-in failure any different from success. E.g. it's a one-shot attempt.
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(false))).thenReturn(
`when`(accountManager.signInWithShareableAccountAsync(any(), eq(true))).thenReturn(
CompletableDeferred(SignInWithShareableAccountResult.Failure)
)
......@@ -665,7 +665,7 @@ class FennecMigratorTest {
}
val captor = argumentCaptor<ShareableAccount>()
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(false))
verify(accountManager).signInWithShareableAccountAsync(captor.capture(), eq(true))
assertEquals("test@example.com", captor.value.email)
// This is going to be package name (org.mozilla.firefox) in actual builds.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment