Search in sources :

Example 26 with ProfileFile

use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.

the class ProfileCredentialsUtilsTest method profileFileWithCircularDependencyThrowsExceptionWhenResolvingCredentials.

@Test
public void profileFileWithCircularDependencyThrowsExceptionWhenResolvingCredentials() {
    ProfileFile configFile = configFile("[profile source]\n" + "aws_access_key_id=defaultAccessKey\n" + "aws_secret_access_key=defaultSecretAccessKey\n" + "\n" + "[profile test]\n" + "source_profile=test3\n" + "role_arn=arn:aws:iam::123456789012:role/testRole\n" + "\n" + "[profile test2]\n" + "source_profile=test\n" + "role_arn=arn:aws:iam::123456789012:role/testRole2\n" + "\n" + "[profile test3]\n" + "source_profile=test2\n" + "role_arn=arn:aws:iam::123456789012:role/testRole3");
    assertThatThrownBy(() -> new ProfileCredentialsUtils(configFile, configFile.profile("test").get(), configFile::profile).credentialsProvider()).isInstanceOf(IllegalStateException.class).hasMessageContaining("Invalid profile file: Circular relationship detected with profiles");
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test) ProcessCredentialsProviderTest(software.amazon.awssdk.auth.credentials.ProcessCredentialsProviderTest)

Example 27 with ProfileFile

use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.

the class ProfileCredentialsUtilsTest method profileFileWithCredentialSourceThrowsExceptionWhenRetrievingCredentialsProvider.

@Test
public void profileFileWithCredentialSourceThrowsExceptionWhenRetrievingCredentialsProvider() {
    ProfileFile profileFile = allTypesProfile();
    List<String> profiles = Arrays.asList("profile-with-container-credential-source", "profile-with-instance-credential-source", "profile-with-environment-credential-source");
    profiles.forEach(profileName -> {
        assertThat(profileFile.profile(profileName)).hasValueSatisfying(profile -> {
            assertThat(profile.property(ProfileProperty.REGION)).isNotPresent();
            ProfileCredentialsUtils profileCredentialsUtils = new ProfileCredentialsUtils(profileFile, profile, profileFile::profile);
            assertThatThrownBy(profileCredentialsUtils::credentialsProvider).isInstanceOf(IllegalStateException.class);
        });
    });
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test) ProcessCredentialsProviderTest(software.amazon.awssdk.auth.credentials.ProcessCredentialsProviderTest)

Example 28 with ProfileFile

use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.

the class ProfileCredentialsUtilsTest method profileFileWithSessionCredentialsLoadsCorrectly.

@Test
public void profileFileWithSessionCredentialsLoadsCorrectly() {
    ProfileFile profileFile = allTypesProfile();
    assertThat(profileFile.profile("profile-with-session-token")).hasValueSatisfying(profile -> {
        assertThat(profile.property(ProfileProperty.REGION)).isNotPresent();
        assertThat(new ProfileCredentialsUtils(profileFile, profile, profileFile::profile).credentialsProvider()).hasValueSatisfying(credentialsProvider -> {
            assertThat(credentialsProvider.resolveCredentials()).satisfies(credentials -> {
                assertThat(credentials).isInstanceOf(AwsSessionCredentials.class);
                assertThat(credentials.accessKeyId()).isEqualTo("defaultAccessKey");
                assertThat(credentials.secretAccessKey()).isEqualTo("defaultSecretAccessKey");
                assertThat(((AwsSessionCredentials) credentials).sessionToken()).isEqualTo("awsSessionToken");
            });
        });
    });
}
Also used : AwsSessionCredentials(software.amazon.awssdk.auth.credentials.AwsSessionCredentials) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test) ProcessCredentialsProviderTest(software.amazon.awssdk.auth.credentials.ProcessCredentialsProviderTest)

Example 29 with ProfileFile

use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.

the class ProfileCredentialsUtilsTest method profileFileWithAssumeRoleThrowsExceptionWhenRetrievingCredentialsProvider.

@Test
public void profileFileWithAssumeRoleThrowsExceptionWhenRetrievingCredentialsProvider() {
    ProfileFile profileFile = allTypesProfile();
    assertThat(profileFile.profile("profile-with-assume-role")).hasValueSatisfying(profile -> {
        assertThat(profile.property(ProfileProperty.REGION)).isNotPresent();
        ProfileCredentialsUtils profileCredentialsUtils = new ProfileCredentialsUtils(profileFile, profile, profileFile::profile);
        assertThatThrownBy(profileCredentialsUtils::credentialsProvider).isInstanceOf(IllegalStateException.class);
    });
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test) ProcessCredentialsProviderTest(software.amazon.awssdk.auth.credentials.ProcessCredentialsProviderTest)

Example 30 with ProfileFile

use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.

the class ProfileCredentialsUtilsTest method roleProfileWithSourceThatHasNoCredentialsThrowsExceptionWhenLoadingCredentials.

@Test
public void roleProfileWithSourceThatHasNoCredentialsThrowsExceptionWhenLoadingCredentials() {
    ProfileFile profiles = configFile("[profile source]\n" + "[profile test]\n" + "source_profile=source\n" + "role_arn=arn:aws:iam::123456789012:role/testRole");
    assertThat(profiles.profile("test")).hasValueSatisfying(profile -> {
        ProfileCredentialsUtils profileCredentialsUtils = new ProfileCredentialsUtils(profiles, profile, profiles::profile);
        assertThatThrownBy(profileCredentialsUtils::credentialsProvider).hasMessageContaining("source profile has no credentials configured");
    });
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test) ProcessCredentialsProviderTest(software.amazon.awssdk.auth.credentials.ProcessCredentialsProviderTest)

Aggregations

ProfileFile (software.amazon.awssdk.profiles.ProfileFile)47 Test (org.junit.jupiter.api.Test)22 StringInputStream (software.amazon.awssdk.utils.StringInputStream)20 Test (org.junit.Test)14 ProcessCredentialsProviderTest (software.amazon.awssdk.auth.credentials.ProcessCredentialsProviderTest)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 ProfileCredentialsUtils (software.amazon.awssdk.auth.credentials.internal.ProfileCredentialsUtils)9 Region (software.amazon.awssdk.regions.Region)9 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)8 URI (java.net.URI)7 Optional (java.util.Optional)6 Arrays (java.util.Arrays)5 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)5 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)5 ExecutionInterceptor (software.amazon.awssdk.core.interceptor.ExecutionInterceptor)5 Profile (software.amazon.awssdk.profiles.Profile)5 SdkAutoCloseable (software.amazon.awssdk.utils.SdkAutoCloseable)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)4