|
|
|
@ -33,7 +33,6 @@ import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoint;
|
|
|
|
|
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
|
|
|
|
|
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint;
|
|
|
|
|
import org.springframework.boot.autoconfigure.security.servlet.RequestMatcherProvider;
|
|
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath;
|
|
|
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
|
|
|
import org.springframework.mock.web.MockServletContext;
|
|
|
|
|
import org.springframework.security.web.util.matcher.RequestMatcher;
|
|
|
|
@ -55,19 +54,19 @@ public class EndpointRequestTests {
|
|
|
|
|
@Test
|
|
|
|
|
public void toAnyEndpointShouldMatchEndpointPath() {
|
|
|
|
|
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/").matches("/actuator/foo");
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/").matches("/actuator/foo/zoo/");
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/").matches("/actuator/bar");
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/").matches("/actuator/bar/baz");
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/").matches("/actuator");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator/foo");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator/foo/zoo/");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator/bar");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator/bar/baz");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void toAnyEndpointShouldMatchEndpointPathWithTrailingSlash() {
|
|
|
|
|
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/").matches("/actuator/foo/");
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/").matches("/actuator/bar/");
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/").matches("/actuator/");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator/foo/");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator/bar/");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -85,26 +84,13 @@ public class EndpointRequestTests {
|
|
|
|
|
assertMatcher(matcher).doesNotMatch("/actuator/baz");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void toAnyEndpointWhenServletPathNotEmptyShouldMatch() {
|
|
|
|
|
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").matches("/spring",
|
|
|
|
|
"/actuator/foo");
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").matches("/spring",
|
|
|
|
|
"/actuator/bar");
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").matches("/spring", "/actuator");
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").doesNotMatch("/spring",
|
|
|
|
|
"/actuator/baz");
|
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").doesNotMatch("", "/actuator/foo");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void toAnyEndpointWhenDispatcherServletPathProviderNotAvailableUsesEmptyPath() {
|
|
|
|
|
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
|
|
|
|
|
assertMatcher(matcher, "/actuator", null).matches("/actuator/foo");
|
|
|
|
|
assertMatcher(matcher, "/actuator", null).matches("/actuator/bar");
|
|
|
|
|
assertMatcher(matcher, "/actuator", null).matches("/actuator");
|
|
|
|
|
assertMatcher(matcher, "/actuator", null).doesNotMatch("/actuator/baz");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator/foo");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator/bar");
|
|
|
|
|
assertMatcher(matcher, "/actuator").matches("/actuator");
|
|
|
|
|
assertMatcher(matcher, "/actuator").doesNotMatch("/actuator/baz");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -151,14 +137,6 @@ public class EndpointRequestTests {
|
|
|
|
|
assertMatcher.doesNotMatch("/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void toLinksWhenServletPathNotEmptyShouldMatch() {
|
|
|
|
|
RequestMatcher matcher = EndpointRequest.toLinks();
|
|
|
|
|
RequestMatcherAssert assertMatcher = assertMatcher(matcher, "/actuator",
|
|
|
|
|
"/spring");
|
|
|
|
|
assertMatcher.matches("/spring/actuator");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void excludeByClassShouldNotMatchExcluded() {
|
|
|
|
|
RequestMatcher matcher = EndpointRequest.toAnyEndpoint()
|
|
|
|
@ -221,7 +199,7 @@ public class EndpointRequestTests {
|
|
|
|
|
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
|
|
|
|
|
RequestMatcher mockRequestMatcher = (request) -> false;
|
|
|
|
|
RequestMatcherAssert assertMatcher = assertMatcher(matcher,
|
|
|
|
|
mockPathMappedEndpoints(""), "", (pattern) -> mockRequestMatcher);
|
|
|
|
|
mockPathMappedEndpoints(""), (pattern) -> mockRequestMatcher);
|
|
|
|
|
assertMatcher.doesNotMatch("/foo");
|
|
|
|
|
assertMatcher.doesNotMatch("/bar");
|
|
|
|
|
}
|
|
|
|
@ -231,8 +209,7 @@ public class EndpointRequestTests {
|
|
|
|
|
RequestMatcher matcher = EndpointRequest.toLinks();
|
|
|
|
|
RequestMatcher mockRequestMatcher = (request) -> false;
|
|
|
|
|
RequestMatcherAssert assertMatcher = assertMatcher(matcher,
|
|
|
|
|
mockPathMappedEndpoints("/actuator"), "",
|
|
|
|
|
(pattern) -> mockRequestMatcher);
|
|
|
|
|
mockPathMappedEndpoints("/actuator"), (pattern) -> mockRequestMatcher);
|
|
|
|
|
assertMatcher.doesNotMatch("/actuator");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -248,13 +225,7 @@ public class EndpointRequestTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RequestMatcherAssert assertMatcher(RequestMatcher matcher, String basePath) {
|
|
|
|
|
return assertMatcher(matcher, mockPathMappedEndpoints(basePath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RequestMatcherAssert assertMatcher(RequestMatcher matcher, String basePath,
|
|
|
|
|
String servletPath) {
|
|
|
|
|
return assertMatcher(matcher, mockPathMappedEndpoints(basePath), servletPath,
|
|
|
|
|
null);
|
|
|
|
|
return assertMatcher(matcher, mockPathMappedEndpoints(basePath), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PathMappedEndpoints mockPathMappedEndpoints(String basePath) {
|
|
|
|
@ -273,11 +244,11 @@ public class EndpointRequestTests {
|
|
|
|
|
|
|
|
|
|
private RequestMatcherAssert assertMatcher(RequestMatcher matcher,
|
|
|
|
|
PathMappedEndpoints pathMappedEndpoints) {
|
|
|
|
|
return assertMatcher(matcher, pathMappedEndpoints, "", null);
|
|
|
|
|
return assertMatcher(matcher, pathMappedEndpoints, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RequestMatcherAssert assertMatcher(RequestMatcher matcher,
|
|
|
|
|
PathMappedEndpoints pathMappedEndpoints, String dispatcherServletPath,
|
|
|
|
|
PathMappedEndpoints pathMappedEndpoints,
|
|
|
|
|
RequestMatcherProvider matcherProvider) {
|
|
|
|
|
StaticWebApplicationContext context = new StaticWebApplicationContext();
|
|
|
|
|
context.registerBean(WebEndpointProperties.class);
|
|
|
|
@ -289,10 +260,6 @@ public class EndpointRequestTests {
|
|
|
|
|
properties.setBasePath(pathMappedEndpoints.getBasePath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (dispatcherServletPath != null) {
|
|
|
|
|
DispatcherServletPath path = () -> dispatcherServletPath;
|
|
|
|
|
context.registerBean(DispatcherServletPath.class, () -> path);
|
|
|
|
|
}
|
|
|
|
|
if (matcherProvider != null) {
|
|
|
|
|
context.registerBean(RequestMatcherProvider.class, () -> matcherProvider);
|
|
|
|
|
}
|
|
|
|
@ -314,10 +281,6 @@ public class EndpointRequestTests {
|
|
|
|
|
matches(mockRequest(servletPath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void matches(String servletPath, String pathInfo) {
|
|
|
|
|
matches(mockRequest(servletPath, pathInfo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void matches(HttpServletRequest request) {
|
|
|
|
|
assertThat(this.matcher.matches(request))
|
|
|
|
|
.as("Matches " + getRequestPath(request)).isTrue();
|
|
|
|
@ -327,20 +290,12 @@ public class EndpointRequestTests {
|
|
|
|
|
doesNotMatch(mockRequest(servletPath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void doesNotMatch(String servletPath, String pathInfo) {
|
|
|
|
|
doesNotMatch(mockRequest(servletPath, pathInfo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void doesNotMatch(HttpServletRequest request) {
|
|
|
|
|
assertThat(this.matcher.matches(request))
|
|
|
|
|
.as("Does not match " + getRequestPath(request)).isFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MockHttpServletRequest mockRequest(String servletPath) {
|
|
|
|
|
return mockRequest(servletPath, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MockHttpServletRequest mockRequest(String servletPath, String path) {
|
|
|
|
|
MockServletContext servletContext = new MockServletContext();
|
|
|
|
|
servletContext.setAttribute(
|
|
|
|
|
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
|
|
|
|
@ -349,7 +304,6 @@ public class EndpointRequestTests {
|
|
|
|
|
if (servletPath != null) {
|
|
|
|
|
request.setServletPath(servletPath);
|
|
|
|
|
}
|
|
|
|
|
request.setPathInfo(path);
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|