Search in sources :

Example 6 with GenericHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderChangePasswordInstrumentedTest method changePasswordInCurrentWithNoCachedTokens.

@Test
public void changePasswordInCurrentWithNoCachedTokens() 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));
    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) 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)

Example 7 with GenericHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderChangePasswordInstrumentedTest method changePasswordInBackgroundWithCachedTokens.

// Test change password, with valid tokens - in background
@Test
public void changePasswordInBackgroundWithCachedTokens() throws Exception {
    testUser = testPool.getUser(TEST_USER_NAME);
    // Set mock result for the change password request API call
    doReturn(TEST_CHANGE_PASSWORD_RESPONSE).when(mockCSIClient).changePassword(any(ChangePasswordRequest.class));
    // Store tokens in shared preferences through AWSKeyStore
    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("onSuccess");
    tracker.activate();
    testUser.changePasswordInBackground(TEST_USER_PASSWORD, TEST_USER_NEW_PASS, new GenericHandler() {

        @Override
        public void onSuccess() {
            assertTrue(tracker.check("onSuccess"));
            ArgumentCaptor<ChangePasswordRequest> argumentCaptor = ArgumentCaptor.forClass(ChangePasswordRequest.class);
            verify(mockCSIClient).changePassword(argumentCaptor.capture());
            ChangePasswordRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_PASSWORD, requestSent.getPreviousPassword());
            assertEquals(TEST_USER_NEW_PASS, requestSent.getProposedPassword());
            assertNotNull(requestSent.getAccessToken());
        }

        @Override
        public void onFailure(Exception exception) {
            assertTrue(tracker.check("onFailure"));
            assertNull(exception);
        }
    });
}
Also used : GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) 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)

Example 8 with GenericHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderChangePasswordInstrumentedTest method changePasswordInBackgroundThreadWithNoCachedTokens.

@Test
public void changePasswordInBackgroundThreadWithNoCachedTokens() 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));
    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) 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)

Example 9 with GenericHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderChangePasswordInstrumentedTest method changePasswordInCurrentThreadWithCachedTokens.

// Test change password, with valid tokens - in current thread
@Test
public void changePasswordInCurrentThreadWithCachedTokens() {
    testPool.setPersistenceEnabled(true);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Set mock result for the change password request API call
    doReturn(TEST_CHANGE_PASSWORD_RESPONSE).when(mockCSIClient).changePassword(any(ChangePasswordRequest.class));
    // Store tokens in shared preferences
    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("onSuccess");
    tracker.activate();
    testUser.changePassword(TEST_USER_PASSWORD, TEST_USER_NEW_PASS, new GenericHandler() {

        @Override
        public void onSuccess() {
            assertTrue(tracker.check("onSuccess"));
            ArgumentCaptor<ChangePasswordRequest> argumentCaptor = ArgumentCaptor.forClass(ChangePasswordRequest.class);
            verify(mockCSIClient).changePassword(argumentCaptor.capture());
            ChangePasswordRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_PASSWORD, requestSent.getPreviousPassword());
            assertEquals(TEST_USER_NEW_PASS, requestSent.getProposedPassword());
            assertNotNull(requestSent.getAccessToken());
        }

        @Override
        public void onFailure(Exception exception) {
            assertTrue(tracker.check("onFailure"));
            assertNull(exception);
        }
    });
}
Also used : GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) 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)

Example 10 with GenericHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderChangePasswordInstrumentedTest method changePasswordInCurrentThreadWithCachedTokensException.

// Test change password, exception when run in current thread
@Test
public void changePasswordInCurrentThreadWithCachedTokensException() 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(360000L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(360000L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
    final FlowTracker tracker = new FlowTracker("onFailure");
    tracker.activate();
    testUser.changePassword(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"));
            ArgumentCaptor<ChangePasswordRequest> argumentCaptor = ArgumentCaptor.forClass(ChangePasswordRequest.class);
            verify(mockCSIClient).changePassword(argumentCaptor.capture());
            ChangePasswordRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_PASSWORD, requestSent.getPreviousPassword());
            assertEquals(TEST_USER_NEW_PASS, requestSent.getProposedPassword());
            assertNotNull(requestSent.getAccessToken());
            assertNotNull(exception);
        }
    });
}
Also used : InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) 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

GenericHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler)25 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)15 Test (org.junit.Test)13 Handler (android.os.Handler)12 CognitoInternalErrorException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException)12 CognitoNotAuthorizedException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)12 CognitoParameterInvalidException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException)12 ArgumentCaptor (org.mockito.ArgumentCaptor)9 AuthenticationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler)8 DevicesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler)8 ForgotPasswordHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler)8 GetDetailsHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler)8 RegisterMfaHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler)8 UpdateAttributesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler)8 VerificationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler)8 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)8 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)8 UserNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 FlowTracker (com.amazonaws.mobileconnectors.cognitoidentityprovider.utils.FlowTracker)7