Search in sources :

Example 71 with IdpResponse

use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.

the class GenericIdpAnonymousUpgradeLinkingHandlerTest method testStartSignIn_anonymousUpgradeLinkingFlow_expectIdpResponseWithCredential.

@Test
public void testStartSignIn_anonymousUpgradeLinkingFlow_expectIdpResponseWithCredential() {
    setupAnonymousUpgrade();
    AuthOperationManager authOperationManager = AuthOperationManager.getInstance();
    authOperationManager.mScratchAuth = mScratchMockAuth;
    when(mScratchMockAuth.startActivityForSignInWithProvider(any(HelperActivityBase.class), any(OAuthProvider.class))).thenReturn(AutoCompleteTask.forSuccess(mMockAuthResult));
    AuthCredential credential = OAuthProvider.newCredentialBuilder(MICROSOFT_PROVIDER).setIdToken(ID_TOKEN).setAccessToken(ACCESS_TOKEN).build();
    when(mMockAuthResult.getCredential()).thenReturn(credential);
    when(mMockAuthResult.getUser()).thenReturn(mMockUser);
    when(mMockUser.getDisplayName()).thenReturn(DISPLAY_NAME);
    when(mMockUser.getPhotoUrl()).thenReturn(new Uri.Builder().build());
    mockOAuthProvider(MICROSOFT_PROVIDER);
    mHandler.startSignIn(mMockAuth, mMockActivity, MICROSOFT_PROVIDER);
    ArgumentCaptor<OAuthProvider> providerCaptor = ArgumentCaptor.forClass(OAuthProvider.class);
    verify(mScratchMockAuth).startActivityForSignInWithProvider(eq(mMockActivity), providerCaptor.capture());
    assertThat(providerCaptor.getValue().getProviderId()).isEqualTo(MICROSOFT_PROVIDER);
    InOrder inOrder = inOrder(mResponseObserver);
    inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResponseObserver).onChanged(resolveCaptor.capture());
    IdpResponse idpResponse = resolveCaptor.getValue().getValue();
    assertThat(idpResponse.getCredentialForLinking()).isNotNull();
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) AuthOperationManager(com.firebase.ui.auth.util.data.AuthOperationManager) InOrder(org.mockito.InOrder) HelperActivityBase(com.firebase.ui.auth.ui.HelperActivityBase) Resource(com.firebase.ui.auth.data.model.Resource) OAuthProvider(com.google.firebase.auth.OAuthProvider) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 72 with IdpResponse

use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.

the class LinkingSocialProviderResponseHandlerTest method testSignIn_genericIdpLinkingFlow_expectImmediateLink.

@Test
public void testSignIn_genericIdpLinkingFlow_expectImmediateLink() {
    mHandler.getOperation().observeForever(mResponseObserver);
    // Set Facebook credential
    AuthCredential facebookAuthCredential = FacebookAuthProvider.getCredential(TestConstants.TOKEN);
    mHandler.setRequestedSignInCredentialForEmail(facebookAuthCredential, TestConstants.EMAIL);
    // Fake social response from Microsoft
    IdpResponse idpResponse = new IdpResponse.Builder(new User.Builder(MICROSOFT_PROVIDER, TestConstants.EMAIL).setName(DISPLAY_NAME).build()).build();
    when(mMockAuth.getCurrentUser()).thenReturn(mMockUser);
    when(mMockUser.linkWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
    mHandler.startSignIn(idpResponse);
    InOrder inOrder = inOrder(mResponseObserver);
    inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResponseObserver).onChanged(resolveCaptor.capture());
    assertThat(resolveCaptor.getValue().getValue()).isNotNull();
}
Also used : GoogleAuthCredential(com.google.firebase.auth.GoogleAuthCredential) AuthCredential(com.google.firebase.auth.AuthCredential) InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 73 with IdpResponse

use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.

the class SocialProviderResponseHandlerTest method testSignInIdp_disabled.

@Test
public void testSignInIdp_disabled() {
    mHandler.getOperation().observeForever(mResultObserver);
    when(mMockAuth.signInWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forFailure(new FirebaseAuthException("ERROR_USER_DISABLED", "disabled")));
    IdpResponse response = new IdpResponse.Builder(new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).setToken(TestConstants.TOKEN).build();
    mHandler.startSignIn(response);
    verify(mResultObserver).onChanged(argThat(ResourceMatchers.isFailureWithCode(ErrorCodes.ERROR_USER_DISABLED)));
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) FirebaseAuthException(com.google.firebase.auth.FirebaseAuthException) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 74 with IdpResponse

use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.

the class SocialProviderResponseHandlerTest method testSignInIdp_resolution.

@Test
public void testSignInIdp_resolution() {
    mHandler.getOperation().observeForever(mResultObserver);
    when(mMockAuth.signInWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forFailure(new FirebaseAuthUserCollisionException("foo", "bar")));
    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).signInWithCredential(any(AuthCredential.class));
    verify(mMockAuth).fetchSignInMethodsForEmail(any(String.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());
    // Call activity result
    IntentRequiredException e = ((IntentRequiredException) resolveCaptor.getValue().getException());
    mHandler.onActivityResult(e.getRequestCode(), Activity.RESULT_OK, response.toIntent());
    // Make sure we get success
    inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
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) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 75 with IdpResponse

use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.

the class SocialProviderResponseHandlerTest method testSignInIdp_success.

@Test
public void testSignInIdp_success() {
    mHandler.getOperation().observeForever(mResultObserver);
    when(mMockAuth.signInWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
    IdpResponse response = new IdpResponse.Builder(new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).setToken(TestConstants.TOKEN).build();
    mHandler.startSignIn(response);
    verify(mMockAuth).signInWithCredential(any(AuthCredential.class));
    InOrder inOrder = inOrder(mResultObserver);
    inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) InOrder(org.mockito.InOrder) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Aggregations

IdpResponse (com.firebase.ui.auth.IdpResponse)81 Test (org.junit.Test)45 Resource (com.firebase.ui.auth.data.model.Resource)35 AuthCredential (com.google.firebase.auth.AuthCredential)31 InOrder (org.mockito.InOrder)31 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)22 FirebaseAuthAnonymousUpgradeException (com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException)19 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)19 User (com.firebase.ui.auth.data.model.User)18 FirebaseUser (com.google.firebase.auth.FirebaseUser)15 AuthOperationManager (com.firebase.ui.auth.util.data.AuthOperationManager)12 EmailAuthCredential (com.google.firebase.auth.EmailAuthCredential)11 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)10 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)10 AuthResult (com.google.firebase.auth.AuthResult)10 Intent (android.content.Intent)9 Nullable (androidx.annotation.Nullable)9 IntentRequiredException (com.firebase.ui.auth.data.model.IntentRequiredException)9 Task (com.google.android.gms.tasks.Task)9 Application (android.app.Application)8