From 8caa0bdc624ab9989e8906ca411bed6b7a3e9912 Mon Sep 17 00:00:00 2001 From: Fabrice Bibonne Date: Wed, 17 Sep 2025 19:40:21 +0200 Subject: [PATCH 1/3] feat (mask properties containing hidden token ignoring case) - functional test - implementation - containsIgnoreCase implementation and test --- README.md | 2 +- pom.xml | 2 +- .../propertieslogger/PropertiesLogger.java | 29 +++++++++++++- .../propertieslogger/ConstantsForTests.java | 5 +++ .../PropertiesLoggerTest.java | 39 +++++++++++++++++++ .../fbibonne/test/MaskedValuesTest.java | 27 +++++++++++++ 6 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/test/java/io/github/fbibonne/springaddons/boot/propertieslogger/ConstantsForTests.java create mode 100644 src/test/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLoggerTest.java create mode 100644 src/test/java/io/github/fbibonne/test/MaskedValuesTest.java diff --git a/README.md b/README.md index 2df80de..fe331ee 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Usage is simple : just add this dependency inside your pom.xml : io.github.fbibonne boot-properties-logger-starter - 1.4.0 + 1.5.0 ``` diff --git a/pom.xml b/pom.xml index 07091bd..9ec12a4 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ io.github.fbibonne boot-properties-logger-starter - 1.4.0 + 1.5.0 jar diff --git a/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLogger.java b/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLogger.java index 95fa324..b213a78 100644 --- a/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLogger.java +++ b/src/main/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLogger.java @@ -11,6 +11,7 @@ import java.util.HashSet; import java.util.Set; import java.util.function.Consumer; +import java.util.function.Predicate; import java.util.function.UnaryOperator; import java.util.stream.Stream; @@ -113,12 +114,38 @@ private void resolveValueThenAppendToDisplay(String key, EnvironmentPreparedEven } private String resolveValueThenMaskItIfSecret(String key, EnvironmentPreparedEventForPropertiesLogging.CustomAbstractEnvironment environment) { - if (propertiesWithHiddenValues.stream().anyMatch(key::contains)) { + if (propertiesWithHiddenValues.stream().anyMatch(isValueContainedIgnoringCaseIn(key))) { return MASK; } return environment.getPropertySafely(key); } + /** + * Implementation of a String#containsIgnoreCase based the algorithm of String#contains + * but using String#equalsIgnoreCase to test equality + * @param container the string which is supposed to contain the argument passed to the predicate. + * Must be not null + * @return a predicate such as container::containsIgnoreCase + * (if String#containsIgnoreCase would exist) + */ + Predicate isValueContainedIgnoringCaseIn(String container) { + return value -> { + if (value==null){ + return false; + } + if (value.isEmpty()){ + return true; + } + int valueLength = value.length(); + for(int i = 0; i <= container.length()- valueLength; i++) { + if (container.substring(i, i+valueLength).equalsIgnoreCase(value)){ + return true; + } + } + return false; + }; + } + private Stream toPropertyNames(EnumerablePropertySource propertySource) { log.trace(() -> "Flat properties for " + propertySource.getName()); return Arrays.stream(propertySource.getPropertyNames()); diff --git a/src/test/java/io/github/fbibonne/springaddons/boot/propertieslogger/ConstantsForTests.java b/src/test/java/io/github/fbibonne/springaddons/boot/propertieslogger/ConstantsForTests.java new file mode 100644 index 0000000..eaac2f3 --- /dev/null +++ b/src/test/java/io/github/fbibonne/springaddons/boot/propertieslogger/ConstantsForTests.java @@ -0,0 +1,5 @@ +package io.github.fbibonne.springaddons.boot.propertieslogger; + +public class ConstantsForTests { + public static final String MASK = PropertiesLogger.MASK; +} diff --git a/src/test/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLoggerTest.java b/src/test/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLoggerTest.java new file mode 100644 index 0000000..668de58 --- /dev/null +++ b/src/test/java/io/github/fbibonne/springaddons/boot/propertieslogger/PropertiesLoggerTest.java @@ -0,0 +1,39 @@ +package io.github.fbibonne.springaddons.boot.propertieslogger; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import static org.assertj.core.api.Assertions.assertThat; + +class PropertiesLoggerTest { + + @ParameterizedTest + @CsvSource({ + "'io.github.fbibonne', 'fbibonne', true", + "'org.test-dash', 't-d', true", + "'io.github.fbibonne', 'fBibonne', true", + "'io.github.fbibonne', 'hub.FB', true", + "'org.test-dash', 't-D', true", + "'io.github.FBibonne', 'fbibonne', true", + "'io.github.FBibonne', 'FBIBONNE', true", + "'io.gitHUB.fbibonne', 'hub.fb', true", + "'org.test-dash', 't-D', true", + "'org.tesT-Dash', 't-d', true", + "'org.test-dash', 't_d', false", + "'io.gitHUB-fbibonne', 'hub.fb', false", + "'io.github.fbibonne', 'io.fb', false", + "'stringFirst', 'string', true", + "'stringFirst', 'StrinG', true", + "'stringLast', 'Lasts', false", + "'stringFirst', 'astring', false", + "'null.is.not.contained', , false", + "'empty.is.contained', '', true", + "'self.is.contained', 'self.is.contained', true", + "'self.is.contained', 'SelF.iS.conTained', true", + "'longer.is.not.contained','longer.is.not.contained+', false" + }) + void isValueContainedIgnoringCaseInTest(String container, String value, boolean expected) { + PropertiesLogger propertiesLogger = new PropertiesLogger(null, null, null); + assertThat(propertiesLogger.isValueContainedIgnoringCaseIn(container).test(value)).isEqualTo(expected); + } +} \ No newline at end of file diff --git a/src/test/java/io/github/fbibonne/test/MaskedValuesTest.java b/src/test/java/io/github/fbibonne/test/MaskedValuesTest.java new file mode 100644 index 0000000..eeb8b3f --- /dev/null +++ b/src/test/java/io/github/fbibonne/test/MaskedValuesTest.java @@ -0,0 +1,27 @@ +package io.github.fbibonne.test; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.context.annotation.Configuration; + +import static io.github.fbibonne.springaddons.boot.propertieslogger.ConstantsForTests.MASK; +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = ExcludedPropertySourcesTest.class, properties = { + "com.mycompany.serviceContactPassword = verysecretpassword", + "properties.logger.prefix-for-properties = com" +}) +@Configuration +@ExtendWith(OutputCaptureExtension.class) +class MaskedValuesTest { + + @Test + void checkMaskValuesIgnoreCase(CapturedOutput output) { + assertThat(output.toString()).doesNotContain("verysecretpassword") + .contains("com.mycompany.serviceContactPassword = "+MASK); + } + +} From 68564400b72db8bc62ddab0186a51682620ee99a Mon Sep 17 00:00:00 2001 From: Fabrice Bibonne Date: Wed, 17 Sep 2025 19:41:48 +0200 Subject: [PATCH 2/3] pom (upgrade spring boot base version) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9ec12a4..766f221 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.springframework.boot spring-boot-dependencies - 3.5.4 + 3.5.5 io.github.fbibonne From cc3dff098e668e60c4837cf9df210cabb7405998 Mon Sep 17 00:00:00 2001 From: Fabrice Bibonne Date: Wed, 17 Sep 2025 19:51:24 +0200 Subject: [PATCH 3/3] ci (fix check_pr ci falilure ) - move maven plugin gpg sign goal to install phase --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 766f221..b29053c 100644 --- a/pom.xml +++ b/pom.xml @@ -140,7 +140,7 @@ sign-artifacts - verify + install sign