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);
}
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);
}
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();
}
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();
}
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();
}
Aggregations