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:
2heunxun
2026-08-25 11:43:49 -07:00
committed by Phillip Webb
parent 67d7523f52
commit d5ace369bd
2 changed files with 14 additions and 1 deletions
@@ -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);
}
}
@@ -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() {