CloudStore { AWSTemporaryCredentials getCachedCreds(final String cacheKey, Integer durationSeconds) { if (cacheTimeout == 0) { return null; } AWSTemporaryCredentials tempCreds = awsCredsCache.get(cacheKey); if (tempCreds == null) { return null; } long diffSeconds = (tempCreds.getExpiration().millis() - System.currentTimeMillis()) / 1000; if (durationSeconds == null || durationSeconds <= 0) { durationSeconds = 3600; } if (durationSeconds - diffSeconds > cacheTimeout) { return null; } return tempCreds; } CloudStore(); void close(); void setHttpClient(HttpClient client); boolean isAwsEnabled(); AmazonS3 getS3Client(); AWSTemporaryCredentials assumeAWSRole(String account, String roleName, String principal,
                                                 Integer durationSeconds, String externalId); String getCloudAccount(String domainName);  }
@Test public void testGetCachedCreds() { CloudStore cloudStore = new CloudStore(); AWSTemporaryCredentials creds = new AWSTemporaryCredentials(); creds.setAccessKeyId("keyid"); creds.setSecretAccessKey("accesskey"); creds.setSessionToken("token"); creds.setExpiration(Timestamp.fromMillis(System.currentTimeMillis() + 3600*1000)); cloudStore.putCacheCreds("account:role:user::", creds); assertNull(cloudStore.getCachedCreds("account:role:user:100:", null)); assertNull(cloudStore.getCachedCreds("account:role:user::ext", null)); assertNotNull(cloudStore.getCachedCreds("account:role:user::", null)); assertNotNull(cloudStore.getCachedCreds("account:role:user::", 0)); assertNotNull(cloudStore.getCachedCreds("account:role:user::", -1)); assertNotNull(cloudStore.getCachedCreds("account:role:user::", 3600)); assertNotNull(cloudStore.getCachedCreds("account:role:user::", 2700)); assertNotNull(cloudStore.getCachedCreds("account:role:user::", 3900)); assertNull(cloudStore.getCachedCreds("account:role:user::", 4260)); assertNull(cloudStore.getCachedCreds("account:role:user::", 7200)); cloudStore.close(); }