Search in sources :

Example 6 with AuthCodeDeliveryDetails

use of com.amplifyframework.auth.AuthCodeDeliveryDetails in project amplify-android by aws-amplify.

the class AuthComponentTest method resendUserAttributeConfirmationCode.

/**
 * Tests the resendUserAttributeConfirmationCode method of the Auth wrapper of AWSMobileClient (AMC) Calls
 * AMC.verifyUserAttribute with the user attribute key to be verified.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
public void resendUserAttributeConfirmationCode() throws AuthException {
    AuthUserAttributeKey attributeKey = AuthUserAttributeKey.custom(ATTRIBUTE_KEY);
    UserCodeDeliveryDetails userCodeDeliveryDetails = new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME);
    doAnswer(invocation -> {
        Callback<UserCodeDeliveryDetails> callback = invocation.getArgument(2);
        callback.onResult(userCodeDeliveryDetails);
        return null;
    }).when(mobileClient).verifyUserAttribute(any(), any(), Mockito.<Callback<UserCodeDeliveryDetails>>any());
    AuthCodeDeliveryDetails result = synchronousAuth.resendUserAttributeConfirmationCode(attributeKey);
    validateCodeDeliveryDetails(result);
    verify(mobileClient).verifyUserAttribute(eq(attributeKey.getKeyString()), any(), Mockito.<Callback<UserCodeDeliveryDetails>>any());
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthUserAttributeKey(com.amplifyframework.auth.AuthUserAttributeKey) Test(org.junit.Test)

Example 7 with AuthCodeDeliveryDetails

use of com.amplifyframework.auth.AuthCodeDeliveryDetails in project amplify-android by aws-amplify.

the class AWSCognitoAuthPlugin method convertSignUpResult.

private AuthSignUpResult convertSignUpResult(@NonNull SignUpResult result, @NonNull String username) {
    UserCodeDeliveryDetails details = Objects.requireNonNull(result).getUserCodeDeliveryDetails();
    AuthCodeDeliveryDetails newDetails = details != null ? new AuthCodeDeliveryDetails(details.getDestination(), AuthCodeDeliveryDetails.DeliveryMedium.fromString(details.getDeliveryMedium()), details.getAttributeName()) : null;
    return new AuthSignUpResult(true, new AuthNextSignUpStep(result.getConfirmationState() ? AuthSignUpStep.DONE : AuthSignUpStep.CONFIRM_SIGN_UP_STEP, Collections.emptyMap(), newDetails), result.getUserSub() != null ? new AuthUser(result.getUserSub(), username) : null);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AuthNextSignUpStep(com.amplifyframework.auth.result.step.AuthNextSignUpStep) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) AuthUser(com.amplifyframework.auth.AuthUser)

Example 8 with AuthCodeDeliveryDetails

use of com.amplifyframework.auth.AuthCodeDeliveryDetails in project amplify-android by aws-amplify.

the class AuthComponentTest method resendUserAttributeConfirmationCodeWithOptions.

/**
 * Tests the resendUserAttributeConfirmationCode method of the Auth wrapper of AWSMobileClient (AMC) Calls
 * AMC.verifyUserAttribute with the user attribute key to be verified and options it received.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
public void resendUserAttributeConfirmationCodeWithOptions() throws AuthException {
    AuthUserAttributeKey attributeKey = AuthUserAttributeKey.custom(ATTRIBUTE_KEY);
    UserCodeDeliveryDetails userCodeDeliveryDetails = new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME);
    AWSCognitoAuthResendUserAttributeConfirmationCodeOptions.CognitoBuilder options = AWSCognitoAuthResendUserAttributeConfirmationCodeOptions.builder();
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("key", "value");
    options.metadata(metadata);
    AWSCognitoAuthResendUserAttributeConfirmationCodeOptions builtOptions = options.build();
    doAnswer(invocation -> {
        Callback<UserCodeDeliveryDetails> callback = invocation.getArgument(2);
        callback.onResult(userCodeDeliveryDetails);
        return null;
    }).when(mobileClient).verifyUserAttribute(any(), any(), Mockito.<Callback<UserCodeDeliveryDetails>>any());
    AuthCodeDeliveryDetails result = synchronousAuth.resendUserAttributeConfirmationCode(attributeKey, builtOptions);
    validateCodeDeliveryDetails(result);
    verify(mobileClient).verifyUserAttribute(eq(attributeKey.getKeyString()), eq(metadata), Mockito.<Callback<UserCodeDeliveryDetails>>any());
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AWSCognitoAuthResendUserAttributeConfirmationCodeOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttributeConfirmationCodeOptions) HashMap(java.util.HashMap) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthUserAttributeKey(com.amplifyframework.auth.AuthUserAttributeKey) RandomString(com.amplifyframework.testutils.random.RandomString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with AuthCodeDeliveryDetails

use of com.amplifyframework.auth.AuthCodeDeliveryDetails 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 10 with AuthCodeDeliveryDetails

use of com.amplifyframework.auth.AuthCodeDeliveryDetails in project amplify-android by aws-amplify.

the class RxAuthBindingTest method testResetPasswordSucceeds.

/**
 * Tests that a successful request to reset the password will propagate a result
 * back through the binding.
 * @throws InterruptedException If test observer is interrupted while awaiting terminal event
 */
