From 7a17452f09ca52a29f5135505c2f7bf64d1a864f Mon Sep 17 00:00:00 2001 From: babubabu Date: Wed, 28 Feb 2024 23:23:32 +0100 Subject: [PATCH] Fixing empty truststore-config in KBCP * do not copy truststore, if "ssl.truststore.location" is set to empty string (e.g. ssl.truststore.location:{ENV_VARIABLE}) via KafkaBinderConfigurataionProperties. --- .../KafkaBinderConfigurationProperties.java | 3 ++- .../KafkaBinderConfigurationPropertiesTest.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java b/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java index 45e4f92d6..c06cef0ea 100644 --- a/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java +++ b/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java @@ -64,6 +64,7 @@ import org.springframework.util.StringUtils; * @author Nico Heller * @author Norbert Gyurian * @author Boini Srinivas + * @author Felix Schultze */ public class KafkaBinderConfigurationProperties { @@ -211,7 +212,7 @@ public class KafkaBinderConfigurationProperties { final String storeLocation = this.configuration.get(storeProperty); // If the path is not defined, or it is a local file path do not move the file - if (storeLocation != null && !checkIfFileExists(storeLocation)) { + if (StringUtils.hasText(storeLocation) && !checkIfFileExists(storeLocation)) { final String fileSystemLocation = moveCertToFileSystem(storeLocation, this.certificateStoreDirectory); // Overriding the value with absolute filesystem path. this.configuration.put(storeProperty, fileSystemLocation); diff --git a/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/test/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationPropertiesTest.java b/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/test/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationPropertiesTest.java index a7d405c28..3b77d5d96 100644 --- a/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/test/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationPropertiesTest.java +++ b/binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/test/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationPropertiesTest.java @@ -253,6 +253,22 @@ public class KafkaBinderConfigurationPropertiesTest { } + @Test + public void testEmptyLocationsAreIgnored() { + KafkaProperties kafkaProperties = new KafkaProperties(); + KafkaBinderConfigurationProperties kafkaBinderConfigurationProperties = + new KafkaBinderConfigurationProperties(kafkaProperties); + final Map configuration = kafkaBinderConfigurationProperties.getConfiguration(); + configuration.put("schema.registry.ssl.truststore.location", ""); + configuration.put("schema.registry.ssl.keystore.location", ""); + kafkaBinderConfigurationProperties.setCertificateStoreDirectory("target"); + + kafkaBinderConfigurationProperties.getKafkaConnectionString(); + + assertThat(configuration.get("schema.registry.ssl.truststore.location")).isEmpty(); + assertThat(configuration.get("schema.registry.ssl.keystore.location")).isEmpty(); + } + private void createContextWithCertFileHandler(HttpServer server, String path) { server.createContext("/" + path, exchange -> { ClassPathResource ts = new ClassPathResource(path);