Search in sources :

Example 11 with InstanceProfileCredentials

use of com.aliyun.oss.common.auth.InstanceProfileCredentials 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());
    }
}
Also used : InstanceProfileCredentialsProvider(com.aliyun.oss.common.auth.InstanceProfileCredentialsProvider) InstanceProfileCredentials(com.aliyun.oss.common.auth.InstanceProfileCredentials) InstanceProfileCredentialsFetcher(com.aliyun.oss.common.auth.InstanceProfileCredentialsFetcher) InstanceProfileCredentialsFetcherMock(com.aliyun.oss.common.provider.mock.InstanceProfileCredentialsFetcherMock) Test(org.junit.Test)

Example 12 with InstanceProfileCredentials

use of com.aliyun.oss.common.auth.InstanceProfileCredentials 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());
    }
}
Also used : InstanceProfileCredentialsProvider(com.aliyun.oss.common.auth.InstanceProfileCredentialsProvider) InstanceProfileCredentials(com.aliyun.oss.common.auth.InstanceProfileCredentials) InstanceProfileCredentialsFetcher(com.aliyun.oss.common.auth.InstanceProfileCredentialsFetcher) InstanceProfileCredentialsFetcherMock(com.aliyun.oss.common.provider.mock.InstanceProfileCredentialsFetcherMock) Test(org.junit.Test)

Example 13 with InstanceProfileCredentials

use of com.aliyun.oss.common.auth.InstanceProfileCredentials in project aliyun-oss-java-sdk by aliyun.

the class InstanceProfileCredentialsProviderTest method testGetCredentialsNegative.

@Test
public void testGetCredentialsNegative() {
    try {
        InstanceProfileCredentialsProvider credentialsProvider = new InstanceProfileCredentialsProvider("NotExistRoleName");
        InstanceProfileCredentials credentials = credentialsProvider.getCredentials();
        Assert.assertNull(credentials);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : InstanceProfileCredentialsProvider(com.aliyun.oss.common.auth.InstanceProfileCredentialsProvider) InstanceProfileCredentials(com.aliyun.oss.common.auth.InstanceProfileCredentials) Test(org.junit.Test)

Aggregations

InstanceProfileCredentials (com.aliyun.oss.common.auth.InstanceProfileCredentials)13 Test (org.junit.Test)11 InstanceProfileCredentialsFetcher (com.aliyun.oss.common.auth.InstanceProfileCredentialsFetcher)7 InstanceProfileCredentialsProvider (com.aliyun.oss.common.auth.InstanceProfileCredentialsProvider)7 InstanceProfileCredentialsFetcherMock (com.aliyun.oss.common.provider.mock.InstanceProfileCredentialsFetcherMock)7 ClientException (com.aliyuncs.exceptions.ClientException)3 Ignore (org.junit.Ignore)2