@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mock ;
import org.mockito.MockitoAnnotations ;
import org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Show Details ;
import org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Show ;
import org.springframework.boot.actuate.endpoint.SecurityContext ;
import org.springframework.boot.actuate.health.HttpCodeStatusMapper ;
import org.springframework.boot.actuate.health.StatusAggregator ;
@ -60,7 +60,7 @@ class AutoConfiguredHealthEndpointGroupTests {
@Test
void isMemberWhenMemberPredicateMatchesAcceptsTrue ( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > name . startsWith ( "a" ) ,
this . statusAggregator , this . httpCodeStatusMapper , Show Details . ALWAYS , Collections . emptySet ( ) ) ;
this . statusAggregator , this . httpCodeStatusMapper , null , Show . ALWAYS , Collections . emptySet ( ) ) ;
assertThat ( group . isMember ( "albert" ) ) . isTrue ( ) ;
assertThat ( group . isMember ( "arnold" ) ) . isTrue ( ) ;
}
@ -68,72 +68,134 @@ class AutoConfiguredHealthEndpointGroupTests {
@Test
void isMemberWhenMemberPredicateRejectsReturnsTrue ( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > name . startsWith ( "a" ) ,
this . statusAggregator , this . httpCodeStatusMapper , Show Details . ALWAYS , Collections . emptySet ( ) ) ;
this . statusAggregator , this . httpCodeStatusMapper , null , Show . ALWAYS , Collections . emptySet ( ) ) ;
assertThat ( group . isMember ( "bert" ) ) . isFalse ( ) ;
assertThat ( group . isMember ( "ernie" ) ) . isFalse ( ) ;
}
@Test
void include DetailsWhenShowDetailsIsNeverReturnsFalse( ) {
void show DetailsWhenShowDetailsIsNeverReturnsFalse( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show Details . NEVER , Collections . emptySet ( ) ) ;
assertThat ( group . include Details( SecurityContext . NONE ) ) . isFalse ( ) ;
this . statusAggregator , this . httpCodeStatusMapper , null , Show . NEVER , Collections . emptySet ( ) ) ;
assertThat ( group . show Details( SecurityContext . NONE ) ) . isFalse ( ) ;
}
@Test
void include DetailsWhenShowDetailsIsAlwaysReturnsTrue( ) {
void show DetailsWhenShowDetailsIsAlwaysReturnsTrue( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show Details . ALWAYS , Collections . emptySet ( ) ) ;
assertThat ( group . include Details( SecurityContext . NONE ) ) . isTrue ( ) ;
this . statusAggregator , this . httpCodeStatusMapper , null , Show . ALWAYS , Collections . emptySet ( ) ) ;
assertThat ( group . show Details( SecurityContext . NONE ) ) . isTrue ( ) ;
}
@Test
void include DetailsWhenShowDetailsIsWhenAuthorizedAndPrincipalIsNullReturnsFalse( ) {
void show DetailsWhenShowDetailsIsWhenAuthorizedAndPrincipalIsNullReturnsFalse( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show Details . WHEN_AUTHORIZED , Collections . emptySet ( ) ) ;
this . statusAggregator , this . httpCodeStatusMapper , null , Show . WHEN_AUTHORIZED , Collections . emptySet ( ) ) ;
given ( this . securityContext . getPrincipal ( ) ) . willReturn ( null ) ;
assertThat ( group . include Details( this . securityContext ) ) . isFalse ( ) ;
assertThat ( group . show Details( this . securityContext ) ) . isFalse ( ) ;
}
@Test
void include DetailsWhenShowDetailsIsWhenAuthorizedAndRolesAreEmptyReturnsTrue( ) {
void show DetailsWhenShowDetailsIsWhenAuthorizedAndRolesAreEmptyReturnsTrue( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show Details . WHEN_AUTHORIZED , Collections . emptySet ( ) ) ;
this . statusAggregator , this . httpCodeStatusMapper , null , Show . WHEN_AUTHORIZED , Collections . emptySet ( ) ) ;
given ( this . securityContext . getPrincipal ( ) ) . willReturn ( this . principal ) ;
assertThat ( group . include Details( this . securityContext ) ) . isTrue ( ) ;
assertThat ( group . show Details( this . securityContext ) ) . isTrue ( ) ;
}
@Test
void include DetailsWhenShowDetailsIsWhenAuthorizedAndUseIsInRoleReturnsTrue( ) {
void show DetailsWhenShowDetailsIsWhenAuthorizedAndUseIsInRoleReturnsTrue( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show Details . WHEN_AUTHORIZED ,
this . statusAggregator , this . httpCodeStatusMapper , null , Show . WHEN_AUTHORIZED ,
Arrays . asList ( "admin" , "root" , "bossmode" ) ) ;
given ( this . securityContext . getPrincipal ( ) ) . willReturn ( this . principal ) ;
given ( this . securityContext . isUserInRole ( "root" ) ) . willReturn ( true ) ;
assertThat ( group . include Details( this . securityContext ) ) . isTrue ( ) ;
assertThat ( group . show Details( this . securityContext ) ) . isTrue ( ) ;
}
@Test
void include DetailsWhenShowDetailsIsWhenAuthorizedAndUseIsNotInRoleReturnsFalse( ) {
void show DetailsWhenShowDetailsIsWhenAuthorizedAndUseIsNotInRoleReturnsFalse( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show Details . WHEN_AUTHORIZED ,
this . statusAggregator , this . httpCodeStatusMapper , null , Show . WHEN_AUTHORIZED ,
Arrays . asList ( "admin" , "rot" , "bossmode" ) ) ;
given ( this . securityContext . getPrincipal ( ) ) . willReturn ( this . principal ) ;
given ( this . securityContext . isUserInRole ( "root" ) ) . willReturn ( true ) ;
assertThat ( group . includeDetails ( this . securityContext ) ) . isFalse ( ) ;
assertThat ( group . showDetails ( this . securityContext ) ) . isFalse ( ) ;
}
@Test
void showComponentsWhenShowComponentsIsNullDelegatesToShowDetails ( ) {
AutoConfiguredHealthEndpointGroup alwaysGroup = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , null , Show . ALWAYS , Collections . emptySet ( ) ) ;
assertThat ( alwaysGroup . showComponents ( SecurityContext . NONE ) ) . isTrue ( ) ;
AutoConfiguredHealthEndpointGroup neverGroup = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , null , Show . NEVER , Collections . emptySet ( ) ) ;
assertThat ( neverGroup . showComponents ( SecurityContext . NONE ) ) . isFalse ( ) ;
}
@Test
void showComponentsWhenShowDetailsIsNeverReturnsFalse ( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show . NEVER , Show . ALWAYS , Collections . emptySet ( ) ) ;
assertThat ( group . showComponents ( SecurityContext . NONE ) ) . isFalse ( ) ;
}
@Test
void showComponentsWhenShowDetailsIsAlwaysReturnsTrue ( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show . ALWAYS , Show . NEVER , Collections . emptySet ( ) ) ;
assertThat ( group . showComponents ( SecurityContext . NONE ) ) . isTrue ( ) ;
}
@Test
void showComponentsWhenShowDetailsIsWhenAuthorizedAndPrincipalIsNullReturnsFalse ( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show . WHEN_AUTHORIZED , Show . NEVER ,
Collections . emptySet ( ) ) ;
given ( this . securityContext . getPrincipal ( ) ) . willReturn ( null ) ;
assertThat ( group . showComponents ( this . securityContext ) ) . isFalse ( ) ;
}
@Test
void showComponentsWhenShowDetailsIsWhenAuthorizedAndRolesAreEmptyReturnsTrue ( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show . WHEN_AUTHORIZED , Show . NEVER ,
Collections . emptySet ( ) ) ;
given ( this . securityContext . getPrincipal ( ) ) . willReturn ( this . principal ) ;
assertThat ( group . showComponents ( this . securityContext ) ) . isTrue ( ) ;
}
@Test
void showComponentsWhenShowDetailsIsWhenAuthorizedAndUseIsInRoleReturnsTrue ( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show . WHEN_AUTHORIZED , Show . NEVER ,
Arrays . asList ( "admin" , "root" , "bossmode" ) ) ;
given ( this . securityContext . getPrincipal ( ) ) . willReturn ( this . principal ) ;
given ( this . securityContext . isUserInRole ( "root" ) ) . willReturn ( true ) ;
assertThat ( group . showComponents ( this . securityContext ) ) . isTrue ( ) ;
}
@Test
void showComponentsWhenShowDetailsIsWhenAuthorizedAndUseIsNotInRoleReturnsFalse ( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , Show . WHEN_AUTHORIZED , Show . NEVER ,
Arrays . asList ( "admin" , "rot" , "bossmode" ) ) ;
given ( this . securityContext . getPrincipal ( ) ) . willReturn ( this . principal ) ;
given ( this . securityContext . isUserInRole ( "root" ) ) . willReturn ( true ) ;
assertThat ( group . showComponents ( this . securityContext ) ) . isFalse ( ) ;
}
@Test
void getStatusAggregatorReturnsStatusAggregator ( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , ShowDetails . ALWAYS , Collections . emptySet ( ) ) ;
this . statusAggregator , this . httpCodeStatusMapper , null , Show . ALWAYS , Collections . emptySet ( ) ) ;
assertThat ( group . getStatusAggregator ( ) ) . isSameAs ( this . statusAggregator ) ;
}
@Test
void getHttpCodeStatusMapperReturnsHttpCodeStatusMapper ( ) {
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup ( ( name ) - > true ,
this . statusAggregator , this . httpCodeStatusMapper , ShowDetails . ALWAYS , Collections . emptySet ( ) ) ;
this . statusAggregator , this . httpCodeStatusMapper , null , Show . ALWAYS , Collections . emptySet ( ) ) ;
assertThat ( group . getHttpCodeStatusMapper ( ) ) . isSameAs ( this . httpCodeStatusMapper ) ;
}