use of com.google.firebase.auth.OAuthProvider in project FirebaseUI-Android by firebase.
the class GenericIdpSignInHandlerTest method testStartSignIn_anonymousUpgradeFlowWithConflict_expectRecoverableError.
@Test
public void testStartSignIn_anonymousUpgradeFlowWithConflict_expectRecoverableError() {
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 1: Anon user signing in with an existing account
when(mMockAuth.fetchSignInMethodsForEmail(any(String.class))).thenReturn(AutoCompleteTask.forSuccess(new FakeSignInMethodQueryResult(Arrays.asList(MICROSOFT_PROVIDER))));
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());
FirebaseAuthAnonymousUpgradeException e = (FirebaseAuthAnonymousUpgradeException) resolveCaptor.getValue().getException();
assertThat(e.getResponse().getCredentialForLinking()).isNotNull();
}
use of com.google.firebase.auth.OAuthProvider in project FirebaseUI-Android by firebase.
the class GenericIdpSignInHandlerTest method testStartSignIn_normalSignInFlowWithError_expectFailure.
@Test
public void testStartSignIn_normalSignInFlowWithError_expectFailure() {
FirebaseAuthException firebaseAuthException = new FirebaseAuthException("foo", "bar");
when(mMockAuth.startActivityForSignInWithProvider(any(Activity.class), any(OAuthProvider.class))).thenReturn(AutoCompleteTask.forFailure(firebaseAuthException));
mockOAuthProvider(MICROSOFT_PROVIDER);
mHandler.startSignIn(mMockAuth, mMockActivity, MICROSOFT_PROVIDER);
ArgumentCaptor<OAuthProvider> providerCaptor = ArgumentCaptor.forClass(OAuthProvider.class);
verify(mMockAuth).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>> resourceCaptor = ArgumentCaptor.forClass(Resource.class);
inOrder.verify(mResponseObserver).onChanged(resourceCaptor.capture());
assertThat(resourceCaptor.getValue().getException()).isInstanceOf(FirebaseAuthException.class);
}
use of com.google.firebase.auth.OAuthProvider in project FirebaseUI-Android by firebase.
the class GenericIdpAnonymousUpgradeLinkingHandlerTest method mockOAuthProvider.
private void mockOAuthProvider(String providerId) {
// TODO(samstern): I wish we did not have to do this but the OAuthProvider() builder
// throws a NPE and we can't fix it due to b/172544960
OAuthProvider mockProvider = mock(OAuthProvider.class);
when(mockProvider.getProviderId()).thenReturn(providerId);
doReturn(mockProvider).when(mHandler).buildOAuthProvider(anyString(), any(FirebaseAuth.class));
}
use of com.google.firebase.auth.OAuthProvider 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.OAuthProvider 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();
}
Aggregations