From 456b70adb3d4904f3ea16e46ae2311c4695b9f37 Mon Sep 17 00:00:00 2001 From: Maximilian Schellhorn Date: Fri, 10 Jan 2025 16:42:34 +0100 Subject: [PATCH] fix: integration test with system properties to simulate non existing config file --- ...ntBridgeAwsCredentialsProviderFactory.java | 3 ++- ...tBridgeCredentialsProviderFactoryTest.java | 24 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/software/amazon/event/kafkaconnector/auth/EventBridgeAwsCredentialsProviderFactory.java b/src/main/java/software/amazon/event/kafkaconnector/auth/EventBridgeAwsCredentialsProviderFactory.java index 877a56f..66629c8 100644 --- a/src/main/java/software/amazon/event/kafkaconnector/auth/EventBridgeAwsCredentialsProviderFactory.java +++ b/src/main/java/software/amazon/event/kafkaconnector/auth/EventBridgeAwsCredentialsProviderFactory.java @@ -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 { diff --git a/src/test/java/software/amazon/event/kafkaconnector/auth/EventBridgeCredentialsProviderFactoryTest.java b/src/test/java/software/amazon/event/kafkaconnector/auth/EventBridgeCredentialsProviderFactoryTest.java index 9aec73d..35501bd 100644 --- a/src/test/java/software/amazon/event/kafkaconnector/auth/EventBridgeCredentialsProviderFactoryTest.java +++ b/src/test/java/software/amazon/event/kafkaconnector/auth/EventBridgeCredentialsProviderFactoryTest.java @@ -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; @@ -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() { @@ -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"); } }