|
|
|
|
@ -29,9 +29,12 @@ import org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Sh
@@ -29,9 +29,12 @@ import org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Sh
|
|
|
|
|
import org.springframework.boot.actuate.endpoint.SecurityContext; |
|
|
|
|
import org.springframework.boot.actuate.health.HttpCodeStatusMapper; |
|
|
|
|
import org.springframework.boot.actuate.health.StatusAggregator; |
|
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static org.mockito.BDDMockito.given; |
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Tests for {@link AutoConfiguredHealthEndpointGroup}. |
|
|
|
|
@ -123,6 +126,30 @@ class AutoConfiguredHealthEndpointGroupTests {
@@ -123,6 +126,30 @@ class AutoConfiguredHealthEndpointGroupTests {
|
|
|
|
|
assertThat(group.showDetails(this.securityContext)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void showDetailsWhenShowDetailsIsWhenAuthorizedAndUserHasRightAuthorityReturnsTrue() { |
|
|
|
|
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
|
|
|
|
this.statusAggregator, this.httpCodeStatusMapper, null, Show.WHEN_AUTHORIZED, |
|
|
|
|
Arrays.asList("admin", "root", "bossmode")); |
|
|
|
|
Authentication principal = mock(Authentication.class); |
|
|
|
|
given(principal.getAuthorities()) |
|
|
|
|
.willAnswer((invocation) -> Collections.singleton(new SimpleGrantedAuthority("admin"))); |
|
|
|
|
given(this.securityContext.getPrincipal()).willReturn(principal); |
|
|
|
|
assertThat(group.showDetails(this.securityContext)).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void showDetailsWhenShowDetailsIsWhenAuthorizedAndUserDoesNotHaveRightAuthoritiesReturnsFalse() { |
|
|
|
|
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
|
|
|
|
this.statusAggregator, this.httpCodeStatusMapper, null, Show.WHEN_AUTHORIZED, |
|
|
|
|
Arrays.asList("admin", "rot", "bossmode")); |
|
|
|
|
Authentication principal = mock(Authentication.class); |
|
|
|
|
given(principal.getAuthorities()) |
|
|
|
|
.willAnswer((invocation) -> Collections.singleton(new SimpleGrantedAuthority("other"))); |
|
|
|
|
given(this.securityContext.getPrincipal()).willReturn(principal); |
|
|
|
|
assertThat(group.showDetails(this.securityContext)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void showComponentsWhenShowComponentsIsNullDelegatesToShowDetails() { |
|
|
|
|
AutoConfiguredHealthEndpointGroup alwaysGroup = new AutoConfiguredHealthEndpointGroup((name) -> true, |
|
|
|
|
@ -185,6 +212,30 @@ class AutoConfiguredHealthEndpointGroupTests {
@@ -185,6 +212,30 @@ class AutoConfiguredHealthEndpointGroupTests {
|
|
|
|
|
assertThat(group.showComponents(this.securityContext)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void showComponentsWhenShowComponentsIsWhenAuthorizedAndUserHasRightAuthoritiesReturnsTrue() { |
|
|
|
|
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
|
|
|
|
this.statusAggregator, this.httpCodeStatusMapper, Show.WHEN_AUTHORIZED, Show.NEVER, |
|
|
|
|
Arrays.asList("admin", "root", "bossmode")); |
|
|
|
|
Authentication principal = mock(Authentication.class); |
|
|
|
|
given(principal.getAuthorities()) |
|
|
|
|
.willAnswer((invocation) -> Collections.singleton(new SimpleGrantedAuthority("admin"))); |
|
|
|
|
given(this.securityContext.getPrincipal()).willReturn(principal); |
|
|
|
|
assertThat(group.showComponents(this.securityContext)).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void showComponentsWhenShowComponentsIsWhenAuthorizedAndUserDoesNotHaveRightAuthoritiesReturnsFalse() { |
|
|
|
|
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
|
|
|
|
this.statusAggregator, this.httpCodeStatusMapper, Show.WHEN_AUTHORIZED, Show.NEVER, |
|
|
|
|
Arrays.asList("admin", "rot", "bossmode")); |
|
|
|
|
Authentication principal = mock(Authentication.class); |
|
|
|
|
given(principal.getAuthorities()) |
|
|
|
|
.willAnswer((invocation) -> Collections.singleton(new SimpleGrantedAuthority("other"))); |
|
|
|
|
given(this.securityContext.getPrincipal()).willReturn(principal); |
|
|
|
|
assertThat(group.showComponents(this.securityContext)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void getStatusAggregatorReturnsStatusAggregator() { |
|
|
|
|
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
|
|
|
|
|