use of com.google.firebase.auth.GoogleAuthCredential in project FirebaseUI-Android by firebase.
the class LinkingSocialProviderResponseHandlerTest method testSignIn_anonymousUpgradeEnabledWithSameIdp_expectMergeFailure.
@Test
public void testSignIn_anonymousUpgradeEnabledWithSameIdp_expectMergeFailure() {
mHandler.getOperation().observeForever(mResponseObserver);
setupAnonymousUpgrade();
// Fake social response from Google
IdpResponse response = new IdpResponse.Builder(new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).setToken(TestConstants.TOKEN).build();
mHandler.startSignIn(response);
// Since we are signing in with the same IDP and anonymous upgrade is enabled, a merge
// failure should occur without any RPC calls
AuthCredential credential = GoogleAuthProvider.getCredential(TestConstants.TOKEN, null);
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();
GoogleAuthCredential responseCredential = (GoogleAuthCredential) e.getResponse().getCredentialForLinking();
assertThat(responseCredential.getProvider()).isEqualTo(credential.getProvider());
assertThat(responseCredential.getSignInMethod()).isEqualTo(credential.getSignInMethod());
}
use of com.google.firebase.auth.GoogleAuthCredential in project FirebaseUI-Android by firebase.
the class LinkingSocialProviderResponseHandlerTest method testSignIn_anonymousUpgradeEnabledWithDifferentIdp_expectMergeFailure.
@Test
public void testSignIn_anonymousUpgradeEnabledWithDifferentIdp_expectMergeFailure() {
mHandler.getOperation().observeForever(mResponseObserver);
setupAnonymousUpgrade();
// We're going to fake a sign in with facebook, where the email belongs
// to an existing account with a Google provider.
// We need to link Facebook to this account, and then a merge failure should occur
// so that the developer can handle it.
// Before we can link, they need to sign in with Google to prove they own the account.
// Fake social response from Google
IdpResponse response = new IdpResponse.Builder(new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).setToken(TestConstants.TOKEN).build();
// Set facebook credential
AuthCredential facebookAuthCredential = FacebookAuthProvider.getCredential(TestConstants.TOKEN);
mHandler.setRequestedSignInCredentialForEmail(facebookAuthCredential, TestConstants.EMAIL);
when(mScratchMockAuth.signInWithCredential(any(GoogleAuthCredential.class))).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
// Mock linking with Facebook to always work
when(FakeAuthResult.INSTANCE.getUser().linkWithCredential(facebookAuthCredential)).thenReturn(new AutoContinueTask<>(FakeAuthResult.INSTANCE, FakeAuthResult.INSTANCE, true, null));
mHandler.startSignIn(response);
verify(mScratchMockAuth).signInWithCredential(any(GoogleAuthCredential.class));
verify(FakeAuthResult.INSTANCE.getUser()).linkWithCredential(facebookAuthCredential);
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());
// Merge failure should occur after successful linking
FirebaseAuthAnonymousUpgradeException e = (FirebaseAuthAnonymousUpgradeException) resolveCaptor.getValue().getException();
AuthCredential credential = ProviderUtils.getAuthCredential(response);
GoogleAuthCredential responseCredential = (GoogleAuthCredential) e.getResponse().getCredentialForLinking();
assertThat(responseCredential.getProvider()).isEqualTo(credential.getProvider());
assertThat(responseCredential.getSignInMethod()).isEqualTo(credential.getSignInMethod());
}
Aggregations