More care taken with management.contextPath
The management.contextPath property should now be respected in a secure application, whether or not the management.port is different. Added some test cases in the sample to verify. Fixes gh-469
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package sample.actuator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -41,8 +43,6 @@ import org.springframework.security.crypto.codec.Base64;
|
||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Integration tests for endpoints configuration.
|
||||
*
|
||||
@@ -78,6 +78,12 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
|
||||
testError();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomContextPath() throws Exception {
|
||||
start(SampleActuatorApplication.class, "--management.contextPath=/admin");
|
||||
testHealth();
|
||||
}
|
||||
|
||||
private void testError() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = getRestTemplate("user", "password").getForEntity(
|
||||
@@ -89,6 +95,18 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
|
||||
assertEquals(999, body.get("status"));
|
||||
}
|
||||
|
||||
private void testHealth() {
|
||||
ResponseEntity<String> entity = getRestTemplate().getForEntity(
|
||||
"http://localhost:8080/admin/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
String body = entity.getBody();
|
||||
assertEquals("ok", body);
|
||||
}
|
||||
|
||||
private RestTemplate getRestTemplate() {
|
||||
return getRestTemplate(null, null);
|
||||
}
|
||||
|
||||
private RestTemplate getRestTemplate(final String username, final String password) {
|
||||
|
||||
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
|
||||
@@ -122,5 +140,4 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
|
||||
return restTemplate;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ManagementSampleActuatorApplicationTests {
|
||||
@BeforeClass
|
||||
public static void start() throws Exception {
|
||||
final String[] args = new String[] { "--server.port=" + port,
|
||||
"--management.port=" + managementPort, "--management.address=127.0.0.1" };
|
||||
"--management.port=" + managementPort, "--management.address=127.0.0.1", "--management.contextPath=/admin" };
|
||||
Future<ConfigurableApplicationContext> future = Executors
|
||||
.newSingleThreadExecutor().submit(
|
||||
new Callable<ConfigurableApplicationContext>() {
|
||||
@@ -82,7 +82,7 @@ public class ManagementSampleActuatorApplicationTests {
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = getRestTemplate().getForEntity(
|
||||
"http://localhost:" + managementPort + "/health", String.class);
|
||||
"http://localhost:" + managementPort + "/admin/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("ok", entity.getBody());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user