Search in sources :

Example 26 with Resource

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

the class EmailLinkSignInHandlerTest method testStartSignIn_differentDeviceLinkWithValidSessionInfo_expectPromptForEmailError.

@Test
@SuppressWarnings("all")
public void testStartSignIn_differentDeviceLinkWithValidSessionInfo_expectPromptForEmailError() {
    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.forSuccess(mMockActionCodeResult));
    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.EMAIL_LINK_PROMPT_FOR_EMAIL_ERROR);
}
Also used : InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 27 with Resource

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

the class GenericIdpSignInHandlerTest method testStartSignIn_anonymousUpgradeFlowWithConflict_expectRecoverableLinkingError.

@Test
public void testStartSignIn_anonymousUpgradeFlowWithConflict_expectRecoverableLinkingError() {
    setupAnonymousUpgrade();
    AuthCredential credential = OAuthProvider.newCredentialBuilder(MICROSOFT_PROVIDER).setIdToken(ID_TOKEN).setAccessToken(ACCESS_TOKEN).build();
    FirebaseAuthUserCollisionException collisionException = new FirebaseAuthUserCollisionException("foo", "bar");
    collisionException.zzb(EMAIL).zza(credential);
    when(mMockAuth.getCurrentUser().startActivityForLinkWithProvider(any(Activity.class), any(OAuthProvider.class))).thenReturn(AutoCompleteTask.forFailure(collisionException));
    // Case 2:  Anonymous user trying to link with a provider keyed by an email that already
    // belongs to an existing account
    when(mMockAuth.fetchSignInMethodsForEmail(any(String.class))).thenReturn(AutoCompleteTask.forSuccess(new FakeSignInMethodQueryResult(Arrays.asList(GoogleAuthProvider.PROVIDER_ID))));
    mockOAuthProvider(MICROSOFT_PROVIDER);
    mHandler.startSignIn(mMockAuth, mMockActivity, MICROSOFT_PROVIDER);
    ArgumentCaptor<OAuthProvider> providerCaptor = ArgumentCaptor.forClass(OAuthProvider.class);
    verify(mMockAuth.getCurrentUser()).startActivityForLinkWithProvider(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());
    FirebaseUiUserCollisionException e = (FirebaseUiUserCollisionException) resolveCaptor.getValue().getException();
    assertThat(e.getCredential()).isNotNull();
    assertThat(e.getEmail()).isEqualTo(EMAIL);
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) FakeSignInMethodQueryResult(com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult) InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) Activity(android.app.Activity) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) OAuthProvider(com.google.firebase.auth.OAuthProvider) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FirebaseUiUserCollisionException(com.firebase.ui.auth.FirebaseUiUserCollisionException) Test(org.junit.Test)

Example 28 with Resource

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

the class GenericIdpSignInHandlerTest method testStartSignIn_anonymousUpgradeFlow_expectSuccess.

@Test
public void testStartSignIn_anonymousUpgradeFlow_expectSuccess() {
    setupAnonymousUpgrade();
    when(mMockAuth.getCurrentUser().startActivityForLinkWithProvider(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.getCurrentUser()).startActivityForLinkWithProvider(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>> 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) Resource(com.firebase.ui.auth.data.model.Resource) Activity(android.app.Activity) OAuthProvider(com.google.firebase.auth.OAuthProvider) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 29 with Resource

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

the class PhoneProviderResponseHandlerTest method testSignIn_autoUpgradeAnonymousEnabledWithExistingUser_expectMergeFailure.

@Test
public void testSignIn_autoUpgradeAnonymousEnabledWithExistingUser_expectMergeFailure() {
    mHandler.getOperation().observeForever(mResponseObserver);
    setupAnonymousUpgrade();
    FirebaseAuthUserCollisionException ex = new FirebaseAuthUserCollisionException("foo", "bar");
    TestHelper.setPrivateField(ex, FirebaseAuthUserCollisionException.class, AuthCredential.class, mCredential);
    when(mMockAuth.getCurrentUser().linkWithCredential(mCredential)).thenReturn(AutoCompleteTask.forFailure(ex));
    IdpResponse response = new IdpResponse.Builder(new User.Builder(PhoneAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).build();
    mHandler.startSignIn(mCredential, response);
    verify(mMockAuth.getCurrentUser()).linkWithCredential(mCredential);
    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());
    FirebaseAuthAnonymousUpgradeException e = (FirebaseAuthAnonymousUpgradeException) resolveCaptor.getValue().getException();
    assertThat(e.getResponse().getCredentialForLinking()).isNotNull();
}
Also used : 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) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) FirebaseAuthAnonymousUpgradeException(com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 30 with Resource

use of com.firebase.ui.auth.data.model.Resource 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)

Aggregations

Resource (com.firebase.ui.auth.data.model.Resource)36 InOrder (org.mockito.InOrder)35 Test (org.junit.Test)34 IdpResponse (com.firebase.ui.auth.IdpResponse)28 AuthCredential (com.google.firebase.auth.AuthCredential)20 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)13 FirebaseAuthAnonymousUpgradeException (com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException)11 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)9 EmailAuthCredential (com.google.firebase.auth.EmailAuthCredential)9 FacebookAuthCredential (com.google.firebase.auth.FacebookAuthCredential)8 OAuthProvider (com.google.firebase.auth.OAuthProvider)7 Activity (android.app.Activity)6 FakeSignInMethodQueryResult (com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult)6 AuthOperationManager (com.firebase.ui.auth.util.data.AuthOperationManager)5 IntentRequiredException (com.firebase.ui.auth.data.model.IntentRequiredException)3 ActionCodeSettings (com.google.firebase.auth.ActionCodeSettings)3 GoogleAuthCredential (com.google.firebase.auth.GoogleAuthCredential)3 FirebaseUiUserCollisionException (com.firebase.ui.auth.FirebaseUiUserCollisionException)2 User (com.firebase.ui.auth.data.model.User)2 FirebaseUser (com.google.firebase.auth.FirebaseUser)2