Skip to content

Commit

Permalink
fix: integration test with system properties to simulate non existing…
Browse files Browse the repository at this point in the history
… config file
  • Loading branch information
maschnetwork committed Jan 10, 2025
1 parent 5b1d7de commit 456b70a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public static AwsCredentialsProvider getAwsCredentialsProvider(EventBridgeSinkCo
return getStsAssumeRoleCredentialsProvider(config);
}

// Temporary workaround until AWS SDK issue is fixed: https://github.com/aws/aws-sdk-java-v2/issues/5635
// Temporary workaround until AWS SDK issue is fixed:
// https://github.com/aws/aws-sdk-java-v2/issues/5635
private static ProfileFileSupplier wrappedProfileDefaultSupplier() {
return () -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import java.util.HashMap;
import java.util.Map;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
Expand All @@ -25,6 +28,12 @@ public class EventBridgeCredentialsProviderFactoryTest {
"aws.eventbridge.region", "us-east-1",
"aws.eventbridge.eventbus.arn", "arn:aws:events:us-east-1:000000000000:event-bus/e2e");

@AfterEach
public final void clearSystemProperties(){
System.clearProperty("aws.configFile");
System.clearProperty("aws.sharedCredentialsFile");
}

@Test
public void shouldUseDefaultAwsCredentialsProvider() {

Expand Down Expand Up @@ -68,12 +77,21 @@ public void shouldUseAwsCredentialsProviderByProvidedClass() {
}

@Test
//Testing wrapper functionality as a quick fix until the SDK issue is solved: https://github.com/aws/aws-sdk-java-v2/issues/5635
// Testing wrapper functionality until the AWS SDK issue is solved:
// https://github.com/aws/aws-sdk-java-v2/issues/5635
public void shouldNotGetSDKClientExceptionWithNull() {
//Set path to non-existing full to force null pointer
System.setProperty("aws.configFile", "/non/existing/file");
System.setProperty("aws.sharedCredentialsFile", "/non/existing/file");

var props = new HashMap<>(commonProps);
var provider = EventBridgeAwsCredentialsProviderFactory.getAwsCredentialsProvider(new EventBridgeSinkConfig(props));
var provider =
EventBridgeAwsCredentialsProviderFactory.getAwsCredentialsProvider(
new EventBridgeSinkConfig(props));
var exception = assertThrows(SdkClientException.class, provider::resolveCredentials);

assertThat(exception).hasMessageNotContaining("Cannot invoke \"java.nio.file.Path.getFileSystem()\" because \"path\" is null");
assertThat(exception)
.hasMessageNotContaining(
"Cannot invoke \"java.nio.file.Path.getFileSystem()\" because \"path\" is null");
}
}

0 comments on commit 456b70a

Please sign in to comment.