use of com.amplifyframework.auth.result.AuthSignInResult in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignInWithWebUIFails.
/**
* Validates that a failed call to sign-in with web UI will propagate the failure
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignInWithWebUIFails() throws InterruptedException {
Activity activity = new Activity();
// Arrange a failure
AuthException failure = new AuthException("Sign in with web UI", " has failed");
doAnswer(invocation -> {
// 0 = activity, 1 = result consumer, 2 = failure consumer
int positionOfFailureConsumer = 2;
Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
onFailure.accept(failure);
return null;
}).when(delegate).signInWithWebUI(eq(activity), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignInResult> observer = auth.signInWithWebUI(activity).test();
// Assert: failure is furnished the via the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoValues().assertError(failure);
}
use of com.amplifyframework.auth.result.AuthSignInResult in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testConfirmSignInSucceeds.
/**
* Validates that a successful call to confirm sign-in will propagate the result
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testConfirmSignInSucceeds() throws InterruptedException {
String confirmationCode = RandomString.string();
// Arrange a successful result.
AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE;
AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.UNKNOWN);
AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
AuthSignInResult expected = new AuthSignInResult(true, nextStep);
doAnswer(invocation -> {
// 0 = confirm code, 1 = onResult, 2 = onFailure
int positionOfResultConsumer = 1;
Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
onResult.accept(expected);
return null;
}).when(delegate).confirmSignIn(eq(confirmationCode), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignInResult> observer = auth.confirmSignIn(confirmationCode).test();
// Assert: result is furnished
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(expected);
}
use of com.amplifyframework.auth.result.AuthSignInResult in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignInWithSocialWebUISucceeds.
/**
* Validates that a successful call to sign-in with social web UI will propagate the result
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignInWithSocialWebUISucceeds() throws InterruptedException {
AuthProvider provider = AuthProvider.amazon();
Activity activity = new Activity();
// Arrange a successful result
AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE;
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 = provider, 1 = activity, 2 = result consumer, 3 = failure consumer
int positionOfResultConsumer = 2;
Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
onResult.accept(result);
return null;
}).when(delegate).signInWithSocialWebUI(eq(provider), eq(activity), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignInResult> observer = auth.signInWithSocialWebUI(provider, 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.result.AuthSignInResult in project amplify-android by aws-amplify.
the class AuthComponentTest method signInWithWebUI.
/**
* Tests that the signInWithWebUI method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.showSignIn
* with the proper parameters and converts the returned result to the proper AuthSignInResult.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void signInWithWebUI() throws AuthException {
Map<String, String> additionalInfoMap = Collections.singletonMap("testKey", "testVal");
UserStateDetails userStateResult = new UserStateDetails(UserState.SIGNED_IN, additionalInfoMap);
doAnswer(invocation -> {
Callback<UserStateDetails> callback = invocation.getArgument(2);
callback.onResult(userStateResult);
return null;
}).when(mobileClient).showSignIn(any(), any(), any());
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());
Activity activity = new Activity();
String federationProviderName = "testFedProvider";
String idpIdentifier = "testIdpID";
String browserPackage = "org.mozilla.firefox";
List<String> scopes = Collections.singletonList("scope");
Map<String, String> signInMap = Collections.singletonMap("signInKey", "signInVal");
Map<String, String> signOutMap = Collections.singletonMap("signOutKey", "signOutVal");
Map<String, String> tokensMap = Collections.singletonMap("tokensKey", "tokensVal");
AuthSignInResult result = synchronousAuth.signInWithWebUI(activity, AWSCognitoAuthWebUISignInOptions.builder().federationProviderName(federationProviderName).idpIdentifier(idpIdentifier).scopes(scopes).signInQueryParameters(signInMap).signOutQueryParameters(signOutMap).tokenQueryParameters(tokensMap).browserPackage(browserPackage).build());
assertTrue(result.isSignInComplete());
assertEquals(AuthSignInStep.DONE, result.getNextStep().getSignInStep());
assertEquals(additionalInfoMap, result.getNextStep().getAdditionalInfo());
ArgumentCaptor<SignInUIOptions> optionsCaptor = ArgumentCaptor.forClass(SignInUIOptions.class);
verify(mobileClient).showSignIn(eq(activity), optionsCaptor.capture(), any());
SignInUIOptions signInUIOptions = optionsCaptor.getValue();
HostedUIOptions hostedUIOptions = signInUIOptions.getHostedUIOptions();
assertNotNull(hostedUIOptions);
assertNull(hostedUIOptions.getIdentityProvider());
assertEquals(federationProviderName, hostedUIOptions.getFederationProviderName());
assertEquals(idpIdentifier, hostedUIOptions.getIdpIdentifier());
assertEquals(browserPackage, signInUIOptions.getBrowserPackage());
assertArrayEquals(scopes.toArray(), hostedUIOptions.getScopes());
assertEquals(signInMap, hostedUIOptions.getSignInQueryParameters());
assertEquals(signOutMap, hostedUIOptions.getSignOutQueryParameters());
assertEquals(tokensMap, hostedUIOptions.getTokenQueryParameters());
}
use of com.amplifyframework.auth.result.AuthSignInResult in project amplify-android by aws-amplify.
the class AuthComponentTest method signInWithAuthFlow.
/**
* Tests that the signIn method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.signIn with
* the username, password it received, authFLowType 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 signInWithAuthFlow() 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).authFlowType(AuthFlowType.CUSTOM_AUTH).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(com.amazonaws.services.cognitoidentityprovider.model.AuthFlowType.CUSTOM_AUTH), (Callback<SignInResult>) any());
}
Aggregations