Search in sources :

Example 11 with FlowTracker

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.utils.FlowTracker in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderChangePasswordInstrumentedTest method changePasswordInCurrentWithExpiredCachedTokensException.

@Test
public void changePasswordInCurrentWithExpiredCachedTokensException() throws Exception {
    testUser = testPool.getUser(TEST_USER_NAME);
    // Set mock result for the change password request API call
    InvalidParameterException exception = new InvalidParameterException("password change request failed");
    doThrow(exception).when(mockCSIClient).changePassword(any(ChangePasswordRequest.class));
    // Store tokens in shared preferences
    SharedPreferences sharedPreferences = appContext.getSharedPreferences("CognitoIdentityProviderCache", Context.MODE_PRIVATE);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(-3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(-3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
    final FlowTracker tracker = new FlowTracker("onFailure");
    tracker.activate();
    testUser.changePasswordInBackground(TEST_USER_PASSWORD, TEST_USER_NEW_PASS, new GenericHandler() {

        @Override
        public void onSuccess() {
            assertTrue(tracker.check("onSuccess"));
        }

        @Override
        public void onFailure(Exception exception) {
            assertTrue(tracker.check("onFailure"));
            assertNotNull(exception);
        }
    });
}
Also used : InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) SharedPreferences(android.content.SharedPreferences) FlowTracker(com.amazonaws.mobileconnectors.cognitoidentityprovider.utils.FlowTracker) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) ChangePasswordRequest(com.amazonaws.services.cognitoidentityprovider.model.ChangePasswordRequest) Test(org.junit.Test)

Aggregations

FlowTracker (com.amazonaws.mobileconnectors.cognitoidentityprovider.utils.FlowTracker)11 Test (org.junit.Test)11 GenericHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler)7 ChangePasswordRequest (com.amazonaws.services.cognitoidentityprovider.model.ChangePasswordRequest)7 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)7 ArgumentCaptor (org.mockito.ArgumentCaptor)7 CognitoDevice (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice)4 CognitoUserSession (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession)4 AuthenticationContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation)4 AuthenticationDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails)4 ChallengeContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation)4 MultiFactorAuthenticationContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation)4 AuthenticationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler)4 InitiateAuthRequest (com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthRequest)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Ignore (org.junit.Ignore)4 SharedPreferences (android.content.SharedPreferences)3 RespondToAuthChallengeRequest (com.amazonaws.services.cognitoidentityprovider.model.RespondToAuthChallengeRequest)2 CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)1