Search in sources :

Example 6 with FlowTracker

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

the class CognitoIdentityProviderSignInUserTest method getSessionInCurrentThreadNoCachedTokensNoMFA.

// Authenticate user with user password verifier in current thread
@Ignore
@Test
public void getSessionInCurrentThreadNoCachedTokensNoMFA() throws Exception {
    assertNotNull(testUser.getUserId());
    // Test with a user cached in shared preferences, with no cached tokens
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + ".LastAuthUser", TEST_USER_NAME);
    // Set mock returns for Authentication API Calls
    // API call to start forgot-password flow
    doReturn(TEST_VALID_INITIATE_USER_SRP_AUTH_RESPONSE).when(mockCSIClient).initiateAuth(any(InitiateAuthRequest.class));
    // Tracker to validate the callback sequence -> callback.getAuthenticationDetails() -> onSuccess()
    final FlowTracker tracker = new FlowTracker("getAuthenticationDetails");
    System.out.println("Get session");
    testUser.getSession(new AuthenticationHandler() {

        @Override
        public void onSuccess(CognitoUserSession session, CognitoDevice device) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("onSuccess"));
            // Extract the arguments passed to the initiateAuth API call
            ArgumentCaptor<InitiateAuthRequest> argumentCaptor = ArgumentCaptor.forClass(InitiateAuthRequest.class);
            verify(mockCSIClient).initiateAuth(argumentCaptor.capture());
            InitiateAuthRequest requestSent = argumentCaptor.getValue();
            // Verify the arguments passed in the API call
            assertNotNull(requestSent);
            assertEquals(TEST_CLIENT_ID, requestSent.getClientId());
            assertEquals("USER_SRP_AUTH", requestSent.getAuthFlow());
            // Check authentication parameters
            assertNotNull(requestSent.getAuthParameters());
            assertNotNull(requestSent.getAuthParameters().get("SRP_A"));
            assertNotNull(requestSent.getAuthParameters().get("SECRET_HASH"));
            assertNotNull(requestSent.getAuthParameters().get("USERNAME"));
            assertNotNull(requestSent.getAuthParameters().get("SRP_A"));
            // Check Validation parameters, input to Lambda Triggers
            assertNotNull(requestSent.getClientMetadata());
            assertEquals(2, requestSent.getClientMetadata().size());
            // Extract the arguments passed to the RespondToAuthChallenge API call
            ArgumentCaptor<RespondToAuthChallengeRequest> argumentCaptorA = ArgumentCaptor.forClass(RespondToAuthChallengeRequest.class);
            verify(mockCSIClient).respondToAuthChallenge(argumentCaptorA.capture());
            RespondToAuthChallengeRequest requestSentA = argumentCaptorA.getValue();
            // Verify the arguments passed in the API call
            assertNotNull(requestSentA);
            assertEquals(TEST_CLIENT_ID, requestSentA.getClientId());
            assertEquals("PASSWORD_VERIFIER", requestSentA.getChallengeName());
            assertNotNull(requestSentA.getSession());
            assertNotNull(requestSentA.getChallengeResponses());
            // Verify if we have a valid session
            assertNotNull(session);
            assertTrue(session.isValid());
            // Verify that the device is null
            assertNull(device);
            tracker.setNext("end");
        }

        @Override
        public void getAuthenticationDetails(AuthenticationContinuation continuation, String username) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("getAuthenticationDetails"));
            // Check parameters
            assertNotNull(continuation);
            assertNotNull(continuation.getParameters());
            // Continue with authentication details
            Map<String, String> TEST_IN_VALIDATION_DATA = new HashMap<String, String>();
            TEST_IN_VALIDATION_DATA.put("DummyAttribute_1", "Value4DummyAttribute_1");
            TEST_IN_VALIDATION_DATA.put("DummyAttribute_2", "Value4DummyAttribute_2");
            AuthenticationDetails authDetails = new AuthenticationDetails(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_VALIDATION_DATA);
            tracker.setNext("onSuccess");
            continuation.setAuthenticationDetails(authDetails);
            // Set challenge response for valid
            doReturn(TEST_VALID_INITIATE_USER_SRP_AUTH_RESPONSE).when(mockCSIClient).initiateAuth(any(InitiateAuthRequest.class));
            doReturn(TEST_VALID_SUCCESSFUL_AUTH_RESPONSE).when(mockCSIClient).respondToAuthChallenge(any(RespondToAuthChallengeRequest.class));
            continuation.continueTask();
        }

        @Override
        public void getMFACode(MultiFactorAuthenticationContinuation continuation) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("getMFACode"));
        }

        @Override
        public void onFailure(Exception exception) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("onFailure"));
        }

        @Override
        public void authenticationChallenge(ChallengeContinuation continuation) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("authenticationChallenge"));
        }
    });
}
Also used : InitiateAuthRequest(com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthRequest) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) AuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation) RespondToAuthChallengeRequest(com.amazonaws.services.cognitoidentityprovider.model.RespondToAuthChallengeRequest) ChallengeContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) FlowTracker(com.amazonaws.mobileconnectors.cognitoidentityprovider.utils.FlowTracker) CognitoUserSession(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession) HashMap(java.util.HashMap) Map(java.util.Map) AuthenticationDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with FlowTracker

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

