mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Fix LdapHealthIndicator reporting when LDAP version is unavailable
Fix regression caused by commit d26b6895 which caused
`doHealthCheck()` to only call `builder.up()` when the LDAP
server's protocol version (`java.naming.ldap.version`) could be
read from the JNDI environment.
See gh-51441
Signed-off-by: 2heunxun <seapeon@naver.com>
This commit is contained in:
+2
-1
@@ -50,8 +50,9 @@ public class LdapHealthIndicator extends AbstractHealthIndicator {
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
String version = this.ldapOperations.executeReadOnly(versionContextExecutor);
|
||||
builder.up();
|
||||
if (version != null) {
|
||||
builder.up().withDetail("version", version);
|
||||
builder.withDetail("version", version);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -49,6 +49,18 @@ class LdapHealthIndicatorTests {
|
||||
then(ldapTemplate).should().executeReadOnly((ContextExecutor<String>) any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void ldapIsUpWhenVersionIsUnavailable() {
|
||||
LdapTemplate ldapTemplate = mock(LdapTemplate.class);
|
||||
given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any())).willReturn(null);
|
||||
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
|
||||
Health health = healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).doesNotContainKey("version");
|
||||
then(ldapTemplate).should().executeReadOnly((ContextExecutor<String>) any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void ldapIsDown() {
|
||||
|
||||
Reference in New Issue
Block a user