use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class EmailLinkSignInHandlerTest method testStartSignIn_linkingFlow_expectSuccessfulLink.
@Test
@SuppressWarnings("all")
public void testStartSignIn_linkingFlow_expectSuccessfulLink() {
mHandler.getOperation().observeForever(mResponseObserver);
when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true);
mPersistenceManager.saveEmail(ApplicationProvider.getApplicationContext(), TestConstants.EMAIL, TestConstants.SESSION_ID, TestConstants.UID);
mPersistenceManager.saveIdpResponseForLinking(ApplicationProvider.getApplicationContext(), buildFacebookIdpResponse());
when(mMockAuth.signInWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forSuccess(mMockAuthResult));
// Mock linking with Facebook to always work
when(mMockAuthResult.getUser().linkWithCredential(any(FacebookAuthCredential.class))).thenReturn(new AutoContinueTask<>(mMockAuthResult, mMockAuthResult, true, null));
mHandler.startSignIn();
// Validate regular sign in
ArgumentCaptor<EmailAuthCredential> credentialCaptor = ArgumentCaptor.forClass(EmailAuthCredential.class);
verify(mMockAuth).signInWithCredential(credentialCaptor.capture());
// TODO: EmailAuthCredential no longer exposes .getEmail() or .getPassword()
// assertThat(credentialCaptor.getValue().getEmail()).isEqualTo(TestConstants.EMAIL);
assertThat(credentialCaptor.getValue().getSignInMethod()).isEqualTo(EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD);
// Validate linking was called
verify(mMockAuthResult.getUser()).linkWithCredential(any(FacebookAuthCredential.class));
// Validate that the data was cleared
assertThat(mPersistenceManager.retrieveSessionRecord(ApplicationProvider.getApplicationContext())).isNull();
// Validate IdpResponse
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());
IdpResponse response = captor.getValue().getValue();
assertThat(captor.getValue().getState()).isEqualTo(State.SUCCESS);
assertThat(response.getUser().getProviderId()).isEqualTo(AuthUI.EMAIL_LINK_PROVIDER);
assertThat(response.getUser().getEmail()).isEqualTo(mMockAuthResult.getUser().getEmail());
assertThat(response.getUser().getName()).isEqualTo(mMockAuthResult.getUser().getDisplayName());
assertThat(response.getUser().getPhotoUri()).isEqualTo(mMockAuthResult.getUser().getPhotoUrl());
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class EmailLinkSignInHandlerTest method testStartSignIn_differentDeviceLinkWithForceSameDeviceTrue_expectWrongDeviceError.
@Test
@SuppressWarnings("all")
public void testStartSignIn_differentDeviceLinkWithForceSameDeviceTrue_expectWrongDeviceError() {
String differentSessionId = SessionUtils.generateRandomAlphaNumericString(10);
initializeHandlerWithSessionInfo(differentSessionId, null, null, true);
mHandler.getOperation().observeForever(mResponseObserver);
when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true);
mHandler.startSignIn();
verify(mMockAuth).isSignInWithEmailLink(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_WRONG_DEVICE_ERROR);
}
use of com.firebase.ui.auth.IdpResponse 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.IdpResponse 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.IdpResponse 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();
}
Aggregations