use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class EndpointDiscoveryTest method canBeEnabledViaProfileOnOverrideConfiguration.
@Test(timeout = 10_000)
public void canBeEnabledViaProfileOnOverrideConfiguration() throws InterruptedException {
ExecutionInterceptor interceptor = Mockito.spy(AbstractExecutionInterceptor.class);
String profileFileContent = "[default]\n" + "aws_endpoint_discovery_enabled = true";
ProfileFile profileFile = ProfileFile.builder().type(ProfileFile.Type.CONFIGURATION).content(new StringInputStream(profileFileContent)).build();
DynamoDbClient dynamoDb = DynamoDbClient.builder().region(Region.US_WEST_2).credentialsProvider(AnonymousCredentialsProvider.create()).overrideConfiguration(c -> c.defaultProfileFile(profileFile).defaultProfileName("default").addExecutionInterceptor(interceptor).retryPolicy(r -> r.numRetries(0))).build();
assertThatThrownBy(dynamoDb::listTables).isInstanceOf(SdkException.class);
ArgumentCaptor<Context.BeforeTransmission> context;
do {
Thread.sleep(1);
context = ArgumentCaptor.forClass(Context.BeforeTransmission.class);
Mockito.verify(interceptor, atLeastOnce()).beforeTransmission(context.capture(), any());
} while (context.getAllValues().size() < 2);
assertThat(context.getAllValues().stream().anyMatch(v -> v.httpRequest().firstMatchingHeader("X-Amz-Target").map(h -> h.equals("DynamoDB_20120810.DescribeEndpoints")).orElse(false))).isTrue();
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class SsoProfileTest method createSsoCredentialsProvider_SsoRegionMissing_throwException.
@Test
public void createSsoCredentialsProvider_SsoRegionMissing_throwException() {
String profileContent = "[profile foo]\n" + "sso_account_id=012345678901\n" + "sso_role_name=SampleRole\n" + "sso_start_url=https://d-abc123.awsapps.com/start-beta\n";
ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(profileContent)).type(ProfileFile.Type.CONFIGURATION).build();
assertThat(profiles.profile("foo")).hasValueSatisfying(profile -> {
assertThatThrownBy(() -> new ProfileCredentialsUtils(profiles, profile, profiles::profile).credentialsProvider()).hasMessageContaining("Profile property 'sso_region' was not configured");
});
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class SsoProfileTest method createSsoCredentialsProvider_SsoStartUrlMissing_throwException.
@Test
public void createSsoCredentialsProvider_SsoStartUrlMissing_throwException() {
String profileContent = "[profile foo]\n" + "sso_account_id=012345678901\n" + "sso_region=us-east-1\n" + "sso_role_name=SampleRole\n";
ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(profileContent)).type(ProfileFile.Type.CONFIGURATION).build();
assertThat(profiles.profile("foo")).hasValueSatisfying(profile -> {
assertThatThrownBy(() -> new ProfileCredentialsUtils(profiles, profile, profiles::profile).credentialsProvider()).hasMessageContaining("Profile property 'sso_start_url' was not configured");
});
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class AssumeRoleIntegrationTest method profileCredentialsProviderCanAssumeRoles.
@Test
public void profileCredentialsProviderCanAssumeRoles() throws InterruptedException {
String ASSUME_ROLE_PROFILE = "[source]\n" + "aws_access_key_id = " + userCredentials.accessKeyId() + "\n" + "aws_secret_access_key = " + userCredentials.secretAccessKey() + "\n" + "\n" + "[test]\n" + "region = us-west-1\n" + "source_profile = source\n" + "role_arn = " + ROLE_ARN;
ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(ASSUME_ROLE_PROFILE)).type(ProfileFile.Type.CREDENTIALS).build();
Optional<Profile> profile = profiles.profile("test");
AwsCredentialsProvider awsCredentialsProvider = new ProfileCredentialsUtils(profiles, profile.get(), profiles::profile).credentialsProvider().get();
// Try to assume the role until the eventual consistency catches up.
AwsCredentials awsCredentials = Waiter.run(awsCredentialsProvider::resolveCredentials).ignoringException(StsException.class).orFail();
assertThat(awsCredentials.accessKeyId()).isNotBlank();
assertThat(awsCredentials.secretAccessKey()).isNotBlank();
((SdkAutoCloseable) awsCredentialsProvider).close();
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class AssumeRoleIntegrationTest method profileCredentialProviderCanAssumeRolesWithEnvironmentCredentialSource.
@Test
public void profileCredentialProviderCanAssumeRolesWithEnvironmentCredentialSource() throws InterruptedException {
EnvironmentVariableHelper.run(helper -> {
helper.set("AWS_ACCESS_KEY_ID", userCredentials.accessKeyId());
helper.set("AWS_SECRET_ACCESS_KEY", userCredentials.secretAccessKey());
helper.remove("AWS_SESSION_TOKEN");
String ASSUME_ROLE_PROFILE = "[test]\n" + "region = us-west-1\n" + "credential_source = Environment\n" + "role_arn = " + ROLE_ARN;
ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(ASSUME_ROLE_PROFILE)).type(ProfileFile.Type.CREDENTIALS).build();
Optional<Profile> profile = profiles.profile("test");
AwsCredentialsProvider awsCredentialsProvider = new ProfileCredentialsUtils(profiles, profile.get(), profiles::profile).credentialsProvider().get();
// Try to assume the role until the eventual consistency catches up.
AwsCredentials awsCredentials = Waiter.run(awsCredentialsProvider::resolveCredentials).ignoringException(StsException.class).orFail();
assertThat(awsCredentials.accessKeyId()).isNotBlank();
assertThat(awsCredentials.secretAccessKey()).isNotBlank();
((SdkAutoCloseable) awsCredentialsProvider).close();
});
}
Aggregations