use of com.aliyun.oss.common.provider.mock.InstanceProfileCredentialsFetcherMock 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.provider.mock.InstanceProfileCredentialsFetcherMock in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsFetcherTest method testFetchInvalidCredentials.
@Test
public void testFetchInvalidCredentials() {
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.FormatInvalid);
credentialsFetcher.fetch(3);
Assert.fail("EcsInstanceCredentialsFetcher.fetch should not be successful.");
} catch (ClientException e) {
Assert.assertEquals(FORMAT_ERROR_MESSAGE, e.getMessage());
}
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.FormatInvalid);
credentialsFetcher.fetch();
Assert.fail("EcsInstanceCredentialsFetcher.fetch should not be successful.");
} catch (ClientException e) {
Assert.assertEquals(FORMAT_ERROR_MESSAGE, e.getMessage());
}
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.ServerHalt);
credentialsFetcher.fetch(3);
Assert.fail("EcsInstanceCredentialsFetcher.fetch should not be successful.");
} catch (ClientException e) {
}
}
use of com.aliyun.oss.common.provider.mock.InstanceProfileCredentialsFetcherMock in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsProviderTest method testGetExceptionalCredentials.
@Test
public void testGetExceptionalCredentials() {
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.Exceptional).withRoleName(TestConfig.ECS_ROLE_NAME);
InstanceProfileCredentialsProvider credentialsProvider = new InstanceProfileCredentialsProvider(TestConfig.ECS_ROLE_NAME).withCredentialsFetcher(credentialsFetcher);
InstanceProfileCredentials credentials = credentialsProvider.getCredentials();
Assert.assertNull(credentials);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.provider.mock.InstanceProfileCredentialsFetcherMock in project aliyun-oss-java-sdk by aliyun.
the class InstanceProfileCredentialsProviderTest method testRefreshCredentials.
@Test
public void testRefreshCredentials() {
try {
InstanceProfileCredentialsFetcher credentialsFetcher = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.Expired).withRoleName(TestConfig.ECS_ROLE_NAME);
InstanceProfileCredentialsProvider credentialsProvider = new InstanceProfileCredentialsProvider(TestConfig.ECS_ROLE_NAME).withCredentialsFetcher(credentialsFetcher);
InstanceProfileCredentials credentials = credentialsProvider.getCredentials();
Assert.assertTrue(credentials.willSoonExpire());
InstanceProfileCredentialsFetcher credentialsFetcher2 = new InstanceProfileCredentialsFetcherMock().withResponseCategory(ResponseCategory.Normal).withRoleName(TestConfig.ECS_ROLE_NAME);
credentialsProvider.withCredentialsFetcher(credentialsFetcher2);
credentials = credentialsProvider.getCredentials();
Assert.assertFalse(credentials.willSoonExpire());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations