use of com.aliyun.oss.common.auth.InstanceProfileCredentials in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsFetcherTest method testFetchNormalCredentials.
@Test
public void testFetchNormalCredentials() {
try {
InstanceProfileCredentialsFetcherMock credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.Normal);
InstanceProfileCredentials credentials = (InstanceProfileCredentials) credentialsFetcher.fetch(3);
Assert.assertEquals(credentials.getAccessKeyId().length(), 29);
Assert.assertEquals(credentials.getSecretAccessKey().length(), 44);
Assert.assertEquals(credentials.getSecurityToken().length(), 536);
Assert.assertTrue(credentials.useSecurityToken());
Assert.assertFalse(credentials.willSoonExpire());
credentials = (InstanceProfileCredentials) credentialsFetcher.fetch();
Assert.assertEquals(credentials.getAccessKeyId().length(), 29);
Assert.assertEquals(credentials.getSecretAccessKey().length(), 44);
Assert.assertEquals(credentials.getSecurityToken().length(), 536);
Assert.assertTrue(credentials.useSecurityToken());
Assert.assertFalse(credentials.willSoonExpire());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.InstanceProfileCredentials in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsTest method testExpiredFactor.
@Test
public void testExpiredFactor() {
try {
InstanceProfileCredentials credentials = new InstanceProfileCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, null, "2010-11-11T11:11:11Z").withExpiredFactor(10.0);
Thread.sleep(1000);
Assert.assertTrue(credentials.willSoonExpire());
credentials = new InstanceProfileCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, null, "2020-11-11T11:11:11Z").withExpiredFactor(0.8);
Thread.sleep(1000);
Assert.assertFalse(credentials.willSoonExpire());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.InstanceProfileCredentials in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsTest method testWillSoonExpire.
@Test
public void testWillSoonExpire() {
try {
InstanceProfileCredentials credentials = new InstanceProfileCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, null, "2016-11-11T11:11:11Z");
Assert.assertTrue(credentials.willSoonExpire());
Assert.assertTrue(credentials.isExpired());
Assert.assertTrue(credentials.shouldRefresh());
credentials = new InstanceProfileCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, null, "2020-11-11T11:11:11Z");
Assert.assertFalse(credentials.willSoonExpire());
Assert.assertFalse(credentials.isExpired());
Assert.assertTrue(credentials.shouldRefresh());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.InstanceProfileCredentials in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsTest method testBasicTest.
@Test
public void testBasicTest() {
try {
InstanceProfileCredentials credentials = new InstanceProfileCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, null, "2017-11-03T05:10:02Z");
Assert.assertEquals(credentials.getAccessKeyId(), ACCESS_KEY_ID);
Assert.assertEquals(credentials.getSecretAccessKey(), ACCESS_KEY_SECRET);
Assert.assertEquals(credentials.getSecurityToken(), null);
Assert.assertFalse(credentials.useSecurityToken());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.InstanceProfileCredentials in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsProviderTest method testGetCredentialsOnEcs.
/**
* NOTE: Run this case on ecs.
*/
@Ignore
public void testGetCredentialsOnEcs() {
try {
// TODO: Establish a simulated ECS metadata service
InstanceProfileCredentialsProvider credentialsProvider = new InstanceProfileCredentialsProvider(TestConfig.ECS_ROLE_NAME);
InstanceProfileCredentials credentials = credentialsProvider.getCredentials();
Assert.assertEquals(credentials.getAccessKeyId().length(), 29);
Assert.assertEquals(credentials.getSecretAccessKey().length(), 44);
Assert.assertEquals(credentials.getSecurityToken().length(), 536);
Assert.assertTrue(credentials.useSecurityToken());
Assert.assertFalse(credentials.willSoonExpire());
Assert.assertFalse(credentials.isExpired());
Assert.assertTrue(credentials.shouldRefresh());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations