use of com.firebase.ui.auth.IdpResponse 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();
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class LinkingSocialProviderResponseHandlerTest method testSignIn_genericIdpLinkingFlow_expectImmediateLink.
@Test
public void testSignIn_genericIdpLinkingFlow_expectImmediateLink() {
mHandler.getOperation().observeForever(mResponseObserver);
// Set Facebook credential
AuthCredential facebookAuthCredential = FacebookAuthProvider.getCredential(TestConstants.TOKEN);
mHandler.setRequestedSignInCredentialForEmail(facebookAuthCredential, TestConstants.EMAIL);
// Fake social response from Microsoft
IdpResponse idpResponse = new IdpResponse.Builder(new User.Builder(MICROSOFT_PROVIDER, TestConstants.EMAIL).setName(DISPLAY_NAME).build()).build();
when(mMockAuth.getCurrentUser()).thenReturn(mMockUser);
when(mMockUser.linkWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
mHandler.startSignIn(idpResponse);
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());
assertThat(resolveCaptor.getValue().getValue()).isNotNull();
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class SocialProviderResponseHandlerTest method testSignInIdp_disabled.
@Test
public void testSignInIdp_disabled() {
mHandler.getOperation().observeForever(mResultObserver);
when(mMockAuth.signInWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forFailure(new FirebaseAuthException("ERROR_USER_DISABLED", "disabled")));
IdpResponse response = new IdpResponse.Builder(new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).setToken(TestConstants.TOKEN).build();
mHandler.startSignIn(response);
verify(mResultObserver).onChanged(argThat(ResourceMatchers.isFailureWithCode(ErrorCodes.ERROR_USER_DISABLED)));
}
use of com.firebase.ui.auth.IdpResponse 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.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class SocialProviderResponseHandlerTest method testSignInIdp_success.
@Test
public void testSignInIdp_success() {
mHandler.getOperation().observeForever(mResultObserver);
when(mMockAuth.signInWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
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));
InOrder inOrder = inOrder(mResultObserver);
inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isLoading()));
inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
Aggregations