use of com.aliyun.oss.common.auth.CustomSessionCredentialsFetcher in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testGetExceptionalCredentials.
@Test
public void testGetExceptionalCredentials() {
try {
CustomSessionCredentialsFetcher credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.Exceptional);
CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST).withCredentialsFetcher(credentialsFetcher);
Credentials credentials = credentialsProvider.getCredentials();
Assert.assertNull(credentials);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.CustomSessionCredentialsFetcher in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testRefreshCredentials.
@Test
public void testRefreshCredentials() {
try {
CustomSessionCredentialsFetcher credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.Expired);
CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST).withCredentialsFetcher(credentialsFetcher);
BasicCredentials credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertTrue(credentials.willSoonExpire());
credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.Normal);
credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.ECS_ROLE_NAME).withCredentialsFetcher(credentialsFetcher);
credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertFalse(credentials.willSoonExpire());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations