Skip to content

Commit 37bef96

Browse files
committed
Merge branch '1.5.x'
2 parents 0ba6342 + 5a8a863 commit 37bef96

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ private void getNames(PropertySources propertySources, NameCallback callback) {
9292

9393
@Override
9494
protected Object getOptionalValue(Environment source, String name) {
95-
Object result = ((EnvironmentEndpoint) getDelegate()).getResolver()
96-
.getProperty(name, Object.class);
95+
Object result = getValue(name);
9796
if (result != null) {
9897
result = ((EnvironmentEndpoint) getDelegate()).sanitize(name, result);
9998
}
@@ -102,13 +101,18 @@ protected Object getOptionalValue(Environment source, String name) {
102101

103102
@Override
104103
protected Object getValue(Environment source, String name) {
105-
Object result = source.getProperty(name, Object.class);
104+
Object result = getValue(name);
106105
if (result == null) {
107106
throw new NoSuchPropertyException("No such property: " + name);
108107
}
109108
return ((EnvironmentEndpoint) getDelegate()).sanitize(name, result);
110109
}
111110

111+
private Object getValue(String name) {
112+
return ((EnvironmentEndpoint) getDelegate()).getResolver().getProperty(name,
113+
Object.class);
114+
}
115+
112116
}
113117

114118
/**

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedPrope
146146
map.put("my.foo", "${my.bar}");
147147
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
148148
.addFirst(new MapPropertySource("unresolved-placeholder", map));
149-
this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk())
149+
this.mvc.perform(get("/application/env/my.foo")).andExpect(status().isOk())
150150
.andExpect(content().string(containsString("\"my.foo\":\"${my.bar}\"")));
151151
}
152152

@@ -155,6 +155,29 @@ public void nestedPathWithSensitivePlaceholderShouldSanitize() throws Exception
155155
Map<String, Object> map = new HashMap<>();
156156
map.put("my.foo", "${my.password}");
157157
map.put("my.password", "hello");
158+
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
159+
.addFirst(new MapPropertySource("placeholder", map));
160+
this.mvc.perform(get("/application/env/my.foo")).andExpect(status().isOk())
161+
.andExpect(content().string(containsString("\"my.foo\":\"******\"")));
162+
}
163+
164+
@Test
165+
public void nestedPathMatchedByRegexWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty()
166+
throws Exception {
167+
Map<String, Object> map = new HashMap<String, Object>();
168+
map.put("my.foo", "${my.bar}");
169+
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
170+
.addFirst(new MapPropertySource("unresolved-placeholder", map));
171+
this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk())
172+
.andExpect(content().string(containsString("\"my.foo\":\"${my.bar}\"")));
173+
}
174+
175+
@Test
176+
public void nestedPathMatchedByRegexWithSensitivePlaceholderShouldSanitize()
177+
throws Exception {
178+
Map<String, Object> map = new HashMap<String, Object>();
179+
map.put("my.foo", "${my.password}");
180+
map.put("my.password", "hello");
158181
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
159182
.addFirst(new MapPropertySource("placeholder", map));
160183
this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk())

0 commit comments

Comments
 (0)