@Test
public void testResetPasswordSucceeds() throws InterruptedException {
    String username = RandomString.string();
    // Arrange delegate to furnish a result
    AuthResetPasswordStep step = AuthResetPasswordStep.CONFIRM_RESET_PASSWORD_WITH_CODE;
    AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.PHONE);
    AuthNextResetPasswordStep nextStep = new AuthNextResetPasswordStep(step, Collections.emptyMap(), details);
    AuthResetPasswordResult expected = new AuthResetPasswordResult(true, nextStep);
    doAnswer(invocation -> {
        // 0 = username, 1 = onResult, 2 = onFailure
        int positionOfResultConsumer = 1;
        Consumer<AuthResetPasswordResult> onResult = invocation.getArgument(positionOfResultConsumer);
        onResult.accept(expected);
        return null;
    }).when(delegate).resetPassword(eq(username), anyConsumer(), anyConsumer());
    // Act: call the binding
    TestObserver<AuthResetPasswordResult> observer = auth.resetPassword(username).test();
    // Assert: result was furnished via Rx Single
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertNoErrors().assertValue(expected);
}
Also used : AuthCodeDeliveryDetails(com.amplifyframework.auth.AuthCodeDeliveryDetails) AuthNextResetPasswordStep(com.amplifyframework.auth.result.step.AuthNextResetPasswordStep) RandomString(com.amplifyframework.testutils.random.RandomString) AuthResetPasswordResult(com.amplifyframework.auth.result.AuthResetPasswordResult) AuthResetPasswordStep(com.amplifyframework.auth.result.step.AuthResetPasswordStep) Test(org.junit.Test)

Aggregations

AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)12 Test (org.junit.Test)11 RandomString (com.amplifyframework.testutils.random.RandomString)6 AuthUserAttributeKey (com.amplifyframework.auth.AuthUserAttributeKey)4 AuthSignInResult (com.amplifyframework.auth.result.AuthSignInResult)4 AuthNextSignInStep (com.amplifyframework.auth.result.step.AuthNextSignInStep)4 AuthSignInStep (com.amplifyframework.auth.result.step.AuthSignInStep)4 UserCodeDeliveryDetails (com.amazonaws.mobile.client.results.UserCodeDeliveryDetails)3 AuthSignUpResult (com.amplifyframework.auth.result.AuthSignUpResult)3 AuthNextSignUpStep (com.amplifyframework.auth.result.step.AuthNextSignUpStep)3 Activity (android.app.Activity)2 AuthSignUpStep (com.amplifyframework.auth.result.step.AuthSignUpStep)2 HashMap (java.util.HashMap)2 AuthProvider (com.amplifyframework.auth.AuthProvider)1 AuthUser (com.amplifyframework.auth.AuthUser)1 AuthUserAttribute (com.amplifyframework.auth.AuthUserAttribute)1 AWSCognitoAuthResendUserAttributeConfirmationCodeOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttributeConfirmationCodeOptions)1 AuthSignUpOptions (com.amplifyframework.auth.options.AuthSignUpOptions)1 AuthResetPasswordResult (com.amplifyframework.auth.result.AuthResetPasswordResult)1 AuthUpdateAttributeResult (com.amplifyframework.auth.result.AuthUpdateAttributeResult)1