use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails 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());
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method signIn.
/**
* Tests that the signIn method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.signIn with
* the username, password it received, and, if included, the metadata sent in the options object.
* Also ensures that in the onResult case, the success callback receives a valid AuthSignInResult.
* @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 signIn() throws AuthException {
SignInResult amcResult = new SignInResult(SignInState.SMS_MFA, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME));
Tokens tokensResult = new Tokens(ACCESS_TOKEN, ID_TOKEN, REFRESH_TOKEN);
doAnswer(invocation -> {
Callback<Tokens> callback = invocation.getArgument(0);
callback.onResult(tokensResult);
return null;
}).when(mobileClient).getTokens(any());
doAnswer(invocation -> {
Callback<SignInResult> callback = invocation.getArgument(5);
callback.onResult(amcResult);
return null;
}).when(mobileClient).signIn(any(), any(), any(), any(), any(), (Callback<SignInResult>) any());
AuthSignInResult result = synchronousAuth.signIn(USERNAME, PASSWORD, AWSCognitoAuthSignInOptions.builder().metadata(CLIENTMETADATA).build());
validateSignInResult(result, false, AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE);
verify(mobileClient).signIn(eq(USERNAME), eq(PASSWORD), eq(CLIENTMETADATA), eq(Collections.emptyMap()), eq(null), (Callback<SignInResult>) any());
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method confirmSignUp.
/**
* Tests that the confirmSignUp method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.confirmSignUp with
* the username and confirmation code 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
public void confirmSignUp() throws AuthException {
SignUpResult amcResult = new SignUpResult(true, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
doAnswer(invocation -> {
Callback<SignUpResult> callback = invocation.getArgument(3);
callback.onResult(amcResult);
return null;
}).when(mobileClient).confirmSignUp(any(), any(), any(), Mockito.<Callback<SignUpResult>>any());
AuthSignUpResult result = synchronousAuth.confirmSignUp(USERNAME, CONFIRMATION_CODE);
validateSignUpResult(result, AuthSignUpStep.DONE);
verify(mobileClient).confirmSignUp(eq(USERNAME), eq(CONFIRMATION_CODE), any(), Mockito.<Callback<SignUpResult>>any());
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method confirmSignUpWithOptions.
/**
* Tests that the confirmSignUp method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.confirmSignUp with
* the username and confirmation code 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
public void confirmSignUpWithOptions() throws AuthException {
SignUpResult amcResult = new SignUpResult(true, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
AWSCognitoAuthConfirmSignUpOptions.CognitoBuilder options = AWSCognitoAuthConfirmSignUpOptions.builder();
Map<String, String> clientMetadata = new HashMap<String, String>();
clientMetadata.put("testKey", "testValue");
options.clientMetadata(clientMetadata);
AWSCognitoAuthConfirmSignUpOptions builtOptions = options.build();
doAnswer(invocation -> {
Callback<SignUpResult> callback = invocation.getArgument(3);
callback.onResult(amcResult);
return null;
}).when(mobileClient).confirmSignUp(any(), any(), any(), Mockito.<Callback<SignUpResult>>any());
AuthSignUpResult result = synchronousAuth.confirmSignUp(USERNAME, CONFIRMATION_CODE, builtOptions);
validateSignUpResult(result, AuthSignUpStep.DONE);
verify(mobileClient).confirmSignUp(eq(USERNAME), eq(CONFIRMATION_CODE), eq(clientMetadata), Mockito.<Callback<SignUpResult>>any());
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method confirmSignIn.
/**
* Tests that the confirmSignIn method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.confirmSignIn with
* the confirmation code it received and the success callback receives a valid AuthSignInResult.
* @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 confirmSignIn() throws AuthException {
SignInResult amcResult = new SignInResult(SignInState.DONE, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME));
Tokens tokensResult = new Tokens(ACCESS_TOKEN, ID_TOKEN, REFRESH_TOKEN);
doAnswer(invocation -> {
Callback<Tokens> callback = invocation.getArgument(0);
callback.onResult(tokensResult);
return null;
}).when(mobileClient).getTokens(any());
doAnswer(invocation -> {
Callback<SignInResult> callback = invocation.getArgument(3);
callback.onResult(amcResult);
return null;
}).when(mobileClient).confirmSignIn(any(String.class), any(), any(), (Callback<SignInResult>) any());
AuthSignInResult result = synchronousAuth.confirmSignIn(CONFIRMATION_CODE);
validateSignInResult(result, true, AuthSignInStep.DONE);
verify(mobileClient).confirmSignIn(eq(CONFIRMATION_CODE), any(), any(), (Callback<SignInResult>) any());
}
Aggregations