the class CognitoIdentityProviderSignInUserTest method getSessionInBackgroundThreadNoCachedTokensNoMFA.

// Authenticate user with user password verifier in background thread
// Failing due to Mockito error
@Ignore
@Test
public void getSessionInBackgroundThreadNoCachedTokensNoMFA() throws Exception {
    assertNotNull(testUser.getUserId());
    // Test with a user cached in shared preferences, with no cached tokens
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + ".LastAuthUser", TEST_USER_NAME);
    // Set mock returns for Authentication API Calls
    // API call to start forgot-password flow
    doReturn(TEST_VALID_INITIATE_USER_SRP_AUTH_RESPONSE).when(mockCSIClient).initiateAuth(any(InitiateAuthRequest.class));
    // Tracker to validate the callback sequence -> callback.getAuthenticationDetails() -> onSuccess()
    final FlowTracker tracker = new FlowTracker("getAuthenticationDetails");
    System.out.println("Get session");
    testUser.getSessionInBackground(new AuthenticationHandler() {

        @Override
        public void onSuccess(CognitoUserSession session, CognitoDevice device) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("onSuccess"));
            // Extract the arguments passed to the initiateAuth API call
            ArgumentCaptor<InitiateAuthRequest> argumentCaptor = ArgumentCaptor.forClass(InitiateAuthRequest.class);
            verify(mockCSIClient).initiateAuth(argumentCaptor.capture());
            InitiateAuthRequest requestSent = argumentCaptor.getValue();
            // Verify the arguments passed in the API call
            assertNotNull(requestSent);
            assertEquals(TEST_CLIENT_ID, requestSent.getClientId());
            assertEquals("USER_SRP_AUTH", requestSent.getAuthFlow());
            // Check authentication parameters
            assertNotNull(requestSent.getAuthParameters());
            assertNotNull(requestSent.getAuthParameters().get("SRP_A"));
            assertNotNull(requestSent.getAuthParameters().get("SECRET_HASH"));
            assertNotNull(requestSent.getAuthParameters().get("USERNAME"));
            assertNotNull(requestSent.getAuthParameters().get("SRP_A"));
            // Check Validation parameters, input to Lambda Triggers
            assertNotNull(requestSent.getClientMetadata());
            assertEquals(2, requestSent.getClientMetadata().size());
            // Extract the arguments passed to the RespondToAuthChallenge API call
            ArgumentCaptor<RespondToAuthChallengeRequest> argumentCaptorA = ArgumentCaptor.forClass(RespondToAuthChallengeRequest.class);
            verify(mockCSIClient).respondToAuthChallenge(argumentCaptorA.capture());
            RespondToAuthChallengeRequest requestSentA = argumentCaptorA.getValue();
            // Verify the arguments passed in the API call
            assertNotNull(requestSentA);
            assertEquals(TEST_CLIENT_ID, requestSentA.getClientId());
            assertEquals("PASSWORD_VERIFIER", requestSentA.getChallengeName());
            assertNotNull(requestSentA.getSession());
            assertNotNull(requestSentA.getChallengeResponses());
            // Verify if we have a valid session
            assertNotNull(session);
            assertTrue(session.isValid());
            // Verify that the device is null
            assertNull(device);
            tracker.setNext("end");
        }

        @Override
        public void getAuthenticationDetails(AuthenticationContinuation continuation, String username) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("getAuthenticationDetails"));
            // Check parameters
            assertNotNull(continuation);
            assertNotNull(continuation.getParameters());
            // Continue with authentication details
            Map<String, String> TEST_IN_VALIDATION_DATA = new HashMap<String, String>();
            TEST_IN_VALIDATION_DATA.put("DummyAttribute_1", "Value4DummyAttribute_1");
            TEST_IN_VALIDATION_DATA.put("DummyAttribute_2", "Value4DummyAttribute_2");
            AuthenticationDetails authDetails = new AuthenticationDetails(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_VALIDATION_DATA);
            tracker.setNext("onSuccess");
            continuation.setAuthenticationDetails(authDetails);
            // Set challenge response for valid
            doReturn(TEST_VALID_INITIATE_USER_SRP_AUTH_RESPONSE).when(mockCSIClient).initiateAuth(any(InitiateAuthRequest.class));
            doReturn(TEST_VALID_SUCCESSFUL_AUTH_RESPONSE).when(mockCSIClient).respondToAuthChallenge(any(RespondToAuthChallengeRequest.class));
            continuation.continueTask();
        }

        @Override
        public void getMFACode(MultiFactorAuthenticationContinuation continuation) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("getMFACode"));
        }

        @Override
        public void onFailure(Exception exception) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("onFailure"));
        }

        @Override
        public void authenticationChallenge(ChallengeContinuation continuation) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("authenticationChallenge"));
        }
    });
}
Also used : InitiateAuthRequest(com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthRequest) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) AuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation) RespondToAuthChallengeRequest(com.amazonaws.services.cognitoidentityprovider.model.RespondToAuthChallengeRequest) ChallengeContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) FlowTracker(com.amazonaws.mobileconnectors.cognitoidentityprovider.utils.FlowTracker) CognitoUserSession(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession) HashMap(java.util.HashMap) Map(java.util.Map) AuthenticationDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with FlowTracker

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

