Skip to content

Commit 68163a6

Browse files
committed
Change query in MongoHealthIndicator
This commit changes the query in MongoHealthIndicator from serverStatus to buildInfo to avoid unprivileged access and corresponding errors. fixes #1289
1 parent 7945b29 commit 68163a6

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Simple implementation of a {@link HealthIndicator} returning status information for
2626
* Mongo data stores.
27-
*
27+
*
2828
* @author Christian Dupuis
2929
* @since 1.1.0
3030
*/
@@ -39,7 +39,7 @@ public MongoHealthIndicator(MongoTemplate mongoTemplate) {
3939

4040
@Override
4141
protected void doHealthCheck(Health.Builder builder) throws Exception {
42-
CommandResult result = this.mongoTemplate.executeCommand("{ serverStatus: 1 }");
42+
CommandResult result = this.mongoTemplate.executeCommand("{ buildInfo: 1 }");
4343
builder.up().withDetail("version", result.getString("version"));
4444
}
4545

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
/**
3838
* Tests for {@link MongoHealthIndicator}.
39-
*
39+
*
4040
* @author Christian Dupuis
4141
*/
4242
public class MongoHealthIndicatorTests {
@@ -67,7 +67,7 @@ public void mongoIsUp() throws Exception {
6767
CommandResult commandResult = Mockito.mock(CommandResult.class);
6868
Mockito.when(commandResult.getString("version")).thenReturn("2.6.4");
6969
MongoTemplate mongoTemplate = Mockito.mock(MongoTemplate.class);
70-
Mockito.when(mongoTemplate.executeCommand("{ serverStatus: 1 }")).thenReturn(
70+
Mockito.when(mongoTemplate.executeCommand("{ buildInfo: 1 }")).thenReturn(
7171
commandResult);
7272
MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);
7373

@@ -76,13 +76,13 @@ public void mongoIsUp() throws Exception {
7676
assertEquals("2.6.4", health.getDetails().get("version"));
7777

7878
Mockito.verify(commandResult).getString("version");
79-
Mockito.verify(mongoTemplate).executeCommand("{ serverStatus: 1 }");
79+
Mockito.verify(mongoTemplate).executeCommand("{ buildInfo: 1 }");
8080
}
8181

8282
@Test
8383
public void mongoIsDown() throws Exception {
8484
MongoTemplate mongoTemplate = Mockito.mock(MongoTemplate.class);
85-
Mockito.when(mongoTemplate.executeCommand("{ serverStatus: 1 }")).thenThrow(
85+
Mockito.when(mongoTemplate.executeCommand("{ buildInfo: 1 }")).thenThrow(
8686
new MongoException("Connection failed"));
8787
MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);
8888

@@ -91,6 +91,6 @@ public void mongoIsDown() throws Exception {
9191
assertTrue(((String) health.getDetails().get("error"))
9292
.contains("Connection failed"));
9393

94-
Mockito.verify(mongoTemplate).executeCommand("{ serverStatus: 1 }");
94+
Mockito.verify(mongoTemplate).executeCommand("{ buildInfo: 1 }");
9595
}
9696
}

0 commit comments

Comments
 (0)