use of com.google.firebase.auth.FirebaseAuthUserCollisionException 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.google.firebase.auth.FirebaseAuthUserCollisionException 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.google.firebase.auth.FirebaseAuthUserCollisionException 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()));
}
use of com.google.firebase.auth.FirebaseAuthUserCollisionException 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);
}
use of com.google.firebase.auth.FirebaseAuthUserCollisionException 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);
}
Aggregations