|
25 | 25 | import org.mockito.Mock;
|
26 | 26 | import org.mockito.MockitoAnnotations;
|
27 | 27 |
|
28 |
| -import org.springframework.boot.actuate.autoconfigure.health.HealthProperties.ShowDetails; |
| 28 | +import org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Show; |
29 | 29 | import org.springframework.boot.actuate.endpoint.SecurityContext;
|
30 | 30 | import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
|
31 | 31 | import org.springframework.boot.actuate.health.StatusAggregator;
|
@@ -60,80 +60,142 @@ void setup() {
|
60 | 60 | @Test
|
61 | 61 | void isMemberWhenMemberPredicateMatchesAcceptsTrue() {
|
62 | 62 | AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> name.startsWith("a"),
|
63 |
| - this.statusAggregator, this.httpCodeStatusMapper, ShowDetails.ALWAYS, Collections.emptySet()); |
| 63 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.ALWAYS, Collections.emptySet()); |
64 | 64 | assertThat(group.isMember("albert")).isTrue();
|
65 | 65 | assertThat(group.isMember("arnold")).isTrue();
|
66 | 66 | }
|
67 | 67 |
|
68 | 68 | @Test
|
69 | 69 | void isMemberWhenMemberPredicateRejectsReturnsTrue() {
|
70 | 70 | AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> name.startsWith("a"),
|
71 |
| - this.statusAggregator, this.httpCodeStatusMapper, ShowDetails.ALWAYS, Collections.emptySet()); |
| 71 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.ALWAYS, Collections.emptySet()); |
72 | 72 | assertThat(group.isMember("bert")).isFalse();
|
73 | 73 | assertThat(group.isMember("ernie")).isFalse();
|
74 | 74 | }
|
75 | 75 |
|
76 | 76 | @Test
|
77 |
| - void includeDetailsWhenShowDetailsIsNeverReturnsFalse() { |
| 77 | + void showDetailsWhenShowDetailsIsNeverReturnsFalse() { |
78 | 78 | AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true,
|
79 |
| - this.statusAggregator, this.httpCodeStatusMapper, ShowDetails.NEVER, Collections.emptySet()); |
80 |
| - assertThat(group.includeDetails(SecurityContext.NONE)).isFalse(); |
| 79 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.NEVER, Collections.emptySet()); |
| 80 | + assertThat(group.showDetails(SecurityContext.NONE)).isFalse(); |
81 | 81 | }
|
82 | 82 |
|
83 | 83 | @Test
|
84 |
| - void includeDetailsWhenShowDetailsIsAlwaysReturnsTrue() { |
| 84 | + void showDetailsWhenShowDetailsIsAlwaysReturnsTrue() { |
85 | 85 | AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true,
|
86 |
| - this.statusAggregator, this.httpCodeStatusMapper, ShowDetails.ALWAYS, Collections.emptySet()); |
87 |
| - assertThat(group.includeDetails(SecurityContext.NONE)).isTrue(); |
| 86 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.ALWAYS, Collections.emptySet()); |
| 87 | + assertThat(group.showDetails(SecurityContext.NONE)).isTrue(); |
88 | 88 | }
|
89 | 89 |
|
90 | 90 | @Test
|
91 |
| - void includeDetailsWhenShowDetailsIsWhenAuthorizedAndPrincipalIsNullReturnsFalse() { |
| 91 | + void showDetailsWhenShowDetailsIsWhenAuthorizedAndPrincipalIsNullReturnsFalse() { |
92 | 92 | AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true,
|
93 |
| - this.statusAggregator, this.httpCodeStatusMapper, ShowDetails.WHEN_AUTHORIZED, Collections.emptySet()); |
| 93 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.WHEN_AUTHORIZED, Collections.emptySet()); |
94 | 94 | given(this.securityContext.getPrincipal()).willReturn(null);
|
95 |
| - assertThat(group.includeDetails(this.securityContext)).isFalse(); |
| 95 | + assertThat(group.showDetails(this.securityContext)).isFalse(); |
96 | 96 | }
|
97 | 97 |
|
98 | 98 | @Test
|
99 |
| - void includeDetailsWhenShowDetailsIsWhenAuthorizedAndRolesAreEmptyReturnsTrue() { |
| 99 | + void showDetailsWhenShowDetailsIsWhenAuthorizedAndRolesAreEmptyReturnsTrue() { |
100 | 100 | AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true,
|
101 |
| - this.statusAggregator, this.httpCodeStatusMapper, ShowDetails.WHEN_AUTHORIZED, Collections.emptySet()); |
| 101 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.WHEN_AUTHORIZED, Collections.emptySet()); |
102 | 102 | given(this.securityContext.getPrincipal()).willReturn(this.principal);
|
103 |
| - assertThat(group.includeDetails(this.securityContext)).isTrue(); |
| 103 | + assertThat(group.showDetails(this.securityContext)).isTrue(); |
104 | 104 | }
|
105 | 105 |
|
106 | 106 | @Test
|
107 |
| - void includeDetailsWhenShowDetailsIsWhenAuthorizedAndUseIsInRoleReturnsTrue() { |
| 107 | + void showDetailsWhenShowDetailsIsWhenAuthorizedAndUseIsInRoleReturnsTrue() { |
108 | 108 | AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true,
|
109 |
| - this.statusAggregator, this.httpCodeStatusMapper, ShowDetails.WHEN_AUTHORIZED, |
| 109 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.WHEN_AUTHORIZED, |
110 | 110 | Arrays.asList("admin", "root", "bossmode"));
|
111 | 111 | given(this.securityContext.getPrincipal()).willReturn(this.principal);
|
112 | 112 | given(this.securityContext.isUserInRole("root")).willReturn(true);
|
113 |
| - assertThat(group.includeDetails(this.securityContext)).isTrue(); |
| 113 | + assertThat(group.showDetails(this.securityContext)).isTrue(); |
114 | 114 | }
|
115 | 115 |
|
116 | 116 | @Test
|
117 |
| - void includeDetailsWhenShowDetailsIsWhenAuthorizedAndUseIsNotInRoleReturnsFalse() { |
| 117 | + void showDetailsWhenShowDetailsIsWhenAuthorizedAndUseIsNotInRoleReturnsFalse() { |
118 | 118 | AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true,
|
119 |
| - this.statusAggregator, this.httpCodeStatusMapper, ShowDetails.WHEN_AUTHORIZED, |
| 119 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.WHEN_AUTHORIZED, |
120 | 120 | Arrays.asList("admin", "rot", "bossmode"));
|
121 | 121 | given(this.securityContext.getPrincipal()).willReturn(this.principal);
|
122 | 122 | given(this.securityContext.isUserInRole("root")).willReturn(true);
|
123 |
| - assertThat(group.includeDetails(this.securityContext)).isFalse(); |
| 123 | + assertThat(group.showDetails(this.securityContext)).isFalse(); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + void showComponentsWhenShowComponentsIsNullDelegatesToShowDetails() { |
| 128 | + AutoConfiguredHealthEndpointGroup alwaysGroup = new AutoConfiguredHealthEndpointGroup((name) -> true, |
| 129 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.ALWAYS, Collections.emptySet()); |
| 130 | + assertThat(alwaysGroup.showComponents(SecurityContext.NONE)).isTrue(); |
| 131 | + AutoConfiguredHealthEndpointGroup neverGroup = new AutoConfiguredHealthEndpointGroup((name) -> true, |
| 132 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.NEVER, Collections.emptySet()); |
| 133 | + assertThat(neverGroup.showComponents(SecurityContext.NONE)).isFalse(); |
| 134 | + } |
| 135 | + |
| 136 | + @Test |
| 137 | + void showComponentsWhenShowDetailsIsNeverReturnsFalse() { |
| 138 | + AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
| 139 | + this.statusAggregator, this.httpCodeStatusMapper, Show.NEVER, Show.ALWAYS, Collections.emptySet()); |
| 140 | + assertThat(group.showComponents(SecurityContext.NONE)).isFalse(); |
| 141 | + } |
| 142 | + |
| 143 | + @Test |
| 144 | + void showComponentsWhenShowDetailsIsAlwaysReturnsTrue() { |
| 145 | + AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
| 146 | + this.statusAggregator, this.httpCodeStatusMapper, Show.ALWAYS, Show.NEVER, Collections.emptySet()); |
| 147 | + assertThat(group.showComponents(SecurityContext.NONE)).isTrue(); |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + void showComponentsWhenShowDetailsIsWhenAuthorizedAndPrincipalIsNullReturnsFalse() { |
| 152 | + AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
| 153 | + this.statusAggregator, this.httpCodeStatusMapper, Show.WHEN_AUTHORIZED, Show.NEVER, |
| 154 | + Collections.emptySet()); |
| 155 | + given(this.securityContext.getPrincipal()).willReturn(null); |
| 156 | + assertThat(group.showComponents(this.securityContext)).isFalse(); |
| 157 | + } |
| 158 | + |
| 159 | + @Test |
| 160 | + void showComponentsWhenShowDetailsIsWhenAuthorizedAndRolesAreEmptyReturnsTrue() { |
| 161 | + AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
| 162 | + this.statusAggregator, this.httpCodeStatusMapper, Show.WHEN_AUTHORIZED, Show.NEVER, |
| 163 | + Collections.emptySet()); |
| 164 | + given(this.securityContext.getPrincipal()).willReturn(this.principal); |
| 165 | + assertThat(group.showComponents(this.securityContext)).isTrue(); |
| 166 | + } |
| 167 | + |
| 168 | + @Test |
| 169 | + void showComponentsWhenShowDetailsIsWhenAuthorizedAndUseIsInRoleReturnsTrue() { |
| 170 | + AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
| 171 | + this.statusAggregator, this.httpCodeStatusMapper, Show.WHEN_AUTHORIZED, Show.NEVER, |
| 172 | + Arrays.asList("admin", "root", "bossmode")); |
| 173 | + given(this.securityContext.getPrincipal()).willReturn(this.principal); |
| 174 | + given(this.securityContext.isUserInRole("root")).willReturn(true); |
| 175 | + assertThat(group.showComponents(this.securityContext)).isTrue(); |
| 176 | + } |
| 177 | + |
| 178 | + @Test |
| 179 | + void showComponentsWhenShowDetailsIsWhenAuthorizedAndUseIsNotInRoleReturnsFalse() { |
| 180 | + AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true, |
| 181 | + this.statusAggregator, this.httpCodeStatusMapper, Show.WHEN_AUTHORIZED, Show.NEVER, |
| 182 | + Arrays.asList("admin", "rot", "bossmode")); |
| 183 | + given(this.securityContext.getPrincipal()).willReturn(this.principal); |
| 184 | + given(this.securityContext.isUserInRole("root")).willReturn(true); |
| 185 | + assertThat(group.showComponents(this.securityContext)).isFalse(); |
124 | 186 | }
|
125 | 187 |
|
126 | 188 | @Test
|
127 | 189 | void getStatusAggregatorReturnsStatusAggregator() {
|
128 | 190 | AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true,
|
129 |
| - this.statusAggregator, this.httpCodeStatusMapper, ShowDetails.ALWAYS, Collections.emptySet()); |
| 191 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.ALWAYS, Collections.emptySet()); |
130 | 192 | assertThat(group.getStatusAggregator()).isSameAs(this.statusAggregator);
|
131 | 193 | }
|
132 | 194 |
|
133 | 195 | @Test
|
134 | 196 | void getHttpCodeStatusMapperReturnsHttpCodeStatusMapper() {
|
135 | 197 | AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true,
|
136 |
| - this.statusAggregator, this.httpCodeStatusMapper, ShowDetails.ALWAYS, Collections.emptySet()); |
| 198 | + this.statusAggregator, this.httpCodeStatusMapper, null, Show.ALWAYS, Collections.emptySet()); |
137 | 199 | assertThat(group.getHttpCodeStatusMapper()).isSameAs(this.httpCodeStatusMapper);
|
138 | 200 | }
|
139 | 201 |
|
|
0 commit comments