Search in sources :

Example 1 with AuthSignInStep

use of com.amplifyframework.auth.result.step.AuthSignInStep in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testConfirmSignInSucceeds.

/**
 * Validates that a successful call to confirm sign-in will propagate the result
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testConfirmSignInSucceeds() throws InterruptedException {
    String confirmationCode = RandomString.string();
    // Arrange a successful result.
    AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE;
    AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.UNKNOWN);
    AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
    AuthSignInResult expected = new AuthSignInResult(true, nextStep);
    doAnswer(invocation -> {
        // 0 = confirm code, 1 = onResult, 2 = onFailure
        int positionOfResultConsumer = 1;
        Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
        onResult.accept(expected);
        return null;
    }).when(delegate).confirmSignIn(eq(confirmationCode), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthSignInResult> observer = auth.confirmSignIn(confirmationCode).test();
    // Assert: result is furnished
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(expected);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AuthNextSignInStep(com.amplifyframework.auth.result.step.AuthNextSignInStep) RandomString(com.amplifyframework.testutils.random.RandomString) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult) AuthSignInStep(com.amplifyframework.auth.result.step.AuthSignInStep) Test(org.junit.Test)

Example 2 with AuthSignInStep

use of com.amplifyframework.auth.result.step.AuthSignInStep in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testSignInWithSocialWebUISucceeds.

/**
 * Validates that a successful call to sign-in with social web UI will propagate the result
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testSignInWithSocialWebUISucceeds() throws InterruptedException {
    AuthProvider provider = AuthProvider.amazon();
    Activity activity = new Activity();
    // Arrange a successful result
    AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE;
    AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.PHONE);
    AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
    AuthSignInResult result = new AuthSignInResult(false, nextStep);
    doAnswer(invocation -> {
        // 0 = provider, 1 = activity, 2 = result consumer, 3 = failure consumer
        int positionOfResultConsumer = 2;
        Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
        onResult.accept(result);
        return null;
    }).when(delegate).signInWithSocialWebUI(eq(provider), eq(activity), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthSignInResult> observer = auth.signInWithSocialWebUI(provider, activity).test();
    // Assert: result is furnished the via the Rx Single
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(result);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) Activity(android.app.Activity) AuthProvider(com.amplifyframework.auth.AuthProvider) AuthNextSignInStep(com.amplifyframework.auth.result.step.AuthNextSignInStep) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult) AuthSignInStep(com.amplifyframework.auth.result.step.AuthSignInStep) Test(org.junit.Test)

Example 3 with AuthSignInStep

use of com.amplifyframework.auth.result.step.AuthSignInStep in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testSignInWithWebUISucceeds.

/**
 * Validates that a successful call to sign-in with web UI will propagate the result
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testSignInWithWebUISucceeds() throws InterruptedException {
    Activity activity = new Activity();
    // Arrange a result
    AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE;
    AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.PHONE);
    AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
    AuthSignInResult result = new AuthSignInResult(false, nextStep);
    doAnswer(invocation -> {
        // 0 = activity, 1 = result consumer, 2 = failure consumer
        int positionOfResultConsumer = 1;
        Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
        onResult.accept(result);
        return null;
    }).when(delegate).signInWithWebUI(eq(activity), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthSignInResult> observer = auth.signInWithWebUI(activity).test();
    // Assert: result is furnished the via the Rx Single
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(result);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) Activity(android.app.Activity) AuthNextSignInStep(com.amplifyframework.auth.result.step.AuthNextSignInStep) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult) AuthSignInStep(com.amplifyframework.auth.result.step.AuthSignInStep) Test(org.junit.Test)

Example 4 with AuthSignInStep

use of com.amplifyframework.auth.result.step.AuthSignInStep in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testSignInSucceeds.

/**
 * Validates that a successful call to sign-in will propagate the result
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testSignInSucceeds() throws InterruptedException {
    String username = RandomString.string();
    String password = RandomString.string();
    // Arrange a result on the result consumer
    AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.EMAIL);
    AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE;
    AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
    AuthSignInResult result = new AuthSignInResult(false, nextStep);
    doAnswer(invocation -> {
        // 0 = username, 1 = password, 2 = onResult, 3 = onFailure
        int positionOfResultConsumer = 2;
        Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
        onResult.accept(result);
        return null;
    }).when(delegate).signIn(eq(username), eq(password), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthSignInResult> observer = auth.signIn(username, password).test();
    // Assert: the result was furnished to the Rx Single
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(result);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AuthNextSignInStep(com.amplifyframework.auth.result.step.AuthNextSignInStep) RandomString(com.amplifyframework.testutils.random.RandomString) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult) AuthSignInStep(com.amplifyframework.auth.result.step.AuthSignInStep) Test(org.junit.Test)

Aggregations

AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)4 AuthSignInResult (com.amplifyframework.auth.result.AuthSignInResult)4 AuthNextSignInStep (com.amplifyframework.auth.result.step.AuthNextSignInStep)4 AuthSignInStep (com.amplifyframework.auth.result.step.AuthSignInStep)4 Test (org.junit.Test)4 Activity (android.app.Activity)2 RandomString (com.amplifyframework.testutils.random.RandomString)2 AuthProvider (com.amplifyframework.auth.AuthProvider)1