Change query in MongoHealthIndicator
This commit changes the query in MongoHealthIndicator from serverStatus to buildInfo to avoid unprivileged access and corresponding errors. fixes #1289
This commit is contained in:
parent
7945b29669
commit
68163a66a5
|
@ -24,7 +24,7 @@ import com.mongodb.CommandResult;
|
|||
/**
|
||||
* Simple implementation of a {@link HealthIndicator} returning status information for
|
||||
* Mongo data stores.
|
||||
*
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
* @since 1.1.0
|
||||
*/
|
||||
|
@ -39,7 +39,7 @@ public class MongoHealthIndicator extends AbstractHealthIndicator {
|
|||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
CommandResult result = this.mongoTemplate.executeCommand("{ serverStatus: 1 }");
|
||||
CommandResult result = this.mongoTemplate.executeCommand("{ buildInfo: 1 }");
|
||||
builder.up().withDetail("version", result.getString("version"));
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
/**
|
||||
* Tests for {@link MongoHealthIndicator}.
|
||||
*
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
*/
|
||||
public class MongoHealthIndicatorTests {
|
||||
|
@ -67,7 +67,7 @@ public class MongoHealthIndicatorTests {
|
|||
CommandResult commandResult = Mockito.mock(CommandResult.class);
|
||||
Mockito.when(commandResult.getString("version")).thenReturn("2.6.4");
|
||||
MongoTemplate mongoTemplate = Mockito.mock(MongoTemplate.class);
|
||||
Mockito.when(mongoTemplate.executeCommand("{ serverStatus: 1 }")).thenReturn(
|
||||
Mockito.when(mongoTemplate.executeCommand("{ buildInfo: 1 }")).thenReturn(
|
||||
commandResult);
|
||||
MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);
|
||||
|
||||
|
@ -76,13 +76,13 @@ public class MongoHealthIndicatorTests {
|
|||
assertEquals("2.6.4", health.getDetails().get("version"));
|
||||
|
||||
Mockito.verify(commandResult).getString("version");
|
||||
Mockito.verify(mongoTemplate).executeCommand("{ serverStatus: 1 }");
|
||||
Mockito.verify(mongoTemplate).executeCommand("{ buildInfo: 1 }");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mongoIsDown() throws Exception {
|
||||
MongoTemplate mongoTemplate = Mockito.mock(MongoTemplate.class);
|
||||
Mockito.when(mongoTemplate.executeCommand("{ serverStatus: 1 }")).thenThrow(
|
||||
Mockito.when(mongoTemplate.executeCommand("{ buildInfo: 1 }")).thenThrow(
|
||||
new MongoException("Connection failed"));
|
||||
MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);
|
||||
|
||||
|
@ -91,6 +91,6 @@ public class MongoHealthIndicatorTests {
|
|||
assertTrue(((String) health.getDetails().get("error"))
|
||||
.contains("Connection failed"));
|
||||
|
||||
Mockito.verify(mongoTemplate).executeCommand("{ serverStatus: 1 }");
|
||||
Mockito.verify(mongoTemplate).executeCommand("{ buildInfo: 1 }");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue