Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-introduce a no-args constructor for LoggingConfigSourceInterceptor... #1127

Merged
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
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