Search in sources :

Example 11 with Resource

use of com.firebase.ui.auth.data.model.Resource in project FirebaseUI-Android by firebase.

the class GenericIdpSignInHandlerTest method testStartSignIn_normalSignInFlow_expectSuccess.

@Test
public void testStartSignIn_normalSignInFlow_expectSuccess() {
    mHandler.getOperation().observeForever(mResponseObserver);
    when(mMockAuth.startActivityForSignInWithProvider(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).startActivityForSignInWithProvider(eq(mMockActivity), providerCaptor.capture());
    assertThat(providerCaptor.getValue().getProviderId()).isEqualTo(MICROSOFT_PROVIDER);
    HashMap<String, String> customArgs = (HashMap<String, String>) mHandler.getArguments().getParams().getSerializable(ExtraConstants.GENERIC_OAUTH_CUSTOM_PARAMETERS);
    assertThat(customArgs).isNotNull();
    assertThat(customArgs).hasSize(1);
    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();
}
Also used : InOrder(org.mockito.InOrder) HashMap(java.util.HashMap) Resource(com.firebase.ui.auth.data.model.Resource) Activity(android.app.Activity) OAuthProvider(com.google.firebase.auth.OAuthProvider) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 12 with Resource

use of com.firebase.ui.auth.data.model.Resource 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();
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) FakeSignInMethodQueryResult(com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult) InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) Activity(android.app.Activity) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) OAuthProvider(com.google.firebase.auth.OAuthProvider) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FirebaseAuthAnonymousUpgradeException(com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException) Test(org.junit.Test)

Example 13 with Resource

use of com.firebase.ui.auth.data.model.Resource 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);
}
Also used : InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) Activity(android.app.Activity) OAuthProvider(com.google.firebase.auth.OAuthProvider) FirebaseAuthException(com.google.firebase.auth.FirebaseAuthException) Test(org.junit.Test)

Example 14 with Resource

use of com.firebase.ui.auth.data.model.Resource in project FirebaseUI-Android by firebase.

the class SmartLockHandlerTest method testSaveCredentials_resolution.

@Test
public void testSaveCredentials_resolution() {
    mHandler.getOperation().observeForever(mResultObserver);
    // Mock credentials to throw an RAE
    ResolvableApiException mockRae = mock(ResolvableApiException.class);
    when(mMockCredentials.save(any(Credential.class))).thenReturn(AutoCompleteTask.forFailure(mockRae));
    // Kick off save
    mHandler.saveCredentials(TestHelper.getMockFirebaseUser(), TestConstants.PASSWORD, null);
    InOrder inOrder = inOrder(mResultObserver);
    inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    // Make sure we get a resolution
    ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResultObserver).onChanged(resolveCaptor.capture());
    // Call activity result
    PendingIntentRequiredException e = ((PendingIntentRequiredException) resolveCaptor.getValue().getException());
    mHandler.onActivityResult(e.getRequestCode(), Activity.RESULT_OK);
    // Make sure we get success
    inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
Also used : ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) Credential(com.google.android.gms.auth.api.credentials.Credential) InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException) Test(org.junit.Test)

Example 15 with Resource

use of com.firebase.ui.auth.data.model.Resource in project FirebaseUI-Android by firebase.

the class WelcomeBackPasswordHandlerTest method verifyMergeFailure.

private void verifyMergeFailure() {
    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());
    EmailAuthCredential responseCredential = (EmailAuthCredential) e.getResponse().getCredentialForLinking();
// TODO: EmailAuthCredential no longer exposes .getEmail() or .getPassword()
// assertThat(responseCredential.getEmail()).isEqualTo(TestConstants.EMAIL);
// assertThat(responseCredential.getPassword()).isEqualTo(TestConstants.PASSWORD);
}
Also used : EmailAuthCredential(com.google.firebase.auth.EmailAuthCredential) InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) FirebaseAuthAnonymousUpgradeException(com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException)

Aggregations

Resource (com.firebase.ui.auth.data.model.Resource)36 InOrder (org.mockito.InOrder)35 Test (org.junit.Test)34 IdpResponse (com.firebase.ui.auth.IdpResponse)28 AuthCredential (com.google.firebase.auth.AuthCredential)20 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)13 FirebaseAuthAnonymousUpgradeException (com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException)11 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)9 EmailAuthCredential (com.google.firebase.auth.EmailAuthCredential)9 FacebookAuthCredential (com.google.firebase.auth.FacebookAuthCredential)8 OAuthProvider (com.google.firebase.auth.OAuthProvider)7 Activity (android.app.Activity)6 FakeSignInMethodQueryResult (com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult)6 AuthOperationManager (com.firebase.ui.auth.util.data.AuthOperationManager)5 IntentRequiredException (com.firebase.ui.auth.data.model.IntentRequiredException)3 ActionCodeSettings (com.google.firebase.auth.ActionCodeSettings)3 GoogleAuthCredential (com.google.firebase.auth.GoogleAuthCredential)3 FirebaseUiUserCollisionException (com.firebase.ui.auth.FirebaseUiUserCollisionException)2 User (com.firebase.ui.auth.data.model.User)2 FirebaseUser (com.google.firebase.auth.FirebaseUser)2