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");
}
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);
});
});
}
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");
});
});
});
}
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);
});
}
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");
});
}
Aggregations