Switch show details default to ShowDetails.NEVER

Closes gh-11869
pull/12149/head
Phillip Webb 7 years ago
parent 46021928ba
commit 349987d9be

@ -34,7 +34,7 @@ public class HealthEndpointProperties {
/** /**
* When to show full health details. * When to show full health details.
*/ */
private ShowDetails showDetails = ShowDetails.WHEN_AUTHORIZED; private ShowDetails showDetails = ShowDetails.NEVER;
/** /**
* Roles used to determine whether or not a user is authorized to be shown details. * Roles used to determine whether or not a user is authorized to be shown details.

@ -90,17 +90,34 @@ public class HealthEndpointWebExtensionTests {
} }
@Test @Test
public void authenticatedUsersAreShownDetailsByDefault() { public void authenticatedUsersAreNotShownDetailsByDefault() {
this.contextRunner.run((context) -> { this.contextRunner.run((context) -> {
HealthEndpointWebExtension extension = context HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class); .getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class); SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal()).willReturn(mock(Principal.class)); given(securityContext.getPrincipal()).willReturn(mock(Principal.class));
assertThat(extension.getHealth(securityContext).getBody().getDetails()) assertThat(extension.getHealth(securityContext).getBody().getDetails())
.isNotEmpty(); .isEmpty();
}); });
} }
@Test
public void authenticatedUsersWhenAuthorizedCanBeShownDetails() {
this.contextRunner
.withPropertyValues(
"management.endpoint.health.show-details=when-authorized")
.run((context) -> {
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
assertThat(
extension.getHealth(securityContext).getBody().getDetails())
.isNotEmpty();
});
}
@Test @Test
public void unauthenticatedUsersCanBeShownDetails() { public void unauthenticatedUsersCanBeShownDetails() {
this.contextRunner this.contextRunner

@ -86,7 +86,9 @@ public class ReactiveHealthEndpointWebExtensionTests {
@Test @Test
public void regularAndReactiveHealthIndicatorsMatch() { public void regularAndReactiveHealthIndicatorsMatch() {
this.contextRunner.withUserConfiguration(HealthIndicatorsConfiguration.class) this.contextRunner
.withPropertyValues("management.endpoint.health.show-details=always")
.withUserConfiguration(HealthIndicatorsConfiguration.class)
.run((context) -> { .run((context) -> {
HealthEndpoint endpoint = context.getBean(HealthEndpoint.class); HealthEndpoint endpoint = context.getBean(HealthEndpoint.class);
ReactiveHealthEndpointWebExtension extension = context ReactiveHealthEndpointWebExtension extension = context
@ -115,17 +117,33 @@ public class ReactiveHealthEndpointWebExtensionTests {
} }
@Test @Test
public void authenticatedUsersAreShownDetailsByDefault() { public void authenticatedUsersAreNotShownDetailsByDefault() {
this.contextRunner.run((context) -> { this.contextRunner.run((context) -> {
ReactiveHealthEndpointWebExtension extension = context ReactiveHealthEndpointWebExtension extension = context
.getBean(ReactiveHealthEndpointWebExtension.class); .getBean(ReactiveHealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class); SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal()).willReturn(mock(Principal.class)); given(securityContext.getPrincipal()).willReturn(mock(Principal.class));
assertThat(extension.health(securityContext).block().getBody().getDetails()) assertThat(extension.health(securityContext).block().getBody().getDetails())
.isNotEmpty(); .isEmpty();
}); });
} }
@Test
public void authenticatedUsersWhenAuthorizedCanBeShownDetails() {
this.contextRunner
.withPropertyValues(
"management.endpoint.health.show-details=when-authorized")
.run((context) -> {
ReactiveHealthEndpointWebExtension extension = context
.getBean(ReactiveHealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
assertThat(extension.health(securityContext).block().getBody()
.getDetails()).isNotEmpty();
});
}
@Test @Test
public void unauthenticatedUsersCanBeShownDetails() { public void unauthenticatedUsersCanBeShownDetails() {
this.contextRunner this.contextRunner

@ -531,7 +531,7 @@ following values:
|Details are shown to all users. |Details are shown to all users.
|=== |===
The default value is `when-authorized`. A user is considered to be authorized when they The default value is `never`. A user is considered to be authorized when they
are in one or more of the endpoint's roles. If the endpoint has no configured roles are in one or more of the endpoint's roles. If the endpoint has no configured roles
(the default) all authenticated users are considered to be authorized. The roles can (the default) all authenticated users are considered to be authorized. The roles can
be configured using the `management.endpoint.health.roles` property. be configured using the `management.endpoint.health.roles` property.

Loading…
Cancel
Save