Skip to content

Commit

Permalink
Re-introduce a no-args constructor for LoggingConfigSourceInterceptor…
Browse files Browse the repository at this point in the history
… so that loading the service as described on https://smallrye.io/smallrye-config/Main/extensions/logging/ is still/again possible (#1127)
  • Loading branch information
turing85 authored Mar 6, 2024
1 parent b58465c commit 55ac71e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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()
Expand Down

0 comments on commit 55ac71e

Please sign in to comment.