Search in sources :

Example 46 with CognitoUserPool

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

the class CognitoIdentityProviderForgotPasswordTest method confirmPasswordInBackground.

@Test
public void confirmPasswordInBackground() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    final FlowTracker tracker;
    tracker = new FlowTracker("onSuccess");
    tracker.activate();
    doReturn(TEST_CONFIRM_PASSWORD_RESPONSE).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
    testUser.confirmPasswordInBackground(TEST_CODE, TEST_USER_PASSWORD, new ForgotPasswordHandler() {

        public void onSuccess() {
            // Check the flow
            assertTrue(tracker.check("onSuccess"));
        }

        public void getResetCode(ForgotPasswordContinuation var1) {
            assertTrue(tracker.check("getResetCode"));
            // Except to fail
            tracker.setNext("onFailure");
        }

        public void onFailure(Exception var1) {
            assertTrue(tracker.check("onFailure"));
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 47 with CognitoUserPool

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

the class CognitoIdentityProviderForgotPasswordTest method forgotPasswordInCurrentThreadInvalidUser.

@Test
public void forgotPasswordInCurrentThreadInvalidUser() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    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).forgotPassword(any(ForgotPasswordRequest.class));
    // Except to fail
    final FlowTracker tracker;
    tracker = new FlowTracker("onFailure");
    tracker.activate();
    testUser.forgotPassword(new ForgotPasswordHandler() {

        public void onSuccess() {
            // Check the flow
            assertTrue(tracker.check("onSuccess"));
        }

        public void getResetCode(ForgotPasswordContinuation var1) {
            assertTrue(tracker.check("getResetCode"));
            tracker.setNext("onSuccess");
            doReturn(TEST_CONFIRM_PASSWORD_RESPONSE).when(mockCSIClient).confirmForgotPassword(any(ConfirmForgotPasswordRequest.class));
            var1.setPassword(TEST_USER_PASSWORD);
            var1.setVerificationCode(TEST_CODE);
            var1.continueTask();
        }

        public void onFailure(Exception var1) {
            assertTrue(tracker.check("onFailure"));
        }
    });
}
Also used : InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 48 with CognitoUserPool

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

the class CognitoIdentityProviderUserPoolTest method signUpUserInBackgroundThread.

@Test
public void signUpUserInBackgroundThread() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
    expected_result_boolean = true;
    testPool.signUpInBackground(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, TEST_IN_VALIDATION_DATA, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            // Verify the arguments
            ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
            verify(mockCSIClient).signUp(argumentCaptor.capture());
            SignUpRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_NAME, requestSent.getUsername());
            assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
            assertNotNull(requestSent.getUserAttributes());
            assertEquals(2, requestSent.getUserAttributes().size());
            assertNotNull(requestSent.getValidationData());
            assertEquals(3, requestSent.getValidationData().size());
            assertNotNull(user);
            assertNotNull(signUpResult.getUserConfirmed());
            assertNotNull(signUpResult.getCodeDeliveryDetails());
            assertEquals(TEST_USER_NAME, user.getUserId());
            assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNull(exception);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Test(org.junit.Test)

Example 49 with CognitoUserPool

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

the class CognitoIdentityProviderUserPoolTest method testCacheWithEncryptionKeyNotRetrieved.

@Test
public void testCacheWithEncryptionKeyNotRetrieved() throws Exception {
    SharedPreferences sharedPreferencesForEncryptionMaterials = appContext.getSharedPreferences(SHARED_PREFERENCES_NAME + ".encryptionKey", Context.MODE_PRIVATE);
    // Test with a user cached in shared preferences
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + ".LastAuthUser", TEST_USER_NAME);
    CognitoUser user = testPool.getCurrentUser();
    assertNotNull(user);
    String username = user.getUserId();
    assertEquals(TEST_USER_NAME, username);
    deleteAllEncryptionKeys();
    CognitoUserPool testPoolAfterKeyDeleted = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET);
    AWSKeyValueStore store = getAWSKeyValueStorageUtility(testPoolAfterKeyDeleted);
    assertNull(store.get("CognitoIdentityProvider." + TEST_CLIENT_ID + ".LastAuthUser"));
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) SharedPreferences(android.content.SharedPreferences) AWSKeyValueStore(com.amazonaws.internal.keyvaluestore.AWSKeyValueStore) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) Test(org.junit.Test)

Example 50 with CognitoUserPool

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

the class CognitoIdentityProviderUserPoolTest method newUserPoolWithPinpointWithoutCachedApp.

@Test
public void newUserPoolWithPinpointWithoutCachedApp() {
    // Test new user pool creation with PP app id.
    CognitoUserPool pool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, new ClientConfiguration(), TEST_AWS_REGION_1, TEST_PP_APP_ID_1);
    assertNotNull(pool);
    assertNotNull(pool.getUserPoolId());
    assertEquals(TEST_USER_POOL, pool.getUserPoolId());
    assertNotNull(pool.getClientId());
    assertEquals(TEST_CLIENT_ID, pool.getClientId());
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.junit.Test)

Aggregations

CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)56 Test (org.junit.Test)41 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)28 ArgumentCaptor (org.mockito.ArgumentCaptor)11 SharedPreferences (android.content.SharedPreferences)9 CognitoUser (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)9 GetUserRequest (com.amazonaws.services.cognitoidentityprovider.model.GetUserRequest)8 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)8 CognitoUserAttributes (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes)7 SignUpResult (com.amazonaws.services.cognitoidentityprovider.model.SignUpResult)7 Before (org.junit.Before)7 CognitoUserCodeDeliveryDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails)6 CognitoUserDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails)6 GetDetailsHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler)6 SignUpHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler)6 UpdateAttributesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler)6 SignUpRequest (com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest)6 UnexpectedLambdaException (com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException)6 UpdateUserAttributesRequest (com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesRequest)6 ClientConfiguration (com.amazonaws.ClientConfiguration)4