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