|
|
@ -55,62 +55,51 @@ class SampleActuatorApplicationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testHomeIsSecure() {
|
|
|
|
void testHomeIsSecure() {
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class));
|
|
|
|
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class);
|
|
|
|
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
assertThat(entity.getBody().get("error")).isEqualTo("Unauthorized");
|
|
|
|
Map<String, Object> body = entity.getBody();
|
|
|
|
|
|
|
|
assertThat(body.get("error")).isEqualTo("Unauthorized");
|
|
|
|
|
|
|
|
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
|
|
|
|
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testMetricsIsSecure() {
|
|
|
|
void testMetricsIsSecure() {
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
ResponseEntity<Map<String, Object>> entity = asMapEntity(
|
|
|
|
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class);
|
|
|
|
this.restTemplate.getForEntity("/actuator/metrics", Map.class));
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
|
|
|
entity = this.restTemplate.getForEntity("/actuator/metrics/", Map.class);
|
|
|
|
entity = asMapEntity(this.restTemplate.getForEntity("/actuator/metrics/", Map.class));
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
|
|
|
entity = this.restTemplate.getForEntity("/actuator/metrics/foo", Map.class);
|
|
|
|
entity = asMapEntity(this.restTemplate.getForEntity("/actuator/metrics/foo", Map.class));
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
|
|
|
entity = this.restTemplate.getForEntity("/actuator/metrics.json", Map.class);
|
|
|
|
entity = asMapEntity(this.restTemplate.getForEntity("/actuator/metrics.json", Map.class));
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testHome() {
|
|
|
|
void testHome() {
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
ResponseEntity<Map<String, Object>> entity = asMapEntity(
|
|
|
|
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/",
|
|
|
|
this.restTemplate.withBasicAuth("user", "password").getForEntity("/", Map.class));
|
|
|
|
Map.class);
|
|
|
|
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil");
|
|
|
|
Map<String, Object> body = entity.getBody();
|
|
|
|
|
|
|
|
assertThat(body.get("message")).isEqualTo("Hello Phil");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
void testMetrics() {
|
|
|
|
void testMetrics() {
|
|
|
|
testHome(); // makes sure some requests have been made
|
|
|
|
testHome(); // makes sure some requests have been made
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
ResponseEntity<Map<String, Object>> entity = asMapEntity(
|
|
|
|
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword())
|
|
|
|
this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/metrics", Map.class));
|
|
|
|
.getForEntity("/actuator/metrics", Map.class);
|
|
|
|
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
Map<String, Object> body = entity.getBody();
|
|
|
|
assertThat(entity.getBody()).containsKey("names");
|
|
|
|
assertThat(body).containsKey("names");
|
|
|
|
List<String> names = (List<String>) entity.getBody().get("names");
|
|
|
|
assertThat((List<String>) body.get("names")).contains("jvm.buffer.count");
|
|
|
|
assertThat(names).contains("jvm.buffer.count");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testEnv() {
|
|
|
|
void testEnv() {
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
ResponseEntity<Map<String, Object>> entity = asMapEntity(
|
|
|
|
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword())
|
|
|
|
this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/env", Map.class));
|
|
|
|
.getForEntity("/actuator/env", Map.class);
|
|
|
|
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
assertThat(entity.getBody()).containsKey("propertySources");
|
|
|
|
Map<String, Object> body = entity.getBody();
|
|
|
|
|
|
|
|
assertThat(body).containsKey("propertySources");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -133,7 +122,7 @@ class SampleActuatorApplicationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testErrorPage() {
|
|
|
|
void testErrorPage() {
|
|
|
|
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/foo",
|
|
|
|
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password").getForEntity("/foo",
|
|
|
|
String.class);
|
|
|
|
String.class);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
String body = entity.getBody();
|
|
|
|
String body = entity.getBody();
|
|
|
@ -145,7 +134,7 @@ class SampleActuatorApplicationTests {
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
|
|
|
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
|
|
|
|
HttpEntity<?> request = new HttpEntity<Void>(headers);
|
|
|
|
HttpEntity<?> request = new HttpEntity<Void>(headers);
|
|
|
|
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/foo",
|
|
|
|
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password").exchange("/foo",
|
|
|
|
HttpMethod.GET, request, String.class);
|
|
|
|
HttpMethod.GET, request, String.class);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
String body = entity.getBody();
|
|
|
|
String body = entity.getBody();
|
|
|
@ -155,32 +144,26 @@ class SampleActuatorApplicationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testErrorPageDirectAccess() {
|
|
|
|
void testErrorPageDirectAccess() {
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
ResponseEntity<Map<String, Object>> entity = asMapEntity(
|
|
|
|
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/error",
|
|
|
|
this.restTemplate.withBasicAuth("user", "password").getForEntity("/error", Map.class));
|
|
|
|
Map.class);
|
|
|
|
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
assertThat(entity.getBody().get("error")).isEqualTo("None");
|
|
|
|
Map<String, Object> body = entity.getBody();
|
|
|
|
assertThat(entity.getBody().get("status")).isEqualTo(999);
|
|
|
|
assertThat(body.get("error")).isEqualTo("None");
|
|
|
|
|
|
|
|
assertThat(body.get("status")).isEqualTo(999);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
|
|
|
void testBeans() {
|
|
|
|
void testBeans() {
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
ResponseEntity<Map<String, Object>> entity = asMapEntity(
|
|
|
|
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword())
|
|
|
|
this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/beans", Map.class));
|
|
|
|
.getForEntity("/actuator/beans", Map.class);
|
|
|
|
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
assertThat(entity.getBody()).containsOnlyKeys("contexts");
|
|
|
|
assertThat(entity.getBody()).containsOnlyKeys("contexts");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
void testConfigProps() {
|
|
|
|
void testConfigProps() {
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
ResponseEntity<Map<String, Object>> entity = asMapEntity(
|
|
|
|
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword())
|
|
|
|
this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/configprops", Map.class));
|
|
|
|
.getForEntity("/actuator/configprops", Map.class);
|
|
|
|
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
Map<String, Object> body = entity.getBody();
|
|
|
|
Map<String, Object> body = entity.getBody();
|
|
|
|
Map<String, Object> contexts = (Map<String, Object>) body.get("contexts");
|
|
|
|
Map<String, Object> contexts = (Map<String, Object>) body.get("contexts");
|
|
|
@ -191,17 +174,15 @@ class SampleActuatorApplicationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testLegacy() {
|
|
|
|
void testLegacy() {
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
ResponseEntity<Map<String, Object>> entity = asMapEntity(
|
|
|
|
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword())
|
|
|
|
this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/legacy", Map.class));
|
|
|
|
.getForEntity("/actuator/legacy", Map.class);
|
|
|
|
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
assertThat(entity.getBody()).contains(entry("legacy", "legacy"));
|
|
|
|
Map<String, Object> body = entity.getBody();
|
|
|
|
|
|
|
|
assertThat(body).contains(entry("legacy", "legacy"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getPassword() {
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
|
|
return "password";
|
|
|
|
static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
|
|
|
|
|
|
|
|
return (ResponseEntity) entity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|