use of com.firebase.ui.auth.data.model.Resource 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.data.model.Resource 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.data.model.Resource 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.firebase.ui.auth.data.model.Resource 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);
}
use of com.firebase.ui.auth.data.model.Resource in project FirebaseUI-Android by firebase.
the class EmailLinkSendEmailHandlerTest method testSendSignInLinkToEmail_linkingFlow_expectSuccess.
@Test
public void testSendSignInLinkToEmail_linkingFlow_expectSuccess() {
mHandler.getOperation().observeForever(mResponseObserver);
boolean forceSameDevice = true;
ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder().setUrl(URL).build();
when(mMockAuth.sendSignInLinkToEmail(any(String.class), any(ActionCodeSettings.class))).thenReturn(AutoCompleteTask.forFailure(new Exception()));
IdpResponse idpResponseForLinking = buildFacebookIdpResponseForLinking();
mHandler.sendSignInLinkToEmail(TestConstants.EMAIL, actionCodeSettings, idpResponseForLinking, forceSameDevice);
ArgumentCaptor<ActionCodeSettings> acsCaptor = ArgumentCaptor.forClass(ActionCodeSettings.class);
verify(mMockAuth).sendSignInLinkToEmail(eq(TestConstants.EMAIL), acsCaptor.capture());
validateSessionIdAddedToContinueUrl(acsCaptor.getValue(), idpResponseForLinking.getProviderType(), forceSameDevice);
ArgumentCaptor<Resource<String>> captor = ArgumentCaptor.forClass(Resource.class);
InOrder inOrder = inOrder(mResponseObserver);
inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
inOrder.verify(mResponseObserver).onChanged(captor.capture());
assertThat(captor.getValue().getState()).isEqualTo(State.FAILURE);
assertThat(captor.getValue().getException()).isNotNull();
}
Aggregations