the class CognitoIdentityProviderSignInUserTest method getSessionWithUserPasswordInCurrentThreadNoCachedTokensNoMFA.

// Authenticate user with user password auth in current thread
// Failing due to Mockito error
@Ignore
@Test
public void getSessionWithUserPasswordInCurrentThreadNoCachedTokensNoMFA() throws Exception {
    testUser = testPool.getUser(TEST_USER_NAME);
    assertNotNull(testUser.getUserId());
    // Test with a user cached in shared preferences, with no cached tokens
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + ".LastAuthUser", TEST_USER_NAME);
    // Set mock returns for Authentication API Calls
    // API call to start forgot-password flow
    doReturn(TEST_VALID_INITIATE_USER_SRP_AUTH_RESPONSE).when(mockCSIClient).initiateAuth(any(InitiateAuthRequest.class));
    // Tracker to validate the callback sequence -> callback.getAuthenticationDetails() -> onSuccess()
    final FlowTracker tracker = new FlowTracker("getAuthenticationDetails");
    System.out.println("Get session");
    testUser.getSession(new AuthenticationHandler() {

        @Override
        public void onSuccess(CognitoUserSession session, CognitoDevice device) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("onSuccess"));
            // Extract the arguments passed to the initiateAuth API call
            ArgumentCaptor<InitiateAuthRequest> argumentCaptor = ArgumentCaptor.forClass(InitiateAuthRequest.class);
            verify(mockCSIClient).initiateAuth(argumentCaptor.capture());
            InitiateAuthRequest requestSent = argumentCaptor.getValue();
            // Verify the arguments passed in the API call
            assertNotNull(requestSent);
            assertEquals(TEST_CLIENT_ID, requestSent.getClientId());
            assertEquals("USER_PASSWORD_AUTH", requestSent.getAuthFlow());
            // Check authentication parameters - username and password.
            assertNotNull(requestSent.getAuthParameters().get("USERNAME"));
            assertNotNull(requestSent.getAuthParameters().get("PASSWORD"));
            // Verify if we have a valid session
            assertNotNull(session);
            assertTrue(session.isValid());
            // Verify that the device is null
            assertNull(device);
            tracker.setNext("end");
        }

        @Override
        public void getAuthenticationDetails(AuthenticationContinuation continuation, String username) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("getAuthenticationDetails"));
            // Check parameters
            assertNotNull(continuation);
            assertNotNull(continuation.getParameters());
            // Continue with authentication details
            Map<String, String> TEST_IN_VALIDATION_DATA = new HashMap<String, String>();
            TEST_IN_VALIDATION_DATA.put("DummyAttribute_1", "Value4DummyAttribute_1");
            TEST_IN_VALIDATION_DATA.put("DummyAttribute_2", "Value4DummyAttribute_2");
            AuthenticationDetails authDetails = new AuthenticationDetails(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_VALIDATION_DATA);
            authDetails.setAuthenticationType(TEST_USER_PASSWORD_AUTH_TYPE);
            tracker.setNext("onSuccess");
            continuation.setAuthenticationDetails(authDetails);
            // Set challenge response for valid
            doReturn(TEST_VALID_INITIATE_USER_PASSWORD_AUTH_RESPONSE).when(mockCSIClient).initiateAuth(any(InitiateAuthRequest.class));
            doReturn(TEST_VALID_SUCCESSFUL_AUTH_RESPONSE).when(mockCSIClient).respondToAuthChallenge(any(RespondToAuthChallengeRequest.class));
            continuation.continueTask();
        }

        @Override
        public void getMFACode(MultiFactorAuthenticationContinuation continuation) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("getMFACode"));
        }

        @Override
        public void onFailure(Exception exception) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("onFailure"));
        }

        @Override
        public void authenticationChallenge(ChallengeContinuation continuation) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("authenticationChallenge"));
        }
    });
}
Also used : InitiateAuthRequest(com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthRequest) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) AuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation) ChallengeContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) FlowTracker(com.amazonaws.mobileconnectors.cognitoidentityprovider.utils.FlowTracker) CognitoUserSession(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession) HashMap(java.util.HashMap) Map(java.util.Map) AuthenticationDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with FlowTracker

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

