Search in sources :

Example 1 with SignUpResult

use of com.amazonaws.mobile.client.results.SignUpResult in project amplify-android by aws-amplify.

the class AuthComponentTest method resendSignUpCodeWithOptions.

/**
 * Tests that the resendSignUpCode method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.resendSignUp with
 * the username and options it received.
 * Also ensures that in the onResult case, the success callback receives a valid AuthSignUpResult.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
// Casts final parameter to Callback to differentiate methods
@SuppressWarnings("unchecked")
public void resendSignUpCodeWithOptions() throws AuthException {
    SignUpResult amcResult = new SignUpResult(false, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
    AWSCognitoAuthResendSignUpCodeOptions.CognitoBuilder options = AWSCognitoAuthResendSignUpCodeOptions.builder();
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("key", "value");
    options.metadata(metadata);
    AWSCognitoAuthResendSignUpCodeOptions builtOptions = options.build();
    doAnswer(invocation -> {
        Callback<SignUpResult> callback = invocation.getArgument(2);
        callback.onResult(amcResult);
        return null;
    }).when(mobileClient).resendSignUp(any(), any(), (Callback<SignUpResult>) any());
    AuthSignUpResult result = synchronousAuth.resendSignUpCode(USERNAME, builtOptions);
    validateSignUpResult(result, AuthSignUpStep.CONFIRM_SIGN_UP_STEP);
    verify(mobileClient).resendSignUp(eq(USERNAME), eq(metadata), (Callback<SignUpResult>) any());
}
Also used : HashMap(java.util.HashMap) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) RandomString(com.amplifyframework.testutils.random.RandomString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AWSCognitoAuthResendSignUpCodeOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) SignUpResult(com.amazonaws.mobile.client.results.SignUpResult) Test(org.junit.Test)

Example 2 with SignUpResult

use of com.amazonaws.mobile.client.results.SignUpResult in project amplify-android by aws-amplify.

the class AuthComponentTest method signUp.

/**
 * Tests that the signUp method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.signUp() with the username
 * and password it received and, if included, the userAttributes and validationData sent in the options object.
 * Also ensures that in the onResult case, the success callback receives a valid AuthSignUpResult.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
public void signUp() throws AuthException {
    SignUpResult amcResult = new SignUpResult(false, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
    doAnswer(invocation -> {
        Callback<SignUpResult> callback = invocation.getArgument(5);
        callback.onResult(amcResult);
        return null;
    }).when(mobileClient).signUp(any(), any(), any(), any(), any(), Mockito.<Callback<SignUpResult>>any());
    AWSCognitoAuthSignUpOptions options = AWSCognitoAuthSignUpOptions.builder().userAttribute(AuthUserAttributeKey.email(), ATTRIBUTE_VAL).validationData(VALIDATIONDATA).clientMetadata(CLIENTMETADATA).build();
    AuthSignUpResult result = synchronousAuth.signUp(USERNAME, PASSWORD, options);
    validateSignUpResult(result, AuthSignUpStep.CONFIRM_SIGN_UP_STEP);
    Map<String, String> expectedAttributeMap = Collections.singletonMap(ATTRIBUTE_KEY, ATTRIBUTE_VAL);
    verify(mobileClient).signUp(eq(USERNAME), eq(PASSWORD), eq(expectedAttributeMap), eq(VALIDATIONDATA), eq(CLIENTMETADATA), Mockito.<Callback<SignUpResult>>any());
}
Also used : AWSCognitoAuthSignUpOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignUpOptions) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) RandomString(com.amplifyframework.testutils.random.RandomString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) SignUpResult(com.amazonaws.mobile.client.results.SignUpResult) Test(org.junit.Test)

Example 3 with SignUpResult

use of com.amazonaws.mobile.client.results.SignUpResult in project amplify-android by aws-amplify.

the class AuthComponentTest method resendSignUpCode.

/**
 * Tests that the resendSignUpCode method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.resendSignUp with
 * the username it received .
 * Also ensures that in the onResult case, the success callback receives a valid AuthSignUpResult.
 * @throws AuthException test fails if this gets thrown since method should succeed
 */
@Test
// Casts final parameter to Callback to differentiate methods
@SuppressWarnings("unchecked")
public void resendSignUpCode() throws AuthException {
    SignUpResult amcResult = new SignUpResult(false, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
    doAnswer(invocation -> {
        Callback<SignUpResult> callback = invocation.getArgument(2);
        callback.onResult(amcResult);
        return null;
    }).when(mobileClient).resendSignUp(any(), any(), (Callback<SignUpResult>) any());
    AuthSignUpResult result = synchronousAuth.resendSignUpCode(USERNAME);
    validateSignUpResult(result, AuthSignUpStep.CONFIRM_SIGN_UP_STEP);
    verify(mobileClient).resendSignUp(eq(USERNAME), any(), (Callback<SignUpResult>) any());
}
Also used : UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) SignUpResult(com.amazonaws.mobile.client.results.SignUpResult) Test(org.junit.Test)

