use of com.aliyun.oss.common.auth.BasicCredentials in project aliyun-oss-java-sdk by aliyun.
the class STSKeyPairSessionCredentialsProviderTest method testStsKeyPairCredentialsProviderExpire.
@Test
public void testStsKeyPairCredentialsProviderExpire() {
try {
PublicKey publicKey = AuthUtils.uploadPublicKey(TestConfig.RAM_REGION_ID, TestConfig.ROOT_ACCESS_KEY_ID, TestConfig.ROOT_ACCESS_KEY_SECRET, AuthUtils.loadPublicKeyFromFile(TestConfig.PUBLIC_KEY_PATH));
CredentialsProvider credentialsProvider = CredentialsProviderFactory.newSTSKeyPairSessionCredentialsProvider(TestConfig.RAM_REGION_ID, publicKey.getPublicKeyId(), AuthUtils.loadPrivateKeyFromFile(TestConfig.PRIVATE_KEY_PATH)).withExpiredFactor(0.001).withExpiredDuration(2000);
BasicCredentials credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertFalse(credentials.willSoonExpire());
Thread.sleep(3000);
Assert.assertTrue(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 STSAssumeRoleSessionCredentialsProviderTest method testStsAssumeRoleCredentialsProviderExpire.
@Test
public void testStsAssumeRoleCredentialsProviderExpire() {
try {
CredentialsProvider credentialsProvider = CredentialsProviderFactory.newSTSAssumeRoleSessionCredentialsProvider(TestConfig.RAM_REGION_ID, TestConfig.USER_ACCESS_KEY_ID, TestConfig.USER_ACCESS_KEY_SECRET, TestConfig.RAM_ROLE_ARN).withExpiredFactor(0.001).withExpiredDuration(2000);
BasicCredentials credentials = (BasicCredentials) credentialsProvider.getCredentials();
Assert.assertFalse(credentials.willSoonExpire());
Thread.sleep(3000);
Assert.assertTrue(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 testExpiredFactor.
@Test
public void testExpiredFactor() {
try {
BasicCredentials credentials = new BasicCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, SECURITY_TOKEN).withExpiredFactor(1.0).withExpiredDuration(3);
Thread.sleep(2000);
Assert.assertFalse(credentials.willSoonExpire());
credentials = new BasicCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, SECURITY_TOKEN).withExpiredFactor(0.1).withExpiredDuration(3);
Thread.sleep(1000);
Assert.assertTrue(credentials.willSoonExpire());
credentials = new BasicCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, SECURITY_TOKEN).withExpiredFactor(1.0).withExpiredDuration(1);
Thread.sleep(1500);
Assert.assertTrue(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 testGetExpiredCredentials.
@Test
public void testGetExpiredCredentials() {
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.assertEquals(credentials.getAccessKeyId().length(), 29);
Assert.assertEquals(credentials.getSecretAccessKey().length(), 44);
Assert.assertEquals(credentials.getSecurityToken().length(), 536);
Assert.assertTrue(credentials.useSecurityToken());
Assert.assertTrue(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 testGetNormalWithoutExpirationCredentials.
@Test
public void testGetNormalWithoutExpirationCredentials() {
try {
CustomSessionCredentialsFetcher credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.NormalWithoutExpiration);
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());
}
}
Aggregations