Search in sources :

Example 6 with CognitoDevice

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

the class CognitoIdentityProviderDevicesTest method forgetDeviceInCurrentThread.

@Test
public void forgetDeviceInCurrentThread() {
    CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Store tokens in shared preferences
    final String testAccessToken = getValidJWT(3600L);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
    // Set mock result for the change password request API call
    doNothing().when(mockCSIClient).forgetDevice(any(ForgetDeviceRequest.class));
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    CognitoDevice cachedDevice = testUser.thisDevice();
    cachedDevice.forgetDevice(new GenericHandler() {

        @Override
        public void onSuccess() {
            ArgumentCaptor<ForgetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(ForgetDeviceRequest.class);
            verify(mockCSIClient).forgetDevice(argumentCaptor.capture());
            ForgetDeviceRequest requestSent = argumentCaptor.getValue();
            Log.d(TAG, "testAccessToken = " + testAccessToken);
            Log.d(TAG, "requestSent.getAccessToken() = " + requestSent.getAccessToken());
            assertEquals(testAccessToken, requestSent.getAccessToken());
            countDownLatch.countDown();
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) ForgetDeviceRequest(com.amazonaws.services.cognitoidentityprovider.model.ForgetDeviceRequest) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 7 with CognitoDevice

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

the class CognitoIdentityProviderDevicesTest method getDeviceDetailsInCurrentThread.

@Test
public void getDeviceDetailsInCurrentThread() {
    CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Store tokens in shared preferences
    final String testAccessToken = getValidJWT(3600L);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + ".idToken", getValidJWT(3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
    // Set mock result for the change password request API call
    doReturn(TEST_VALID_GET_DEVICE_RESPONSE).when(mockCSIClient).getDevice(any(GetDeviceRequest.class));
    CognitoDevice cachedDevice = testUser.thisDevice();
    cachedDevice.getDevice(new GenericHandler() {

        @Override
        public void onSuccess() {
            ArgumentCaptor<GetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(GetDeviceRequest.class);
            verify(mockCSIClient).getDevice(argumentCaptor.capture());
            GetDeviceRequest requestSent = argumentCaptor.getValue();
            assertEquals(testAccessToken, requestSent.getAccessToken());
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) GetDeviceRequest(com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) Test(org.junit.Test)

Example 8 with CognitoDevice

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

the class CognitoIdentityProviderDevicesTest method listDevicesInBackgroundThread.

@Test
public void listDevicesInBackgroundThread() {
    // Set mock result for the change password request API call
    doReturn(TEST_VALID_LIST_DEVICES_RESPONSE).when(mockCSIClient).listDevices(any(ListDevicesRequest.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);
    testUser.listDevicesInBackground(10, "ptoken", new DevicesHandler() {

        @Override
        public void onSuccess(List<CognitoDevice> devices) {
            assertNotNull(devices);
            ArgumentCaptor<ListDevicesRequest> argumentCaptor = ArgumentCaptor.forClass(ListDevicesRequest.class);
            verify(mockCSIClient).listDevices(argumentCaptor.capture());
            ListDevicesRequest requestSent = argumentCaptor.getValue();
            assertEquals("ptoken", requestSent.getPaginationToken());
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : DevicesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) ListDevicesRequest(com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest) Test(org.junit.Test)

Example 9 with CognitoDevice

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

the class CognitoIdentityProviderDevicesTest method forgetDeviceInBackgroundThread.

@Test
public void forgetDeviceInBackgroundThread() {
    CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Store tokens in shared preferences
    final String testAccessToken = getValidJWT(3600L);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
    // Set mock result for the change password request API call
    doNothing().when(mockCSIClient).forgetDevice(any(ForgetDeviceRequest.class));
    CognitoDevice cachedDevice = testUser.thisDevice();
    cachedDevice.forgetDeviceInBackground(new GenericHandler() {

        @Override
        public void onSuccess() {
            ArgumentCaptor<ForgetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(ForgetDeviceRequest.class);
            verify(mockCSIClient).forgetDevice(argumentCaptor.capture());
            ForgetDeviceRequest requestSent = argumentCaptor.getValue();
            assertEquals(testAccessToken, requestSent.getAccessToken());
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) ForgetDeviceRequest(com.amazonaws.services.cognitoidentityprovider.model.ForgetDeviceRequest) Test(org.junit.Test)

Example 10 with CognitoDevice

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

the class CognitoIdentityProviderDevicesTest method getDevice.

@Test
public void getDevice() {
    CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
    testUser = testPool.getUser(TEST_USER_NAME);
    CognitoDevice cachedDevice = testUser.thisDevice();
    assertNotNull(cachedDevice);
}
Also used : CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) Test(org.junit.Test)

Aggregations

CognitoDevice (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice)22 Test (org.junit.Test)15 ArgumentCaptor (org.mockito.ArgumentCaptor)12 CognitoUserSession (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession)10 AuthenticationContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation)10 ChallengeContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation)10 MultiFactorAuthenticationContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation)10 AuthenticationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler)10 AuthenticationDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails)7 GenericHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler)6 HashMap (java.util.HashMap)6 ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)5 FlowTracker (com.amazonaws.mobileconnectors.cognitoidentityprovider.utils.FlowTracker)4 InitiateAuthRequest (com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthRequest)4 Map (java.util.Map)4 JSONException (org.json.JSONException)4 Ignore (org.junit.Ignore)4 SignInResult (com.amazonaws.mobile.client.results.SignInResult)3 ForgetDeviceRequest (com.amazonaws.services.cognitoidentityprovider.model.ForgetDeviceRequest)3 GetDeviceRequest (com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest)3