Search in sources :

Example 1 with CustomSessionCredentialsFetcherMock

use of com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock 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 CustomSessionCredentialsFetcherMock

use of com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock 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 3 with CustomSessionCredentialsFetcherMock

use of com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock 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 4 with CustomSessionCredentialsFetcherMock

use of com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock 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)

Example 5 with CustomSessionCredentialsFetcherMock

use of com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock 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());
    }
}
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)

Aggregations

BasicCredentials (com.aliyun.oss.common.auth.BasicCredentials)7 CustomSessionCredentialsFetcher (com.aliyun.oss.common.auth.CustomSessionCredentialsFetcher)7 CustomSessionCredentialsProvider (com.aliyun.oss.common.auth.CustomSessionCredentialsProvider)7 CustomSessionCredentialsFetcherMock (com.aliyun.oss.common.provider.mock.CustomSessionCredentialsFetcherMock)7 Test (org.junit.Test)7 Credentials (com.aliyun.oss.common.auth.Credentials)2