Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ internal suspend fun FirebaseAuthUI.signInWithFacebook(
updateAuthState(
AuthState.Loading("Signing in with facebook...")
)
(testLoginManagerProvider ?: credentialProvider).logOut()
Comment thread
demolaf marked this conversation as resolved.
Outdated
val profileData = provider.fetchFacebookProfile(accessToken)
val credential = credentialProvider.getCredential(accessToken.token)
Comment thread
demolaf marked this conversation as resolved.
Outdated
signInAndLinkWithCredential(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,46 @@ class FacebookAuthProviderFirebaseAuthUITest {
}
}

@Test
@Config(manifest = Config.NONE, qualifiers = "night")
fun `signInWithFacebook - calls logOut before sign in to clear stale cached token`() = runTest {
val instance = FirebaseAuthUI.create(firebaseApp, mockFirebaseAuth)
val provider = spy(AuthProvider.Facebook())
val config = authUIConfiguration {
context = applicationContext
providers {
provider(provider)
}
}

val mockAccessToken = mock<AccessToken> {
on { token } doReturn "random-token"
}
val mockCredential = mock<AuthCredential>()
val mockUser = mock<FirebaseUser>()
val mockAuthResult = mock<AuthResult>()
whenever(mockAuthResult.user).thenReturn(mockUser)
whenever(mockUser.isEmailVerified).thenReturn(true)
whenever(mockUser.providerData).thenReturn(emptyList())
val taskCompletionSource = TaskCompletionSource<AuthResult>()
taskCompletionSource.setResult(mockAuthResult)
whenever(mockFirebaseAuth.signInWithCredential(mockCredential))
.thenReturn(taskCompletionSource.task)
doReturn(null).whenever(provider).fetchFacebookProfile(any())
whenever(mockFBAuthCredentialProvider.getCredential("random-token"))
.thenReturn(mockCredential)

instance.signInWithFacebook(
context = applicationContext,
config = config,
provider = provider,
accessToken = mockAccessToken,
credentialProvider = mockFBAuthCredentialProvider
)

verify(mockFBAuthCredentialProvider).logOut()
}

@Test
@Config(manifest = Config.NONE, qualifiers = "night")
fun `signInWithFacebook - successful sign in signs user in and emits Success authState`() = runTest {
Expand Down
Loading