Example 4 with SignUpResult

use of com.amazonaws.mobile.client.results.SignUpResult in project amplify-android by aws-amplify.

the class AWSCognitoAuthPlugin method resendSignUpCode.

@Override
public void resendSignUpCode(@NonNull String username, @NonNull AuthResendSignUpCodeOptions options, @NonNull Consumer<AuthSignUpResult> onSuccess, @NonNull Consumer<AuthException> onException) {
    final Map<String, String> clientMetadata = new HashMap<>();
    if (options instanceof AWSCognitoAuthResendSignUpCodeOptions) {
        AWSCognitoAuthResendSignUpCodeOptions cognitoOptions = (AWSCognitoAuthResendSignUpCodeOptions) options;
        clientMetadata.putAll(cognitoOptions.getMetadata());
    }
    awsMobileClient.resendSignUp(username, clientMetadata, new Callback<SignUpResult>() {

        @Override
        public void onResult(SignUpResult result) {
            onSuccess.accept(convertSignUpResult(result, username));
        }

        @Override
        public void onError(Exception error) {
            onException.accept(CognitoAuthExceptionConverter.lookup(error, "Resend confirmation code failed"));
        }
    });
}
Also used : HashMap(java.util.HashMap) AWSCognitoAuthResendSignUpCodeOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions) AuthException(com.amplifyframework.auth.AuthException) JSONException(org.json.JSONException) AmplifyException(com.amplifyframework.AmplifyException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) AuthNavigationException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) SignUpResult(com.amazonaws.mobile.client.results.SignUpResult)

Example 5 with SignUpResult

use of com.amazonaws.mobile.client.results.SignUpResult in project aws-sdk-android by aws-amplify.

the class AWSMobileClientTest method testSignUp.

@Test(expected = com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException.class)
public void testSignUp() throws Exception {
    final String username = "testUser" + System.currentTimeMillis() + new Random().nextInt();
    assertNotEquals("generated usernames are the same", this.username, username);
    final HashMap<String, String> userAttributes = new HashMap<String, String>();
    userAttributes.put("email", EMAIL);
    final SignUpResult signUpResult = auth.signUp(username, PASSWORD, userAttributes, null);
    // Check for non-null user sub in the SignUpResult
    String userSub = signUpResult.getUserSub();
    assertNotNull(userSub);
    // Validate that the userSub is a valid UUID
    assertEquals(36, userSub.length());
    assertEquals(5, userSub.split("-").length);
    assertEquals(8, userSub.split("-")[0].length());
    assertEquals(4, userSub.split("-")[1].length());
    assertEquals(4, userSub.split("-")[2].length());
    assertEquals(4, userSub.split("-")[3].length());
    assertEquals(12, userSub.split("-")[4].length());
    final UserCodeDeliveryDetails details = signUpResult.getUserCodeDeliveryDetails();
    if (details != null) {
        assertEquals("s***@s***.com", details.getDestination());
        assertEquals("email", details.getAttributeName());
        assertEquals("EMAIL", details.getDeliveryMedium());
    }
    assertNotNull(signUpResult.getUserSub());
    final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
    assertEquals("Cannot support MFA in tests", SignInState.DONE, signInResult.getSignInState());
}
Also used : Random(java.util.Random) HashMap(java.util.HashMap) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) SignUpResult(com.amazonaws.mobile.client.results.SignUpResult) SignInResult(com.amazonaws.mobile.client.results.SignInResult) Test(org.junit.Test)

Aggregations

SignUpResult (com.amazonaws.mobile.client.results.SignUpResult)10 AuthSignUpResult (com.amplifyframework.auth.result.AuthSignUpResult)8 UserCodeDeliveryDetails (com.amazonaws.mobile.client.results.UserCodeDeliveryDetails)7 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 JSONException (org.json.JSONException)4 AuthNavigationException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)3 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)3 AmplifyException (com.amplifyframework.AmplifyException)3 AuthException (com.amplifyframework.auth.AuthException)3 RandomString (com.amplifyframework.testutils.random.RandomString)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 AWSCognitoAuthConfirmSignUpOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthConfirmSignUpOptions)2 AWSCognitoAuthResendSignUpCodeOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions)2 AWSCognitoAuthSignUpOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignUpOptions)2 AmazonClientException (com.amazonaws.AmazonClientException)1 ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)1 SignInResult (com.amazonaws.mobile.client.results.SignInResult)1 CognitoUser (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)1 CognitoUserAttributes (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes)1