use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.
the class CognitoCachingCredentialsProviderIntegrationTest method testEncryptionKeyLossInAWSCredentials_WhileAppIsInClosed.
@Test
public void testEncryptionKeyLossInAWSCredentials_WhileAppIsInClosed() throws Exception {
// Makes a network call to get credentials and saves it to local persistence store
AWSSessionCredentials awsSessionCredentialsFromNetwork = credentialsProvider.getCredentials();
verifyAWSCredentials(awsSessionCredentialsFromNetwork);
AWSSessionCredentials awsSessionCredentialsFromCache = credentialsProvider.getCredentials();
verifyAWSCredentials(awsSessionCredentialsFromCache);
assertTrue(compareAWSSessionCredentials(awsSessionCredentialsFromNetwork, awsSessionCredentialsFromCache));
deleteAllEncryptionKeys();
CognitoCachingCredentialsProvider newCredentialsProvider = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
awsSessionCredentialsFromNetwork = newCredentialsProvider.getCredentials();
verifyAWSCredentials(awsSessionCredentialsFromNetwork);
awsSessionCredentialsFromCache = newCredentialsProvider.getCredentials();
verifyAWSCredentials(awsSessionCredentialsFromCache);
assertTrue(compareAWSSessionCredentials(awsSessionCredentialsFromNetwork, awsSessionCredentialsFromCache));
}
use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.
the class AWSKeyValueStoreMigrationIntegrationTest method verifyCredentialsProviderClear.
private void verifyCredentialsProviderClear() {
for (int iterator = 0; iterator < credentialsProviders.size(); iterator++) {
final CognitoCachingCredentialsProvider cccp = credentialsProviders.get(iterator);
cccp.clearCredentials();
cccp.clear();
assertNull(cccp.getCachedIdentityId());
assertNotNull(cccp.getIdentityId());
assertNotNull(cccp.getCachedIdentityId());
}
}
use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.
the class AWSKeyValueStoreMigrationIntegrationTest method testCachedAWSCredentialsMigrationFromNoEncryption.
@Test
public void testCachedAWSCredentialsMigrationFromNoEncryption() throws Exception {
Log.d(TAG, "SharedPreferences contents before migration for " + SHARED_PREFERENCES_NAME + "=> " + sharedPreferencesForAuth.getAll().toString());
assertEquals("accessKey", sharedPreferencesForAuth.getString(identityPoolId + ".accessKey", null));
assertEquals("secretKey", sharedPreferencesForAuth.getString(identityPoolId + ".secretKey", null));
assertEquals("sessionToken", sharedPreferencesForAuth.getString(identityPoolId + ".sessionToken", null));
assertEquals("identityId", sharedPreferencesForAuth.getString(identityPoolId + ".identityId", null));
assertEquals(time, sharedPreferencesForAuth.getLong(identityPoolId + ".expirationDate", 0));
assertEquals(stringSet, sharedPreferencesForAuth.getStringSet("stringSet", null));
credentialsProvider = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
credentialsProviders.add(credentialsProvider);
AWSKeyValueStore awsKeyValueStore = new AWSKeyValueStore(ApplicationProvider.getApplicationContext(), SHARED_PREFERENCES_NAME, true);
assertNotNull(awsKeyValueStore);
Log.d(TAG, "SharedPreferences contents after migration for " + SHARED_PREFERENCES_NAME + " => " + sharedPreferencesForAuth.getAll().toString());
assertEquals("accessKey", awsKeyValueStore.get(identityPoolId + ".accessKey"));
assertEquals("secretKey", awsKeyValueStore.get(identityPoolId + ".secretKey"));
assertEquals("sessionToken", awsKeyValueStore.get(identityPoolId + ".sessionToken"));
assertEquals("identityId", awsKeyValueStore.get(identityPoolId + ".identityId"));
assertEquals(String.valueOf(time), awsKeyValueStore.get(identityPoolId + ".expirationDate"));
assertNotNull(awsKeyValueStore.get("stringSet"));
verifyStringSet();
credentialsProvider.clearCredentials();
credentialsProvider.clear();
assertNull(credentialsProvider.getCachedIdentityId());
assertNotNull(credentialsProvider.getCredentials());
assertNotNull(credentialsProvider.getIdentityId());
assertNotNull(credentialsProvider.getCachedIdentityId());
assertEquals(credentialsProvider.getIdentityId(), credentialsProvider.getCachedIdentityId());
verifySharedPreferencesContents();
verifyCredentialsProviderClear();
}
use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.
the class AWSKeyValueStoreNoCachingIntegrationTest 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);
credentialsProvider.setPersistenceEnabled(false);
credentialsProviders.add(credentialsProvider);
}
use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.
the class MqttManagerIntegrationTest method beforeSuite.
@BeforeClass
public static void beforeSuite() throws JSONException {
Context appContext = ApplicationProvider.getApplicationContext();
keyStorePath = appContext.getFilesDir().toString() + "/";
System.out.println(keyStorePath);
credentialsProvider = new CognitoCachingCredentialsProvider(appContext, getPackageConfigure("iot").getString(ConfigKey.IDENTITY_POOL_ID.toString()), Regions.US_EAST_1);
iotClient = new IotClient(credentialsProvider);
iotClient.cleanupPolicy(IOT_POLICY_NAME);
keysAndCertificateInfo = iotClient.createAndAttachPolicy(IOT_POLICY_NAME, new JSONObject().put("Version", "2012-10-17").put("Statement", new JSONArray(Collections.singletonList(new JSONObject().put("Action", "iot:*").put("Resource", "*").put("Effect", "Allow")))).toString());
customAuthorization = CustomAuthorization.from(getPackageConfigure("iot"), keysAndCertificateInfo);
iotClient.cleanupAuthorizer(customAuthorization.getCustomAuthorizerName());
iotClient.createAuthorizer(customAuthorization.getCustomAuthorizerName(), customAuthorization.getCustomAuthorizerLamdbaArn(), customAuthorization.getTokenKeyName(), keysAndCertificateInfo.getPublicKey());
}
Aggregations