|
|
@ -17,6 +17,8 @@
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.security.servlet;
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.security.servlet;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@ -76,23 +78,23 @@ public class EndpointRequestTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void toAnyEndpointWhenServletPathNotEmptyShouldMatch() {
|
|
|
|
public void toAnyEndpointWhenServletPathNotEmptyShouldMatch() {
|
|
|
|
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
|
|
|
|
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").matches("/spring",
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring", "/admin").matches("/actuator/foo",
|
|
|
|
"/actuator/foo");
|
|
|
|
"/spring", "/admin");
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").matches("/spring",
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring", "/admin").matches("/actuator/bar",
|
|
|
|
"/actuator/bar");
|
|
|
|
"/spring", "/admin");
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").matches("/spring", "/actuator");
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").matches("/actuator", "/spring");
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").doesNotMatch("/spring",
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").doesNotMatch("/actuator/baz",
|
|
|
|
"/actuator/baz");
|
|
|
|
"/spring");
|
|
|
|
assertMatcher(matcher, "/actuator", "/spring").doesNotMatch("", "/actuator/foo");
|
|
|
|
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", (String) null).matches("/actuator/foo");
|
|
|
|
assertMatcher(matcher, "/actuator", null).matches("/actuator/bar");
|
|
|
|
assertMatcher(matcher, "/actuator", (String) null).matches("/actuator/bar");
|
|
|
|
assertMatcher(matcher, "/actuator", null).matches("/actuator");
|
|
|
|
assertMatcher(matcher, "/actuator", (String) null).matches("/actuator");
|
|
|
|
assertMatcher(matcher, "/actuator", null).doesNotMatch("/actuator/baz");
|
|
|
|
assertMatcher(matcher, "/actuator", (String) null).doesNotMatch("/actuator/baz");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -219,8 +221,8 @@ public class EndpointRequestTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private RequestMatcherAssert assertMatcher(RequestMatcher matcher, String basePath,
|
|
|
|
private RequestMatcherAssert assertMatcher(RequestMatcher matcher, String basePath,
|
|
|
|
String servletPath) {
|
|
|
|
String... servletPaths) {
|
|
|
|
return assertMatcher(matcher, mockPathMappedEndpoints(basePath), servletPath);
|
|
|
|
return assertMatcher(matcher, mockPathMappedEndpoints(basePath), servletPaths);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private PathMappedEndpoints mockPathMappedEndpoints(String basePath) {
|
|
|
|
private PathMappedEndpoints mockPathMappedEndpoints(String basePath) {
|
|
|
@ -243,7 +245,7 @@ public class EndpointRequestTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private RequestMatcherAssert assertMatcher(RequestMatcher matcher,
|
|
|
|
private RequestMatcherAssert assertMatcher(RequestMatcher matcher,
|
|
|
|
PathMappedEndpoints pathMappedEndpoints, String servletPath) {
|
|
|
|
PathMappedEndpoints pathMappedEndpoints, String... servletPaths) {
|
|
|
|
StaticWebApplicationContext context = new StaticWebApplicationContext();
|
|
|
|
StaticWebApplicationContext context = new StaticWebApplicationContext();
|
|
|
|
context.registerBean(WebEndpointProperties.class);
|
|
|
|
context.registerBean(WebEndpointProperties.class);
|
|
|
|
if (pathMappedEndpoints != null) {
|
|
|
|
if (pathMappedEndpoints != null) {
|
|
|
@ -254,8 +256,9 @@ public class EndpointRequestTests {
|
|
|
|
properties.setBasePath(pathMappedEndpoints.getBasePath());
|
|
|
|
properties.setBasePath(pathMappedEndpoints.getBasePath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (servletPath != null) {
|
|
|
|
if (servletPaths != null) {
|
|
|
|
DispatcherServletPathProvider pathProvider = () -> servletPath;
|
|
|
|
DispatcherServletPathProvider pathProvider = () -> new LinkedHashSet<>(
|
|
|
|
|
|
|
|
Arrays.asList(servletPaths));
|
|
|
|
context.registerBean(DispatcherServletPathProvider.class, () -> pathProvider);
|
|
|
|
context.registerBean(DispatcherServletPathProvider.class, () -> pathProvider);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return assertThat(new RequestMatcherAssert(context, matcher));
|
|
|
|
return assertThat(new RequestMatcherAssert(context, matcher));
|
|
|
@ -276,8 +279,8 @@ public class EndpointRequestTests {
|
|
|
|
matches(mockRequest(servletPath));
|
|
|
|
matches(mockRequest(servletPath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void matches(String servletPath, String pathInfo) {
|
|
|
|
public void matches(String pathInfo, String... servletPaths) {
|
|
|
|
matches(mockRequest(servletPath, pathInfo));
|
|
|
|
Arrays.stream(servletPaths).forEach((p) -> matches(mockRequest(p, pathInfo)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void matches(HttpServletRequest request) {
|
|
|
|
private void matches(HttpServletRequest request) {
|
|
|
|