Search in sources :

Example 1 with CustomSessionCredentialsProvider

use of com.aliyun.oss.common.auth.CustomSessionCredentialsProvider 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());
    }
}
Also used : CustomSessionCredentialsFetcherMock(com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock) CustomSessionCredentialsProvider(com.aliyun.oss.common.auth.CustomSessionCredentialsProvider) CustomSessionCredentialsFetcher(com.aliyun.oss.common.auth.CustomSessionCredentialsFetcher) BasicCredentials(com.aliyun.oss.common.auth.BasicCredentials) Test(org.junit.Test)

Example 2 with CustomSessionCredentialsProvider

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

the class CustomSessionCredentialsProviderTest method testGetCredentialsNegative.

@Test
public void testGetCredentialsNegative() {
    try {
        CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST + "/noteixst");
        Credentials credentials = credentialsProvider.getCredentials();
        Assert.assertNull(credentials);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : CustomSessionCredentialsProvider(com.aliyun.oss.common.auth.CustomSessionCredentialsProvider) BasicCredentials(com.aliyun.oss.common.auth.BasicCredentials) Credentials(com.aliyun.oss.common.auth.Credentials) Test(org.junit.Test)

Example 3 with CustomSessionCredentialsProvider

use of com.aliyun.oss.common.auth.CustomSessionCredentialsProvider 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());
    }
}
Also used : CustomSessionCredentialsFetcherMock(com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock) CustomSessionCredentialsProvider(com.aliyun.oss.common.auth.CustomSessionCredentialsProvider) CustomSessionCredentialsFetcher(com.aliyun.oss.common.auth.CustomSessionCredentialsFetcher) BasicCredentials(com.aliyun.oss.common.auth.BasicCredentials) Test(org.junit.Test)

Example 4 with CustomSessionCredentialsProvider

use of com.aliyun.oss.common.auth.CustomSessionCredentialsProvider 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());
    }
}
Also used : CustomSessionCredentialsFetcherMock(com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock) CustomSessionCredentialsProvider(com.aliyun.oss.common.auth.CustomSessionCredentialsProvider) CustomSessionCredentialsFetcher(com.aliyun.oss.common.auth.CustomSessionCredentialsFetcher) BasicCredentials(com.aliyun.oss.common.auth.BasicCredentials) Test(org.junit.Test)

Example 5 with CustomSessionCredentialsProvider

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

the class CustomSessionCredentialsProviderTest method testGetCredentialsServerHalt.

@Test
public void testGetCredentialsServerHalt() {
    try {
        CustomSessionCredentialsFetcher credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.ServerHalt);
        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());
    }
}
Also used : CustomSessionCredentialsFetcherMock(com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock) CustomSessionCredentialsProvider(com.aliyun.oss.common.auth.CustomSessionCredentialsProvider) CustomSessionCredentialsFetcher(com.aliyun.oss.common.auth.CustomSessionCredentialsFetcher) BasicCredentials(com.aliyun.oss.common.auth.BasicCredentials) Credentials(com.aliyun.oss.common.auth.Credentials) Test(org.junit.Test)

Aggregations

CustomSessionCredentialsProvider (com.aliyun.oss.common.auth.CustomSessionCredentialsProvider)10 Test (org.junit.Test)10 BasicCredentials (com.aliyun.oss.common.auth.BasicCredentials)9 CustomSessionCredentialsFetcher (com.aliyun.oss.common.auth.CustomSessionCredentialsFetcher)7 CustomSessionCredentialsFetcherMock (com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock)7 Credentials (com.aliyun.oss.common.auth.Credentials)4 OSS (com.aliyun.oss.OSS)2 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2