Search in sources :

Example 16 with CognitoCachingCredentialsProvider

use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.

the class CognitoCachingCredentialsProviderIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    sharedPreferencesForAuth.edit().clear().commit();
    AWSKeyValueStore.cacheFactory.clear();
    credentialsProviders = new ArrayList<CognitoCachingCredentialsProvider>();
    credentialsProvider = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
    credentialsProviders.add(credentialsProvider);
}
Also used : CognitoCachingCredentialsProvider(com.amazonaws.auth.CognitoCachingCredentialsProvider) Before(org.junit.Before)

Example 17 with CognitoCachingCredentialsProvider

use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.

the class CognitoCachingCredentialsProviderIntegrationTest method testEncryptionKeyLossInGetIdentityId_WhileAppIsClosed.

@Test
public void testEncryptionKeyLossInGetIdentityId_WhileAppIsClosed() throws Exception {
    // Makes a network call to get credentials and saves it to local persistence store
    String identityIdFromNetwork = credentialsProvider.getIdentityId();
    assertNotNull(identityIdFromNetwork);
    String identityIdFromCache = credentialsProvider.getCachedIdentityId();
    assertNotNull(identityIdFromCache);
    assertEquals(identityIdFromNetwork, identityIdFromCache);
    deleteAllEncryptionKeys();
    CognitoCachingCredentialsProvider newCredentialsProvider = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
    identityIdFromCache = newCredentialsProvider.getCachedIdentityId();
    assertNull(identityIdFromCache);
    identityIdFromNetwork = newCredentialsProvider.getIdentityId();
    assertNotNull(identityIdFromNetwork);
    identityIdFromCache = newCredentialsProvider.getCachedIdentityId();
    assertNotNull(identityIdFromCache);
    assertEquals(identityIdFromNetwork, identityIdFromCache);
}
Also used : CognitoCachingCredentialsProvider(com.amazonaws.auth.CognitoCachingCredentialsProvider) Test(org.junit.Test)

Example 18 with CognitoCachingCredentialsProvider

use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.

the class CognitoCachingCredentialsProviderIntegrationTest method testCachedAWSCredentialsPersistence.

@Test
public void testCachedAWSCredentialsPersistence() throws Exception {
    Log.d(TAG, "SharedPreferences keys for com.amazonaws.android.auth => " + sharedPreferencesForAuth.getAll().toString());
    assertNull(credentialsProvider.getCachedIdentityId());
    credentialsProvider.clearCredentials();
    credentialsProvider.clear();
    assertNull(credentialsProvider.getCachedIdentityId());
    assertNotNull(credentialsProvider.getCredentials());
    assertNotNull(credentialsProvider.getIdentityId());
    assertNotNull(credentialsProvider.getCachedIdentityId());
    assertEquals(credentialsProvider.getIdentityId(), credentialsProvider.getCachedIdentityId());
    verifySharedPreferencesContents();
    // Now create a new credentials provider with the same identity pool id
    CognitoCachingCredentialsProvider persistenceCredentialsProvider = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
    credentialsProviders.add(persistenceCredentialsProvider);
    Log.d(TAG, "Persistence check: SharedPreferences keys for com.amazonaws.android.auth => " + sharedPreferencesForAuth.getAll().toString());
    assertNotNull(persistenceCredentialsProvider.getCachedIdentityId());
    persistenceCredentialsProvider.clearCredentials();
    persistenceCredentialsProvider.clear();
    assertNull(persistenceCredentialsProvider.getCachedIdentityId());
    assertNotNull(persistenceCredentialsProvider.getCredentials());
    Log.d(TAG, "Credentials = " + persistenceCredentialsProvider.getCredentials());
    assertNotNull(persistenceCredentialsProvider.getIdentityId());
    Log.d(TAG, "Identity Id = " + persistenceCredentialsProvider.getIdentityId());
    assertNotNull(persistenceCredentialsProvider.getCachedIdentityId());
    Log.d(TAG, "Cached Identity Id = " + persistenceCredentialsProvider.getCachedIdentityId());
    assertEquals(persistenceCredentialsProvider.getIdentityId(), persistenceCredentialsProvider.getCachedIdentityId());
    verifySharedPreferencesContents();
    verifyCredentialsProviderClear();
}
Also used : CognitoCachingCredentialsProvider(com.amazonaws.auth.CognitoCachingCredentialsProvider) Test(org.junit.Test)

Example 19 with CognitoCachingCredentialsProvider

use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.

the class CognitoCachingCredentialsProviderIntegrationTest method testMultipleCognitoCachingCredentialsProviders.

@Test
public void testMultipleCognitoCachingCredentialsProviders() throws Exception {
    CognitoCachingCredentialsProvider credentialsProvider1 = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("other_identity_pool_id"), Regions.US_EAST_1);
    credentialsProviders.add(credentialsProvider1);
    for (CognitoCachingCredentialsProvider cccp : credentialsProviders) {
        assertNull(cccp.getCachedIdentityId());
        cccp.clearCredentials();
        cccp.clear();
        assertNull(cccp.getCachedIdentityId());
    }
    for (CognitoCachingCredentialsProvider cccp : credentialsProviders) {
        assertNotNull(cccp.getCredentials());
        Log.d(TAG, "Credentials = " + cccp.getCredentials());
    }
    for (CognitoCachingCredentialsProvider cccp : credentialsProviders) {
        assertNotNull(cccp.getIdentityId());
        Log.d(TAG, "Identity Id = " + cccp.getIdentityId());
        assertNotNull(cccp.getCachedIdentityId());
        Log.d(TAG, "Cached Identity Id = " + cccp.getCachedIdentityId());
        assertEquals(cccp.getIdentityId(), cccp.getCachedIdentityId());
    }
    verifySharedPreferencesContents();
    verifyCredentialsProviderClear();
}
Also used : CognitoCachingCredentialsProvider(com.amazonaws.auth.CognitoCachingCredentialsProvider) Test(org.junit.Test)

Example 20 with CognitoCachingCredentialsProvider

use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.

the class CognitoCachingCredentialsProviderIntegrationTest method testMultipleCognitoCachingCredentialsProvidersWithRefresh.

@Test
public void testMultipleCognitoCachingCredentialsProvidersWithRefresh() throws Exception {
    CognitoCachingCredentialsProvider credentialsProvider1 = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("other_identity_pool_id"), Regions.US_EAST_1);
    credentialsProvider1.setPersistenceEnabled(false);
    credentialsProviders.add(credentialsProvider1);
    for (CognitoCachingCredentialsProvider cccp : credentialsProviders) {
        cccp.setPersistenceEnabled(false);
        assertNull(cccp.getCachedIdentityId());
        cccp.clearCredentials();
        cccp.clear();
        assertNull(cccp.getCachedIdentityId());
        final AWSSessionCredentials credentialsBeforeRefresh = cccp.getCredentials();
        assertNotNull(credentialsBeforeRefresh);
        Log.d(TAG, "Before Refresh: Credentials = " + credentialsBeforeRefresh);
        final String identityIdBeforeRefresh = cccp.getIdentityId();
        assertNotNull(identityIdBeforeRefresh);
        Log.d(TAG, "Before Refresh: Identity Id = " + identityIdBeforeRefresh);
        final String cachedIdentityIdBeforeRefresh = cccp.getCachedIdentityId();
        assertNotNull(cachedIdentityIdBeforeRefresh);
        Log.d(TAG, "Before Refresh: Cached Identity Id = " + cachedIdentityIdBeforeRefresh);
        assertEquals(identityIdBeforeRefresh, cachedIdentityIdBeforeRefresh);
        // Refresh
        cccp.refresh();
        final AWSSessionCredentials credentialsAfterRefresh = cccp.getCredentials();
        assertNotNull(credentialsAfterRefresh);
        Log.d(TAG, "After Refresh: Credentials = " + credentialsAfterRefresh);
        assertNotEquals(credentialsAfterRefresh.getSessionToken(), credentialsBeforeRefresh.getSessionToken());
        assertNotEquals(credentialsAfterRefresh.getAWSSecretKey(), credentialsBeforeRefresh.getAWSSecretKey());
        assertNotEquals(credentialsAfterRefresh.getAWSAccessKeyId(), credentialsBeforeRefresh.getAWSAccessKeyId());
        final String identityIdAfterRefresh = cccp.getIdentityId();
        assertNotNull(identityIdAfterRefresh);
        Log.d(TAG, "After Refresh: Identity Id = " + identityIdAfterRefresh);
        assertEquals(identityIdAfterRefresh, identityIdBeforeRefresh);
        final String cachedIdentityIdAfterRefresh = cccp.getCachedIdentityId();
        assertNotNull(cachedIdentityIdAfterRefresh);
        Log.d(TAG, "After Refresh: Cached Identity Id = " + cachedIdentityIdAfterRefresh);
        assertEquals(cachedIdentityIdAfterRefresh, cachedIdentityIdBeforeRefresh);
        assertEquals(identityIdAfterRefresh, cachedIdentityIdAfterRefresh);
    }
}
Also used : AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) CognitoCachingCredentialsProvider(com.amazonaws.auth.CognitoCachingCredentialsProvider) Test(org.junit.Test)

Aggregations

CognitoCachingCredentialsProvider (com.amazonaws.auth.CognitoCachingCredentialsProvider)23 Test (org.junit.Test)10 JSONObject (org.json.JSONObject)5 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)4 Regions (com.amazonaws.regions.Regions)3 Before (org.junit.Before)3 PinpointConfiguration (com.amazonaws.mobileconnectors.pinpoint.PinpointConfiguration)2 PinpointManager (com.amazonaws.mobileconnectors.pinpoint.PinpointManager)2 JSONException (org.json.JSONException)2 Context (android.content.Context)1 CustomTabsCallback (androidx.browser.customtabs.CustomTabsCallback)1 AmazonClientException (com.amazonaws.AmazonClientException)1 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AWSAbstractCognitoIdentityProvider (com.amazonaws.auth.AWSAbstractCognitoIdentityProvider)1 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)1 IdentityManager (com.amazonaws.mobile.auth.core.IdentityManager)1 SignInStateChangeListener (com.amazonaws.mobile.auth.core.SignInStateChangeListener)1 InternalCallback (com.amazonaws.mobile.client.internal.InternalCallback)1 ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)1 OAuth2Client (com.amazonaws.mobile.client.internal.oauth2.OAuth2Client)1