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);
}
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);
}
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();
}
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();
}
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);
}
}
Aggregations