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());
}
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());
}
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());
}
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"));
}
});
}
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());
}
Aggregations