use of com.aliyun.oss.common.auth.BasicCredentials in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testGetNormalWithoutTokenCredentials.
@Test
public void testGetNormalWithoutTokenCredentials() {
try {
CustomSessionCredentialsFetcher credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.NormalWithoutToken);
CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST).withCredentialsFetcher(credentialsFetcher);
BasicCredentials credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertEquals(credentials.getAccessKeyId().length(), 29);
Assert.assertEquals(credentials.getSecretAccessKey().length(), 44);
Assert.assertFalse(credentials.useSecurityToken());
Assert.assertFalse(credentials.willSoonExpire());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.BasicCredentials in project aliyun-oss-java-sdk by aliyun.
the class BasicCredentialsTest method testBasicTest.
@Test
public void testBasicTest() {
try {
BasicCredentials credentials = new BasicCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, SECURITY_TOKEN).withExpiredFactor(0.8).withExpiredDuration(900);
Assert.assertEquals(credentials.getAccessKeyId(), ACCESS_KEY_ID);
Assert.assertEquals(credentials.getSecretAccessKey(), ACCESS_KEY_SECRET);
Assert.assertEquals(credentials.getSecurityToken(), SECURITY_TOKEN);
Assert.assertTrue(credentials.useSecurityToken());
credentials = new BasicCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, null).withExpiredFactor(0.8).withExpiredDuration(900);
Assert.assertEquals(credentials.getAccessKeyId(), ACCESS_KEY_ID);
Assert.assertEquals(credentials.getSecretAccessKey(), ACCESS_KEY_SECRET);
Assert.assertNull(credentials.getSecurityToken());
Assert.assertFalse(credentials.useSecurityToken());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.BasicCredentials in project aliyun-oss-java-sdk by aliyun.
the class BasicCredentialsTest method testWillSoonExpire.
@Test
public void testWillSoonExpire() {
try {
BasicCredentials credentials = new BasicCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, SECURITY_TOKEN).withExpiredFactor(1.0).withExpiredDuration(1);
Thread.sleep(2000);
Assert.assertTrue(credentials.willSoonExpire());
credentials = new BasicCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, SECURITY_TOKEN).withExpiredFactor(1.0).withExpiredDuration(100);
Thread.sleep(2000);
Assert.assertFalse(credentials.willSoonExpire());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.BasicCredentials in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testGetNormalCredentials.
@Test
public void testGetNormalCredentials() {
try {
CustomSessionCredentialsFetcher credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.Normal);
CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST).withCredentialsFetcher(credentialsFetcher);
BasicCredentials credentials = (BasicCredentials) 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());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.BasicCredentials 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