Skip actuator path extension content negotiation

Allow `PathExtensionContentNegotiationStrategy` to be bypassed by
actuator endpoints. Prior to this commit calling `/loggers/com.aaa.cab`
would return a HTTP 406 response due to `.cab` being a known extension.

Fixes gh-8765
This commit is contained in:
Andy Wilkinson
2017-04-10 11:47:15 +01:00
committed by Phillip Webb
parent f3c45077ac
commit b9be0e3e0f
6 changed files with 116 additions and 13 deletions

View File

@@ -193,7 +193,7 @@ public class EndpointWebMvcAutoConfigurationTests {
.getBean(ManagementContextResolver.class).getApplicationContext();
List<?> interceptors = (List<?>) ReflectionTestUtils.getField(
managementContext.getBean(EndpointHandlerMapping.class), "interceptors");
assertThat(interceptors).hasSize(1);
assertThat(interceptors).hasSize(2);
}
@Test
@@ -211,7 +211,7 @@ public class EndpointWebMvcAutoConfigurationTests {
.getBean(ManagementContextResolver.class).getApplicationContext();
List<?> interceptors = (List<?>) ReflectionTestUtils.getField(
managementContext.getBean(EndpointHandlerMapping.class), "interceptors");
assertThat(interceptors).hasSize(1);
assertThat(interceptors).hasSize(2);
EmbeddedServletContainerFactory parentContainerFactory = this.applicationContext
.getBean(EmbeddedServletContainerFactory.class);
EmbeddedServletContainerFactory managementContainerFactory = managementContext
@@ -536,7 +536,7 @@ public class EndpointWebMvcAutoConfigurationTests {
.getBean(ManagementContextResolver.class).getApplicationContext();
List<?> interceptors = (List<?>) ReflectionTestUtils.getField(
managementContext.getBean(EndpointHandlerMapping.class), "interceptors");
assertThat(interceptors).hasSize(1);
assertThat(interceptors).hasSize(2);
ManagementServerProperties managementServerProperties = this.applicationContext
.getBean(ManagementServerProperties.class);
assertThat(managementServerProperties.getSsl()).isNotNull();
@@ -577,7 +577,7 @@ public class EndpointWebMvcAutoConfigurationTests {
.getBean(ManagementContextResolver.class).getApplicationContext();
List<?> interceptors = (List<?>) ReflectionTestUtils.getField(
managementContext.getBean(EndpointHandlerMapping.class), "interceptors");
assertThat(interceptors).hasSize(1);
assertThat(interceptors).hasSize(2);
ManagementServerProperties managementServerProperties = this.applicationContext
.getBean(ManagementServerProperties.class);
assertThat(managementServerProperties.getSsl()).isNotNull();

View File

@@ -60,7 +60,8 @@ public abstract class AbstractEndpointHandlerMappingTests {
Collections.singletonList(endpoint));
mapping.setApplicationContext(this.context);
mapping.afterPropertiesSet();
assertThat(mapping.getHandler(request("POST", "/a")).getInterceptors()).isNull();
assertThat(mapping.getHandler(request("POST", "/a")).getInterceptors())
.hasSize(1);
}
@Test
@@ -75,8 +76,8 @@ public abstract class AbstractEndpointHandlerMappingTests {
mapping.afterPropertiesSet();
MockHttpServletRequest request = request("POST", "/a");
request.addHeader("Origin", "http://example.com");
assertThat(mapping.getHandler(request).getInterceptors().length).isEqualTo(2);
assertThat(mapping.getHandler(request).getInterceptors()[1])
assertThat(mapping.getHandler(request).getInterceptors().length).isEqualTo(3);
assertThat(mapping.getHandler(request).getInterceptors()[2])
.isEqualTo(securityInterceptor);
}

View File

@@ -178,6 +178,16 @@ public class LoggersMvcEndpointTests {
verifyZeroInteractions(this.loggingSystem);
}
@Test
public void logLevelForLoggerWithNameThatCouldBeMistakenForAPathExtension()
throws Exception {
given(this.loggingSystem.getLoggerConfiguration("com.png"))
.willReturn(new LoggerConfiguration("com.png", null, LogLevel.DEBUG));
this.mvc.perform(get("/loggers/com.png")).andExpect(status().isOk())
.andExpect(content().string(equalTo(
"{\"configuredLevel\":null," + "\"effectiveLevel\":\"DEBUG\"}")));
}
@Configuration
@Import({ JacksonAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,

View File

@@ -125,6 +125,13 @@ public class MetricsMvcEndpointTests {
.andExpect(content().string(equalTo("{\"foo\":1}")));
}
@Test
public void specificMetricWithNameThatCouldBeMistakenForAPathExtension()
throws Exception {
this.mvc.perform(get("/metrics/bar.png")).andExpect(status().isOk())
.andExpect(content().string(equalTo("{\"bar.png\":1}")));
}
@Test
public void specificMetricWhenDisabled() throws Exception {
this.context.getBean(MetricsEndpoint.class).setEnabled(false);
@@ -138,7 +145,8 @@ public class MetricsMvcEndpointTests {
@Test
public void regexAll() throws Exception {
String expected = "\"foo\":1,\"group1.a\":1,\"group1.b\":1,\"group2.a\":1,\"group2_a\":1";
String expected = "\"foo\":1,\"bar.png\":1,\"group1.a\":1,\"group1.b\":1"
+ ",\"group2.a\":1,\"group2_a\":1";
this.mvc.perform(get("/metrics/.*")).andExpect(status().isOk())
.andExpect(content().string(containsString(expected)));
}
@@ -178,6 +186,7 @@ public class MetricsMvcEndpointTests {
public Collection<Metric<?>> metrics() {
ArrayList<Metric<?>> metrics = new ArrayList<Metric<?>>();
metrics.add(new Metric<Integer>("foo", 1));
metrics.add(new Metric<Integer>("bar.png", 1));
metrics.add(new Metric<Integer>("group1.a", 1));
metrics.add(new Metric<Integer>("group1.b", 1));
metrics.add(new Metric<Integer>("group2.a", 1));