|
|
|
@ -34,12 +34,16 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
import org.springframework.boot.context.properties.ConstructorBinding;
|
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
|
import org.springframework.boot.context.properties.bind.DefaultValue;
|
|
|
|
|
import org.springframework.boot.origin.Origin;
|
|
|
|
|
import org.springframework.boot.origin.OriginLookup;
|
|
|
|
|
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
|
import org.springframework.boot.test.context.runner.ContextConsumer;
|
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.mock.env.MockPropertySource;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.assertj.core.api.Assertions.entry;
|
|
|
|
@ -281,6 +285,23 @@ class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void originParents() {
|
|
|
|
|
this.contextRunner.withUserConfiguration(SensiblePropertiesConfiguration.class)
|
|
|
|
|
.withInitializer(this::initializeOriginParents).run(assertProperties("sensible", (properties) -> {
|
|
|
|
|
}, (inputs) -> {
|
|
|
|
|
Map<String, Object> stringInputs = (Map<String, Object>) inputs.get("string");
|
|
|
|
|
String[] originParents = (String[]) stringInputs.get("originParents");
|
|
|
|
|
assertThat(originParents).containsExactly("spring", "boot");
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initializeOriginParents(ConfigurableApplicationContext context) {
|
|
|
|
|
MockPropertySource propertySource = new OriginParentMockPropertySource();
|
|
|
|
|
propertySource.setProperty("sensible.string", "spring");
|
|
|
|
|
context.getEnvironment().getPropertySources().addFirst(propertySource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ContextConsumer<AssertableApplicationContext> assertProperties(String prefix,
|
|
|
|
|
Consumer<Map<String, Object>> properties) {
|
|
|
|
|
return assertProperties(prefix, properties, (inputs) -> {
|
|
|
|
@ -310,6 +331,38 @@ class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
return prefix.equals(candidate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static class OriginParentMockPropertySource extends MockPropertySource implements OriginLookup<String> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Origin getOrigin(String key) {
|
|
|
|
|
return new MockOrigin(key, new MockOrigin("spring", new MockOrigin("boot", null)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static class MockOrigin implements Origin {
|
|
|
|
|
|
|
|
|
|
private final String value;
|
|
|
|
|
|
|
|
|
|
private final MockOrigin parent;
|
|
|
|
|
|
|
|
|
|
MockOrigin(String value, MockOrigin parent) {
|
|
|
|
|
this.value = value;
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Origin getParent() {
|
|
|
|
|
return this.parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
return this.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
|
static class EndpointConfig {
|
|
|
|
|
|
|
|
|
@ -649,6 +702,8 @@ class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
@ConfigurationProperties("sensible")
|
|
|
|
|
public static class SensibleProperties {
|
|
|
|
|
|
|
|
|
|
private String string;
|
|
|
|
|
|
|
|
|
|
private URI sensitiveUri = URI.create("http://user:password@localhost:8080");
|
|
|
|
|
|
|
|
|
|
private URI noPasswordUri = URI.create("http://user:@localhost:8080");
|
|
|
|
@ -666,6 +721,14 @@ class ConfigurationPropertiesReportEndpointTests {
|
|
|
|
|
this.listOfListItems.add(Collections.singletonList(new ListItem()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setString(String string) {
|
|
|
|
|
this.string = string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getString() {
|
|
|
|
|
return this.string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setSensitiveUri(URI sensitiveUri) {
|
|
|
|
|
this.sensitiveUri = sensitiveUri;
|
|
|
|
|
}
|
|
|
|
|