|
|
|
|
@@ -22,7 +22,7 @@ import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
@@ -31,6 +31,7 @@ import org.springframework.boot.actuate.context.properties.ConfigurationProperti
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
@@ -47,20 +48,20 @@ public class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void configurationPropertiesAreReturned() throws Exception {
|
|
|
|
|
load((properties) -> {
|
|
|
|
|
load((context, properties) -> {
|
|
|
|
|
assertThat(properties.getContextId()).isEqualTo(context.getId());
|
|
|
|
|
assertThat(properties.getBeans().size()).isGreaterThan(0);
|
|
|
|
|
ConfigurationPropertiesBeanDescriptor nestedProperties = properties.getBeans()
|
|
|
|
|
.get("testProperties");
|
|
|
|
|
assertThat(nestedProperties).isNotNull();
|
|
|
|
|
assertThat(nestedProperties.getPrefix()).isEqualTo("test");
|
|
|
|
|
assertThat(nestedProperties.getProperties()).isNotNull();
|
|
|
|
|
assertThat(nestedProperties.getProperties()).isNotEmpty();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void entriesWithNullValuesAreNotIncluded() {
|
|
|
|
|
load((properties) -> {
|
|
|
|
|
load((context, properties) -> {
|
|
|
|
|
Map<String, Object> nestedProperties = properties.getBeans()
|
|
|
|
|
.get("testProperties").getProperties();
|
|
|
|
|
assertThat(nestedProperties).doesNotContainKey("nullValue");
|
|
|
|
|
@@ -69,7 +70,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void defaultKeySanitization() throws Exception {
|
|
|
|
|
load((properties) -> {
|
|
|
|
|
load((context, properties) -> {
|
|
|
|
|
Map<String, Object> nestedProperties = properties.getBeans()
|
|
|
|
|
.get("testProperties").getProperties();
|
|
|
|
|
assertThat(nestedProperties).isNotNull();
|
|
|
|
|
@@ -80,7 +81,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void customKeySanitization() throws Exception {
|
|
|
|
|
load("property", (properties) -> {
|
|
|
|
|
load("property", (context, properties) -> {
|
|
|
|
|
Map<String, Object> nestedProperties = properties.getBeans()
|
|
|
|
|
.get("testProperties").getProperties();
|
|
|
|
|
assertThat(nestedProperties).isNotNull();
|
|
|
|
|
@@ -91,7 +92,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void customPatternKeySanitization() throws Exception {
|
|
|
|
|
load(".*pass.*", (properties) -> {
|
|
|
|
|
load(".*pass.*", (context, properties) -> {
|
|
|
|
|
Map<String, Object> nestedProperties = properties.getBeans()
|
|
|
|
|
.get("testProperties").getProperties();
|
|
|
|
|
assertThat(nestedProperties).isNotNull();
|
|
|
|
|
@@ -104,23 +105,24 @@ public class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void keySanitizationWithCustomPatternUsingCompositeKeys() throws Exception {
|
|
|
|
|
// gh-4415
|
|
|
|
|
load(Arrays.asList(".*\\.secrets\\..*", ".*\\.hidden\\..*"), (properties) -> {
|
|
|
|
|
Map<String, Object> nestedProperties = properties.getBeans()
|
|
|
|
|
.get("testProperties").getProperties();
|
|
|
|
|
assertThat(nestedProperties).isNotNull();
|
|
|
|
|
Map<String, Object> secrets = (Map<String, Object>) nestedProperties
|
|
|
|
|
.get("secrets");
|
|
|
|
|
Map<String, Object> hidden = (Map<String, Object>) nestedProperties
|
|
|
|
|
.get("hidden");
|
|
|
|
|
assertThat(secrets.get("mine")).isEqualTo("******");
|
|
|
|
|
assertThat(secrets.get("yours")).isEqualTo("******");
|
|
|
|
|
assertThat(hidden.get("mine")).isEqualTo("******");
|
|
|
|
|
});
|
|
|
|
|
load(Arrays.asList(".*\\.secrets\\..*", ".*\\.hidden\\..*"),
|
|
|
|
|
(context, properties) -> {
|
|
|
|
|
Map<String, Object> nestedProperties = properties.getBeans()
|
|
|
|
|
.get("testProperties").getProperties();
|
|
|
|
|
assertThat(nestedProperties).isNotNull();
|
|
|
|
|
Map<String, Object> secrets = (Map<String, Object>) nestedProperties
|
|
|
|
|
.get("secrets");
|
|
|
|
|
Map<String, Object> hidden = (Map<String, Object>) nestedProperties
|
|
|
|
|
.get("hidden");
|
|
|
|
|
assertThat(secrets.get("mine")).isEqualTo("******");
|
|
|
|
|
assertThat(secrets.get("yours")).isEqualTo("******");
|
|
|
|
|
assertThat(hidden.get("mine")).isEqualTo("******");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void mixedBoolean() throws Exception {
|
|
|
|
|
load((properties) -> {
|
|
|
|
|
load((context, properties) -> {
|
|
|
|
|
Map<String, Object> nestedProperties = properties.getBeans()
|
|
|
|
|
.get("testProperties").getProperties();
|
|
|
|
|
assertThat(nestedProperties.get("mixedBoolean")).isEqualTo(true);
|
|
|
|
|
@@ -130,7 +132,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void listsAreSanitized() throws Exception {
|
|
|
|
|
load((properties) -> {
|
|
|
|
|
load((context, properties) -> {
|
|
|
|
|
Map<String, Object> nestedProperties = properties.getBeans()
|
|
|
|
|
.get("testProperties").getProperties();
|
|
|
|
|
assertThat(nestedProperties.get("listItems")).isInstanceOf(List.class);
|
|
|
|
|
@@ -144,7 +146,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void listsOfListsAreSanitized() throws Exception {
|
|
|
|
|
load((properties) -> {
|
|
|
|
|
load((context, properties) -> {
|
|
|
|
|
Map<String, Object> nestedProperties = properties.getBeans()
|
|
|
|
|
.get("testProperties").getProperties();
|
|
|
|
|
assertThat(nestedProperties.get("listOfListItems")).isInstanceOf(List.class);
|
|
|
|
|
@@ -158,17 +160,18 @@ public class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void load(Consumer<ConfigurationPropertiesDescriptor> properties) {
|
|
|
|
|
private void load(
|
|
|
|
|
BiConsumer<ApplicationContext, ConfigurationPropertiesDescriptor> properties) {
|
|
|
|
|
load(Collections.emptyList(), properties);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void load(String keyToSanitize,
|
|
|
|
|
Consumer<ConfigurationPropertiesDescriptor> properties) {
|
|
|
|
|
BiConsumer<ApplicationContext, ConfigurationPropertiesDescriptor> properties) {
|
|
|
|
|
load(Collections.singletonList(keyToSanitize), properties);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void load(List<String> keysToSanitize,
|
|
|
|
|
Consumer<ConfigurationPropertiesDescriptor> properties) {
|
|
|
|
|
BiConsumer<ApplicationContext, ConfigurationPropertiesDescriptor> properties) {
|
|
|
|
|
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
|
.withUserConfiguration(Config.class);
|
|
|
|
|
contextRunner.run((context) -> {
|
|
|
|
|
@@ -178,7 +181,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
endpoint.setKeysToSanitize(
|
|
|
|
|
keysToSanitize.toArray(new String[keysToSanitize.size()]));
|
|
|
|
|
}
|
|
|
|
|
properties.accept(endpoint.configurationProperties());
|
|
|
|
|
properties.accept(context, endpoint.configurationProperties());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|