diff --git a/implementation/src/main/java/io/smallrye/config/LoggingConfigSourceInterceptor.java b/implementation/src/main/java/io/smallrye/config/LoggingConfigSourceInterceptor.java index fe16de083..5da68e9e9 100644 --- a/implementation/src/main/java/io/smallrye/config/LoggingConfigSourceInterceptor.java +++ b/implementation/src/main/java/io/smallrye/config/LoggingConfigSourceInterceptor.java @@ -12,6 +12,10 @@ public class LoggingConfigSourceInterceptor implements ConfigSourceInterceptor { private final boolean enabled; + public LoggingConfigSourceInterceptor() { + this(true); + } + public LoggingConfigSourceInterceptor(final boolean enabled) { this.enabled = enabled; } diff --git a/implementation/src/test/java/io/smallrye/config/LoggingConfigSourceInterceptorTest.java b/implementation/src/test/java/io/smallrye/config/LoggingConfigSourceInterceptorTest.java index 77d666527..a93e49667 100644 --- a/implementation/src/test/java/io/smallrye/config/LoggingConfigSourceInterceptorTest.java +++ b/implementation/src/test/java/io/smallrye/config/LoggingConfigSourceInterceptorTest.java @@ -73,6 +73,36 @@ void interceptor() throws Exception { assertTrue(logs.contains("SRCFG01001: The config secret was loaded from secret with the value secret")); } + @Test + void explicitInterceptor() throws Exception { + Config config = new SmallRyeConfigBuilder() + .addDefaultSources() + .addDefaultInterceptors() + .withInterceptors(new LoggingConfigSourceInterceptor()) + .withSources(new ConfigValuePropertiesConfigSource( + LoggingConfigSourceInterceptorTest.class.getResource("/config-values.properties"))) + .withSecretKeys("secret") + .build(); + + assertEquals("abc", config.getValue("my.prop", String.class)); + // No log is done here to not expose any sensitive information + assertThrows(SecurityException.class, () -> config.getValue("secret", String.class)); + assertThrows(NoSuchElementException.class, () -> config.getValue("not.found", String.class)); + + // This should not log the secret value: + assertEquals("12345678", SecretKeys.doUnlocked(() -> config.getValue("secret", String.class))); + + List logs = logCapture.records().stream().map(LogRecord::getMessage).collect(toList()); + // my.prop lookup + assertTrue(logs.stream() + .anyMatch(log -> log.contains("The config my.prop was loaded from ConfigValuePropertiesConfigSource"))); + assertTrue(logs.stream().anyMatch(log -> log.contains(":1 with the value abc"))); + // not.found lookup + assertTrue(logs.contains("SRCFG01002: The config not.found was not found")); + // secret lookup, shows the key but hides the source and value + assertTrue(logs.contains("SRCFG01001: The config secret was loaded from secret with the value secret")); + } + @Test void expansion() { SmallRyeConfig config = new SmallRyeConfigBuilder()