Search in sources :

Example 6 with IntentRequiredException

use of com.firebase.ui.auth.data.model.IntentRequiredException in project FirebaseUI-Android by firebase.

the class SocialProviderResponseHandlerTest method testSignInIdp_anonymousUserUpgradeEnabledAndExistingIdpUserWithDifferentIdp_expectMergeFailure.

@Test
public void testSignInIdp_anonymousUserUpgradeEnabledAndExistingIdpUserWithDifferentIdp_expectMergeFailure() {
    mHandler.getOperation().observeForever(mResultObserver);
    setupAnonymousUpgrade();
    when(mMockAuth.getCurrentUser().linkWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forFailure(new FirebaseAuthUserCollisionException("foo", "bar")));
    // Case 2 & 3: trying to link with an account that has 1 idp, which is different from the
    // one that we're trying to log in with
    when(mMockAuth.fetchSignInMethodsForEmail(any(String.class))).thenReturn(AutoCompleteTask.forSuccess(new FakeSignInMethodQueryResult(Collections.singletonList(FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD))));
    IdpResponse response = new IdpResponse.Builder(new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).setToken(TestConstants.TOKEN).build();
    mHandler.startSignIn(response);
    verify(mMockAuth.getCurrentUser()).linkWithCredential(any(AuthCredential.class));
    InOrder inOrder = inOrder(mResultObserver);
    inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResultObserver).onChanged(resolveCaptor.capture());
    // Make sure that we are trying to start the WelcomeBackIdpPrompt activity
    IntentRequiredException e = ((IntentRequiredException) resolveCaptor.getValue().getException());
    assertThat(e.getIntent().getComponent().getClassName()).isEqualTo(WelcomeBackIdpPrompt.class.toString().split(" ")[1]);
    assertThat(IdpResponse.fromResultIntent(e.getIntent())).isEqualTo(response);
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) FakeSignInMethodQueryResult(com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult) IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) WelcomeBackIdpPrompt(com.firebase.ui.auth.ui.idp.WelcomeBackIdpPrompt) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 7 with IntentRequiredException

use of com.firebase.ui.auth.data.model.IntentRequiredException in project FirebaseUI-Android by firebase.

the class SocialProviderResponseHandlerTest method testSignInIdp_anonymousUserUpgradeEnabledAndExistingPasswordUserWithDifferentIdp_expectMergeFailure.

@Test
public void testSignInIdp_anonymousUserUpgradeEnabledAndExistingPasswordUserWithDifferentIdp_expectMergeFailure() {
    mHandler.getOperation().observeForever(mResultObserver);
    setupAnonymousUpgrade();
    when(mMockAuth.getCurrentUser().linkWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forFailure(new FirebaseAuthUserCollisionException("foo", "bar")));
    // Case 2 & 3: trying to link with an account that has 1 password provider and logging in
    // with an idp that has the same email
    when(mMockAuth.fetchSignInMethodsForEmail(any(String.class))).thenReturn(AutoCompleteTask.forSuccess(new FakeSignInMethodQueryResult(Collections.singletonList(EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD))));
    IdpResponse response = new IdpResponse.Builder(new User.Builder(FacebookAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).setToken(TestConstants.TOKEN).setSecret(TestConstants.SECRET).build();
    mHandler.startSignIn(response);
    verify(mMockAuth.getCurrentUser()).linkWithCredential(any(AuthCredential.class));
    InOrder inOrder = inOrder(mResultObserver);
    inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResultObserver).onChanged(resolveCaptor.capture());
    // Make sure that we are trying to start the WelcomeBackIdpPrompt activity
    IntentRequiredException e = ((IntentRequiredException) resolveCaptor.getValue().getException());
    assertThat(e.getIntent().getComponent().getClassName()).isEqualTo(WelcomeBackPasswordPrompt.class.toString().split(" ")[1]);
    assertThat(IdpResponse.fromResultIntent(e.getIntent())).isEqualTo(response);
}
Also used : FakeSignInMethodQueryResult(com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult) User(com.firebase.ui.auth.data.model.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) AuthCredential(com.google.firebase.auth.AuthCredential) IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) IdpResponse(com.firebase.ui.auth.IdpResponse) WelcomeBackPasswordPrompt(com.firebase.ui.auth.ui.email.WelcomeBackPasswordPrompt) Test(org.junit.Test)

Aggregations

IntentRequiredException (com.firebase.ui.auth.data.model.IntentRequiredException)7 IdpResponse (com.firebase.ui.auth.IdpResponse)4 PendingIntentRequiredException (com.firebase.ui.auth.data.model.PendingIntentRequiredException)4 Resource (com.firebase.ui.auth.data.model.Resource)4 User (com.firebase.ui.auth.data.model.User)3 FakeSignInMethodQueryResult (com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult)3 AuthCredential (com.google.firebase.auth.AuthCredential)3 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)3 Test (org.junit.Test)3 InOrder (org.mockito.InOrder)3 Bundle (android.os.Bundle)2 Activity (android.app.Activity)1 Application (android.app.Application)1 Intent (android.content.Intent)1 TextUtils (android.text.TextUtils)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AuthUI (com.firebase.ui.auth.AuthUI)1 EMAIL_LINK_PROVIDER (com.firebase.ui.auth.AuthUI.EMAIL_LINK_PROVIDER)1 ErrorCodes (com.firebase.ui.auth.ErrorCodes)1