Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty string check for aws url validation #1089

Merged
merged 5 commits into from Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -138,7 +138,7 @@ private void validateMetadataServerUrls() {
}

private static void validateMetadataServerUrlIfAny(String urlString, String nameInConfig) {
sai-sunder-s marked this conversation as resolved.
Show resolved Hide resolved
if (urlString != null) {
if (urlString != null && !urlString.isEmpty()) {
sai-sunder-s marked this conversation as resolved.
Show resolved Hide resolved
try {
URL url = new URL(urlString);
String host = url.getHost();
Expand Down
Expand Up @@ -475,6 +475,41 @@ public void getAwsSecurityCredentials_fromEnvironmentVariablesWithToken() throws
.setEnv("AWS_SECRET_ACCESS_KEY", "awsSecretAccessKey")
.setEnv("AWS_SESSION_TOKEN", "awsSessionToken");

AwsCredentialSource credSource =
new AwsCredentialSource(
new HashMap<String, Object>() {
{
put("environment_id", "aws1");
put("region_url", "");
put("url", "");
put("regional_cred_verification_url", "regionalCredVerificationUrl");
}
});

AwsCredentials testAwsCredentials =
(AwsCredentials)
AwsCredentials.newBuilder(AWS_CREDENTIAL)
.setEnvironmentProvider(environmentProvider)
.setCredentialSource(credSource)
.build();

AwsSecurityCredentials credentials =
testAwsCredentials.getAwsSecurityCredentials(EMPTY_METADATA_HEADERS);

assertEquals("awsAccessKeyId", credentials.getAccessKeyId());
assertEquals("awsSecretAccessKey", credentials.getSecretAccessKey());
assertEquals("awsSessionToken", credentials.getToken());
}

@Test
public void getAwsSecurityCredentials_fromEnvironmentVariables_noMetadataServerCall()
throws IOException {
TestEnvironmentProvider environmentProvider = new TestEnvironmentProvider();
environmentProvider
.setEnv("AWS_ACCESS_KEY_ID", "awsAccessKeyId")
.setEnv("AWS_SECRET_ACCESS_KEY", "awsSecretAccessKey")
.setEnv("AWS_SESSION_TOKEN", "awsSessionToken");

AwsCredentials testAwsCredentials =
(AwsCredentials)
AwsCredentials.newBuilder(AWS_CREDENTIAL)
Expand Down