|
24 | 24 | import org.springframework.boot.actuate.endpoint.HealthEndpoint; |
25 | 25 | import org.springframework.boot.actuate.health.Health; |
26 | 26 | import org.springframework.boot.actuate.health.Status; |
| 27 | +import org.springframework.boot.test.util.EnvironmentTestUtils; |
27 | 28 | import org.springframework.core.env.MapPropertySource; |
28 | 29 | import org.springframework.core.env.PropertySource; |
29 | 30 | import org.springframework.http.HttpStatus; |
@@ -264,4 +265,45 @@ public void newValueIsReturnedOnceTtlExpires() throws InterruptedException { |
264 | 265 | assertThat(health.getStatus() == Status.DOWN).isTrue(); |
265 | 266 | } |
266 | 267 |
|
| 268 | + @Test |
| 269 | + public void detailIsHiddenWhenAllEndpointsAreSensitive() { |
| 270 | + EnvironmentTestUtils.addEnvironment(this.environment, "endpoints.sensitive:true"); |
| 271 | + this.mvc = new HealthMvcEndpoint(this.endpoint, false); |
| 272 | + this.mvc.setEnvironment(this.environment); |
| 273 | + given(this.endpoint.invoke()) |
| 274 | + .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); |
| 275 | + Object result = this.mvc.invoke(null); |
| 276 | + assertThat(result instanceof Health).isTrue(); |
| 277 | + assertThat(((Health) result).getStatus() == Status.UP).isTrue(); |
| 278 | + assertThat(((Health) result).getDetails().get("foo")).isNull(); |
| 279 | + } |
| 280 | + |
| 281 | + @Test |
| 282 | + public void detailIsHiddenWhenHealthEndpointIsSensitive() { |
| 283 | + EnvironmentTestUtils.addEnvironment(this.environment, |
| 284 | + "endpoints.health.sensitive:true"); |
| 285 | + this.mvc = new HealthMvcEndpoint(this.endpoint, false); |
| 286 | + this.mvc.setEnvironment(this.environment); |
| 287 | + given(this.endpoint.invoke()) |
| 288 | + .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); |
| 289 | + Object result = this.mvc.invoke(null); |
| 290 | + assertThat(result instanceof Health).isTrue(); |
| 291 | + assertThat(((Health) result).getStatus() == Status.UP).isTrue(); |
| 292 | + assertThat(((Health) result).getDetails().get("foo")).isNull(); |
| 293 | + } |
| 294 | + |
| 295 | + @Test |
| 296 | + public void detailIsHiddenWhenOnlyHealthEndpointIsSensitive() { |
| 297 | + EnvironmentTestUtils.addEnvironment(this.environment, |
| 298 | + "endpoints.health.sensitive:true", "endpoints.sensitive:false"); |
| 299 | + this.mvc = new HealthMvcEndpoint(this.endpoint, false); |
| 300 | + this.mvc.setEnvironment(this.environment); |
| 301 | + given(this.endpoint.invoke()) |
| 302 | + .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); |
| 303 | + Object result = this.mvc.invoke(null); |
| 304 | + assertThat(result instanceof Health).isTrue(); |
| 305 | + assertThat(((Health) result).getStatus() == Status.UP).isTrue(); |
| 306 | + assertThat(((Health) result).getDetails().get("foo")).isNull(); |
| 307 | + } |
| 308 | + |
267 | 309 | } |
0 commit comments