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