Search in sources :

Example 1 with AuthNextSignInStep

use of com.amplifyframework.auth.result.step.AuthNextSignInStep 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 AuthNextSignInStep

use of com.amplifyframework.auth.result.step.AuthNextSignInStep 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 AuthNextSignInStep

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

the class AuthComponentTest method validateSignInResult.

private void validateSignInResult(AuthSignInResult result, boolean targetIsSignedIn, AuthSignInStep targetStep) {
    AuthNextSignInStep nextStep = result.getNextStep();
    validateCodeDeliveryDetails(nextStep.getCodeDeliveryDetails());
    assertEquals(targetIsSignedIn, result.isSignInComplete());
    assertEquals(targetStep, nextStep.getSignInStep());
}
Also used : AuthNextSignInStep(com.amplifyframework.auth.result.step.AuthNextSignInStep)

Example 4 with AuthNextSignInStep

use of com.amplifyframework.auth.result.step.AuthNextSignInStep 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 5 with AuthNextSignInStep

use of com.amplifyframework.auth.result.step.AuthNextSignInStep 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

AuthNextSignInStep (com.amplifyframework.auth.result.step.AuthNextSignInStep)6 AuthSignInResult (com.amplifyframework.auth.result.AuthSignInResult)5 AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)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 HostedUIOptions (com.amazonaws.mobile.client.HostedUIOptions)1 SignInUIOptions (com.amazonaws.mobile.client.SignInUIOptions)1 UserStateDetails (com.amazonaws.mobile.client.UserStateDetails)1 AuthNavigationException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)1 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)1 AmplifyException (com.amplifyframework.AmplifyException)1 AuthException (com.amplifyframework.auth.AuthException)1 AuthProvider (com.amplifyframework.auth.AuthProvider)1 AWSCognitoAuthWebUISignInOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthWebUISignInOptions)1 JSONException (org.json.JSONException)1