Search in sources :

Example 21 with IdpResponse

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

the class EmailLinkSignInHandlerTest method testStartSignIn_differentDeviceLinkWithValidSessionInfo_expectInvalidLinkError.

@Test
@SuppressWarnings("all")
public void testStartSignIn_differentDeviceLinkWithValidSessionInfo_expectInvalidLinkError() {
    String differentSessionId = SessionUtils.generateRandomAlphaNumericString(10);
    initializeHandlerWithSessionInfo(differentSessionId, null, null, false);
    mHandler.getOperation().observeForever(mResponseObserver);
    when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true);
    when(mMockAuth.checkActionCode(any(String.class))).thenReturn(AutoCompleteTask.<ActionCodeResult>forFailure(new Exception("foo")));
    mHandler.startSignIn();
    verify(mMockAuth).isSignInWithEmailLink(any(String.class));
    verify(mMockAuth).checkActionCode(any(String.class));
    ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class);
    InOrder inOrder = inOrder(mResponseObserver);
    inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading()));
    inOrder.verify(mResponseObserver).onChanged(captor.capture());
    FirebaseUiException exception = (FirebaseUiException) captor.getValue().getException();
    assertThat(exception).isNotNull();
    assertThat(exception.getErrorCode()).isEqualTo(ErrorCodes.INVALID_EMAIL_LINK_ERROR);
}
Also used : InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) FirebaseAuthAnonymousUpgradeException(com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 22 with IdpResponse

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

the class GenericIdpSignInHandlerTest method testStartSignIn_normalSignInFlow_expectSuccess.

@Test
public void testStartSignIn_normalSignInFlow_expectSuccess() {
    mHandler.getOperation().observeForever(mResponseObserver);
    when(mMockAuth.startActivityForSignInWithProvider(any(Activity.class), any(OAuthProvider.class))).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
    mockOAuthProvider(MICROSOFT_PROVIDER);
    mHandler.startSignIn(mMockAuth, mMockActivity, MICROSOFT_PROVIDER);
    ArgumentCaptor<OAuthProvider> providerCaptor = ArgumentCaptor.forClass(OAuthProvider.class);
    verify(mMockAuth).startActivityForSignInWithProvider(eq(mMockActivity), providerCaptor.capture());
    assertThat(providerCaptor.getValue().getProviderId()).isEqualTo(MICROSOFT_PROVIDER);
    HashMap<String, String> customArgs = (HashMap<String, String>) mHandler.getArguments().getParams().getSerializable(ExtraConstants.GENERIC_OAUTH_CUSTOM_PARAMETERS);
    assertThat(customArgs).isNotNull();
    assertThat(customArgs).hasSize(1);
    InOrder inOrder = inOrder(mResponseObserver);
    inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    ArgumentCaptor<Resource<IdpResponse>> resourceCaptor = ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResponseObserver).onChanged(resourceCaptor.capture());
    IdpResponse returnedIdpResponse = resourceCaptor.getValue().getValue();
    assertThat(returnedIdpResponse.isSuccessful()).isTrue();
    assertThat(returnedIdpResponse.getUser()).isNotNull();
}
Also used : InOrder(org.mockito.InOrder) HashMap(java.util.HashMap) Resource(com.firebase.ui.auth.data.model.Resource) Activity(android.app.Activity) OAuthProvider(com.google.firebase.auth.OAuthProvider) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 23 with IdpResponse

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

the class PhoneProviderResponseHandlerTest method testSignIn_autoUpgradeAnonymousEnabledWithNewUser_expectSuccess.

@Test
public void testSignIn_autoUpgradeAnonymousEnabledWithNewUser_expectSuccess() {
    mHandler.getOperation().observeForever(mResponseObserver);
    setupAnonymousUpgrade();
    when(mMockAuth.getCurrentUser().linkWithCredential(mCredential)).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
    IdpResponse response = new IdpResponse.Builder(new User.Builder(PhoneAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).build();
    mHandler.startSignIn(mCredential, response);
    verify(mMockAuth.getCurrentUser()).linkWithCredential(mCredential);
    verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
Also used : User(com.firebase.ui.auth.data.model.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 24 with IdpResponse

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

the class PhoneProviderResponseHandlerTest method testSignIn_withValidCredentialAndNewUser_expectSuccess.

@Test
public void testSignIn_withValidCredentialAndNewUser_expectSuccess() {
    mHandler.getOperation().observeForever(mResponseObserver);
    when(mMockAuth.signInWithCredential(mCredential)).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
    IdpResponse response = new IdpResponse.Builder(new User.Builder(PhoneAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).build();
    mHandler.startSignIn(mCredential, response);
    verify(mMockAuth).signInWithCredential(mCredential);
    verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
Also used : User(com.firebase.ui.auth.data.model.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 25 with IdpResponse

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

the class AnonymousSignInHandlerTest method testStartSignIn_expectSuccess.

@Test
public void testStartSignIn_expectSuccess() {
    mHandler.getOperation().observeForever(mResponseObserver);
    when(mMockAuth.signInAnonymously()).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
    mHandler.startSignIn(mMockActivity);
    verify(mMockAuth).signInAnonymously();
    InOrder inOrder = inOrder(mResponseObserver);
    inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResponseObserver).onChanged(captor.capture());
    assertThat(captor.getValue().getState()).isEqualTo(State.SUCCESS);
    IdpResponse response = captor.getValue().getValue();
    assertThat(response.isNewUser()).isFalse();
}
Also used : InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) 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