the class CognitoIdentityProviderSignInUserTest method getSessionWithUserPasswordInBackgroundThreadNoCachedTokensNoMFA.

// Authenticate user with user password auth in current thread
// Failing due to Mockito error
@Ignore
@Test
public void getSessionWithUserPasswordInBackgroundThreadNoCachedTokensNoMFA() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    assertNotNull(testUser.getUserId());
    // Test with a user cached in shared preferences, with no cached tokens
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + ".LastAuthUser", TEST_USER_NAME);
    // Set mock returns for Authentication API Calls
    // API call to start forgot-password flow
    doReturn(TEST_VALID_INITIATE_USER_SRP_AUTH_RESPONSE).when(mockCSIClient).initiateAuth(any(InitiateAuthRequest.class));
    // Tracker to validate the callback sequence -> callback.getAuthenticationDetails() -> onSuccess()
    final FlowTracker tracker = new FlowTracker("getAuthenticationDetails");
    System.out.println("Get session");
    testUser.getSessionInBackground(new AuthenticationHandler() {

        @Override
        public void onSuccess(CognitoUserSession session, CognitoDevice device) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("onSuccess"));
            // Extract the arguments passed to the initiateAuth API call
            ArgumentCaptor<InitiateAuthRequest> argumentCaptor = ArgumentCaptor.forClass(InitiateAuthRequest.class);
            verify(mockCSIClient).initiateAuth(argumentCaptor.capture());
            InitiateAuthRequest requestSent = argumentCaptor.getValue();
            // Verify the arguments passed in the API call
            assertNotNull(requestSent);
            assertEquals(TEST_CLIENT_ID, requestSent.getClientId());
            assertEquals("USER_PASSWORD_AUTH", requestSent.getAuthFlow());
            // Check authentication parameters - username and password.
            assertNotNull(requestSent.getAuthParameters().get("USERNAME"));
            assertNotNull(requestSent.getAuthParameters().get("PASSWORD"));
            // Verify if we have a valid session
            assertNotNull(session);
            assertTrue(session.isValid());
            // Verify that the device is null
            assertNull(device);
            tracker.setNext("end");
        }

        @Override
        public void getAuthenticationDetails(AuthenticationContinuation continuation, String username) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("getAuthenticationDetails"));
            // Check parameters
            assertNotNull(continuation);
            assertNotNull(continuation.getParameters());
            // Continue with authentication details
            Map<String, String> TEST_IN_VALIDATION_DATA = new HashMap<String, String>();
            TEST_IN_VALIDATION_DATA.put("DummyAttribute_1", "Value4DummyAttribute_1");
            TEST_IN_VALIDATION_DATA.put("DummyAttribute_2", "Value4DummyAttribute_2");
            AuthenticationDetails authDetails = new AuthenticationDetails(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_VALIDATION_DATA);
            authDetails.setAuthenticationType(TEST_USER_PASSWORD_AUTH_TYPE);
            tracker.setNext("onSuccess");
            continuation.setAuthenticationDetails(authDetails);
            // Set challenge response for valid
            doReturn(TEST_VALID_INITIATE_USER_PASSWORD_AUTH_RESPONSE).when(mockCSIClient).initiateAuth(any(InitiateAuthRequest.class));
            doReturn(TEST_VALID_SUCCESSFUL_AUTH_RESPONSE).when(mockCSIClient).respondToAuthChallenge(any(RespondToAuthChallengeRequest.class));
            continuation.continueTask();
        }

        @Override
        public void getMFACode(MultiFactorAuthenticationContinuation continuation) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("getMFACode"));
        }

        @Override
        public void onFailure(Exception exception) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("onFailure"));
        }

        @Override
        public void authenticationChallenge(ChallengeContinuation continuation) {
            // Check if this method was called out of sequence
            assertTrue(tracker.check("authenticationChallenge"));
        }
    });
}
Also used : InitiateAuthRequest(com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthRequest) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) AuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation) ChallengeContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) FlowTracker(com.amazonaws.mobileconnectors.cognitoidentityprovider.utils.FlowTracker) CognitoUserSession(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession) HashMap(java.util.HashMap) Map(java.util.Map) AuthenticationDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with FlowTracker

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

the class CognitoIdentityProviderChangePasswordInstrumentedTest method changePasswordInBackgroundWithExpiredCachedTokensException.

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