Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Usage is simple : just add this dependency inside your pom.xml :
<dependency>
<groupId>io.github.fbibonne</groupId>
<artifactId>boot-properties-logger-starter</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.5.4</version>
<version>3.5.5</version>
</parent>

<groupId>io.github.fbibonne</groupId>
<artifactId>boot-properties-logger-starter</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -140,7 +140,7 @@
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<phase>install</phase>
<goals>
<goal>sign</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 <code>container::containsIgnoreCase</code>
* (if String#containsIgnoreCase would exist)
*/
Predicate<? super String> 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<String> toPropertyNames(EnumerablePropertySource<?> propertySource) {
log.trace(() -> "Flat properties for " + propertySource.getName());
return Arrays.stream(propertySource.getPropertyNames());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.fbibonne.springaddons.boot.propertieslogger;

public class ConstantsForTests {
public static final String MASK = PropertiesLogger.MASK;
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
27 changes: 27 additions & 0 deletions src/test/java/io/github/fbibonne/test/MaskedValuesTest.java
Original file line number Diff line number Diff line change
@@ -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);
}

}