Merge branch '1.5.x'
This commit is contained in:
commit
37bef961ea
|
|
@ -92,8 +92,7 @@ public class EnvironmentMvcEndpoint extends EndpointMvcAdapter
|
|||
|
||||
@Override
|
||||
protected Object getOptionalValue(Environment source, String name) {
|
||||
Object result = ((EnvironmentEndpoint) getDelegate()).getResolver()
|
||||
.getProperty(name, Object.class);
|
||||
Object result = getValue(name);
|
||||
if (result != null) {
|
||||
result = ((EnvironmentEndpoint) getDelegate()).sanitize(name, result);
|
||||
}
|
||||
|
|
@ -102,13 +101,18 @@ public class EnvironmentMvcEndpoint extends EndpointMvcAdapter
|
|||
|
||||
@Override
|
||||
protected Object getValue(Environment source, String name) {
|
||||
Object result = source.getProperty(name, Object.class);
|
||||
Object result = getValue(name);
|
||||
if (result == null) {
|
||||
throw new NoSuchPropertyException("No such property: " + name);
|
||||
}
|
||||
return ((EnvironmentEndpoint) getDelegate()).sanitize(name, result);
|
||||
}
|
||||
|
||||
private Object getValue(String name) {
|
||||
return ((EnvironmentEndpoint) getDelegate()).getResolver().getProperty(name,
|
||||
Object.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ public class EnvironmentMvcEndpointTests {
|
|||
map.put("my.foo", "${my.bar}");
|
||||
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
|
||||
.addFirst(new MapPropertySource("unresolved-placeholder", map));
|
||||
this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk())
|
||||
this.mvc.perform(get("/application/env/my.foo")).andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("\"my.foo\":\"${my.bar}\"")));
|
||||
}
|
||||
|
||||
|
|
@ -155,6 +155,29 @@ public class EnvironmentMvcEndpointTests {
|
|||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("my.foo", "${my.password}");
|
||||
map.put("my.password", "hello");
|
||||
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
|
||||
.addFirst(new MapPropertySource("placeholder", map));
|
||||
this.mvc.perform(get("/application/env/my.foo")).andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("\"my.foo\":\"******\"")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedPathMatchedByRegexWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty()
|
||||
throws Exception {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("my.foo", "${my.bar}");
|
||||
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
|
||||
.addFirst(new MapPropertySource("unresolved-placeholder", map));
|
||||
this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("\"my.foo\":\"${my.bar}\"")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedPathMatchedByRegexWithSensitivePlaceholderShouldSanitize()
|
||||
throws Exception {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("my.foo", "${my.password}");
|
||||
map.put("my.password", "hello");
|
||||
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
|
||||
.addFirst(new MapPropertySource("placeholder", map));
|
||||
this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk())
|
||||
|
|
|
|||
Loading…
Reference in New Issue