use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.
the class EndpointProfileIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
JSONObject testConfig = getPackageConfigure("pinpoint");
String identityPoolId = testConfig.getString("identity_pool_id");
String appId = testConfig.getString("AppId");
Regions regions = Regions.fromName(testConfig.getString("Region"));
getApplicationContext().deleteDatabase("awspinpoint.db");
goOnline();
credentialsProvider = new CognitoCachingCredentialsProvider(getApplicationContext(), identityPoolId, regions);
PinpointConfiguration pinpointConfiguration = new PinpointConfiguration(getApplicationContext(), appId, regions, ChannelType.GCM, credentialsProvider);
pinpointManager = new PinpointManager(pinpointConfiguration);
}
use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.
the class CognitoCachingCredentialsProviderDataCorruptionIntegrationTest method testCachedAWSCredentialsWithKeyNotRetrieved.
// getCredentials() will store the encrypted credentials in SharedPreferences.
// Now delete the key held in Android KeyStore
// getCredentials() now cannot read the content, so it will delete the encrypted
// credentials and go to clean state and fetch credentials from AWS.
@Test
public void testCachedAWSCredentialsWithKeyNotRetrieved() throws Exception {
verifyGetCredentialsAndIdentityId();
verifySharedPreferencesContents();
final String cachedIdentityId = credentialsProvider.getCachedIdentityId();
deleteAllEncryptionKeys();
CognitoCachingCredentialsProvider credentialsProviderAfterKeyDeleted = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
assertNull(credentialsProviderAfterKeyDeleted.getCachedIdentityId());
assertNotNull(credentialsProviderAfterKeyDeleted.getCredentials());
assertNotNull(credentialsProviderAfterKeyDeleted.getIdentityId());
final String cachedIdentityIdAfterKeyDeleted = credentialsProviderAfterKeyDeleted.getCachedIdentityId();
assertNotEquals(cachedIdentityId, cachedIdentityIdAfterKeyDeleted);
}
use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.
the class CognitoCachingCredentialsProviderDataCorruptionIntegrationTest method testCachedAWSCredentialsWithCredentialsExpired.
@Test
public void testCachedAWSCredentialsWithCredentialsExpired() throws Exception {
verifyGetCredentialsAndIdentityId();
verifySharedPreferencesContents();
final AWSSessionCredentials currentCredentials = credentialsProvider.getCredentials();
// modify the expiration date of credentials
sharedPreferencesForAuth.edit().putString(credentialsProvider.getIdentityPoolId() + ".expirationDate.encrypted", "-00000011111").commit();
assertEquals("-00000011111", sharedPreferencesForAuth.getString(credentialsProvider.getIdentityPoolId() + ".expirationDate.encrypted", null));
// getCredentials() now will fetch the SAME credentials from Amazon Cognito by making a network call
// as the credentials are only expired on client locally.
AWSSessionCredentials credentialsFromCredentialsProvider = credentialsProvider.getCredentials();
assertNotNull("getCredentials() with credentials expired locally should fetch new credentials", credentialsFromCredentialsProvider);
assertEquals(currentCredentials.getAWSAccessKeyId(), credentialsFromCredentialsProvider.getAWSAccessKeyId());
assertEquals(currentCredentials.getAWSSecretKey(), credentialsFromCredentialsProvider.getAWSSecretKey());
assertEquals(currentCredentials.getSessionToken(), credentialsFromCredentialsProvider.getSessionToken());
// refresh will get NEW credentials from Amazon Cognito by making a network call
credentialsProvider.refresh();
AWSSessionCredentials credentialsFromCredentialsProviderAfterRefresh = credentialsProvider.getCredentials();
assertNotNull("getCredentials() after refresh should fetch new credentials", credentialsFromCredentialsProviderAfterRefresh);
assertNotEquals(credentialsFromCredentialsProviderAfterRefresh.getAWSAccessKeyId(), credentialsFromCredentialsProvider.getAWSAccessKeyId());
assertNotEquals(credentialsFromCredentialsProviderAfterRefresh.getAWSSecretKey(), credentialsFromCredentialsProvider.getAWSSecretKey());
assertNotEquals(credentialsFromCredentialsProviderAfterRefresh.getSessionToken(), credentialsFromCredentialsProvider.getSessionToken());
// Repeat getCredentials() for an other credentials provider
CognitoCachingCredentialsProvider credentialsProvider1 = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
final AWSSessionCredentials newCredentials = credentialsProvider1.getCredentials();
assertNotNull("getCredentials() with corrupted key should fetch new credentials", newCredentials);
assertNotEquals(currentCredentials.getAWSAccessKeyId(), newCredentials.getAWSAccessKeyId());
assertNotEquals(currentCredentials.getAWSSecretKey(), newCredentials.getAWSSecretKey());
assertNotEquals(currentCredentials.getSessionToken(), newCredentials.getSessionToken());
}
use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.
the class CognitoCachingCredentialsProviderDataCorruptionIntegrationTest method testCachedAWSCredentialsWithCorruptedAccessKey.
@Test
public void testCachedAWSCredentialsWithCorruptedAccessKey() throws Exception {
verifyGetCredentialsAndIdentityId();
verifySharedPreferencesContents();
final AWSSessionCredentials currentCredentials = credentialsProvider.getCredentials();
// make the access key null
sharedPreferencesForAuth.edit().putString(credentialsProvider.getIdentityPoolId() + ".accessKey.encrypted", null).commit();
assertNull(sharedPreferencesForAuth.getString(credentialsProvider.getIdentityPoolId() + ".accessKey.encrypted", null));
// getCredentials() now will fetch the same credentials from AWS Cognito by making a network call
final AWSSessionCredentials credentialsFromCredentialsProvider = credentialsProvider.getCredentials();
assertNotNull("getCredentials() with corrupted data should fetch new credentials", credentialsFromCredentialsProvider);
assertEquals(currentCredentials.getAWSAccessKeyId(), credentialsFromCredentialsProvider.getAWSAccessKeyId());
assertEquals(currentCredentials.getAWSSecretKey(), credentialsFromCredentialsProvider.getAWSSecretKey());
assertEquals(currentCredentials.getSessionToken(), credentialsFromCredentialsProvider.getSessionToken());
// Repeat getCredentials() for an other credentials provider
CognitoCachingCredentialsProvider credentialsProvider1 = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
final AWSSessionCredentials newCredentials = credentialsProvider1.getCredentials();
assertNotNull("getCredentials() with corrupted key should fetch new credentials", newCredentials);
assertNotEquals(currentCredentials.getAWSAccessKeyId(), newCredentials.getAWSAccessKeyId());
assertNotEquals(currentCredentials.getAWSSecretKey(), newCredentials.getAWSSecretKey());
assertNotEquals(currentCredentials.getSessionToken(), newCredentials.getSessionToken());
}
use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.
the class CognitoCachingCredentialsProviderIntegrationTest method verifySharedPreferencesContents.
private void verifySharedPreferencesContents() {
assert sharedPreferencesForAuth.getAll().keySet().size() == credentialsProviders.size() * 5;
Log.d(TAG, "SharedPreferences Keys = " + sharedPreferencesForAuth.getAll().keySet().toString());
for (int iterator = 0; iterator < credentialsProviders.size(); iterator++) {
final CognitoCachingCredentialsProvider cccp = credentialsProviders.get(iterator);
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".accessKey.encrypted", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".secretKey.encrypted", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".sessionToken.encrypted", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".identityId.encrypted", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".expirationDate.encrypted", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".accessKey.encrypted.iv", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".secretKey.encrypted.iv", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".sessionToken.encrypted.iv", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".identityId.encrypted.iv", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".expirationDate.encrypted.iv", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".accessKey.encrypted.keyvaluestoreversion", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".secretKey.encrypted.keyvaluestoreversion", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".sessionToken.encrypted.keyvaluestoreversion", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".identityId.encrypted.keyvaluestoreversion", null));
assertNotNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".expirationDate.encrypted.keyvaluestoreversion", null));
assertNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".accessKey", null));
assertNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".secretKey", null));
assertNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".sessionToken", null));
assertNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".identityId", null));
assertNull(sharedPreferencesForAuth.getString(cccp.getIdentityPoolId() + ".expirationDate", null));
}
}
Aggregations