Merge branch '2.0.x'

pull/13933/head
Madhura Bhave 6 years ago
commit f2a9030788

@ -157,6 +157,14 @@ public final class EndpointRequest {
protected abstract RequestMatcher createDelegate(WebApplicationContext context, protected abstract RequestMatcher createDelegate(WebApplicationContext context,
RequestMatcherFactory requestMatcherFactory); RequestMatcherFactory requestMatcherFactory);
protected List<RequestMatcher> getLinksMatchers(
RequestMatcherFactory requestMatcherFactory, String basePath) {
List<RequestMatcher> linksMatchers = new ArrayList<>();
linksMatchers.add(requestMatcherFactory.antPath(basePath));
linksMatchers.add(requestMatcherFactory.antPath(basePath, "/"));
return linksMatchers;
}
} }
/** /**
@ -220,10 +228,10 @@ public final class EndpointRequest {
streamPaths(this.excludes, pathMappedEndpoints).forEach(paths::remove); streamPaths(this.excludes, pathMappedEndpoints).forEach(paths::remove);
List<RequestMatcher> delegateMatchers = getDelegateMatchers( List<RequestMatcher> delegateMatchers = getDelegateMatchers(
requestMatcherFactory, paths); requestMatcherFactory, paths);
if (this.includeLinks String basePath = pathMappedEndpoints.getBasePath();
&& StringUtils.hasText(pathMappedEndpoints.getBasePath())) { if (this.includeLinks && StringUtils.hasText(basePath)) {
delegateMatchers.add( delegateMatchers
requestMatcherFactory.antPath(pathMappedEndpoints.getBasePath())); .addAll(getLinksMatchers(requestMatcherFactory, basePath));
} }
return new OrRequestMatcher(delegateMatchers); return new OrRequestMatcher(delegateMatchers);
} }
@ -271,8 +279,10 @@ public final class EndpointRequest {
RequestMatcherFactory requestMatcherFactory) { RequestMatcherFactory requestMatcherFactory) {
WebEndpointProperties properties = context WebEndpointProperties properties = context
.getBean(WebEndpointProperties.class); .getBean(WebEndpointProperties.class);
if (StringUtils.hasText(properties.getBasePath())) { String basePath = properties.getBasePath();
return requestMatcherFactory.antPath(properties.getBasePath()); if (StringUtils.hasText(basePath)) {
return new OrRequestMatcher(
getLinksMatchers(requestMatcherFactory, basePath));
} }
return EMPTY_MATCHER; return EMPTY_MATCHER;
} }

@ -59,6 +59,14 @@ public class EndpointRequestTests {
assertMatcher(matcher).matches("/actuator"); assertMatcher(matcher).matches("/actuator");
} }
@Test
public void toAnyEndpointShouldMatchEndpointPathWithTrailingSlash() {
ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint();
assertMatcher(matcher).matches("/actuator/foo/");
assertMatcher(matcher).matches("/actuator/bar/");
assertMatcher(matcher).matches("/actuator/");
}
@Test @Test
public void toAnyEndpointWhenBasePathIsEmptyShouldNotMatchLinks() { public void toAnyEndpointWhenBasePathIsEmptyShouldNotMatchLinks() {
ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint(); ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint();
@ -104,6 +112,7 @@ public class EndpointRequestTests {
assertMatcher(matcher).doesNotMatch("/actuator/foo"); assertMatcher(matcher).doesNotMatch("/actuator/foo");
assertMatcher(matcher).doesNotMatch("/actuator/bar"); assertMatcher(matcher).doesNotMatch("/actuator/bar");
assertMatcher(matcher).matches("/actuator"); assertMatcher(matcher).matches("/actuator");
assertMatcher(matcher).matches("/actuator/");
} }
@Test @Test

@ -54,10 +54,20 @@ public class EndpointRequestTests {
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/bar"); assertMatcher(matcher, "/actuator", "/").matches("/actuator/bar");
assertMatcher(matcher, "/actuator", "/").matches("/actuator/bar/baz");
assertMatcher(matcher, "/actuator", "/").matches("/actuator"); 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/");
}
@Test @Test
public void toAnyEndpointWhenBasePathIsEmptyShouldNotMatchLinks() { public void toAnyEndpointWhenBasePathIsEmptyShouldNotMatchLinks() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint(); RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
@ -127,6 +137,7 @@ public class EndpointRequestTests {
assertMatcher(matcher).doesNotMatch("/actuator/foo"); assertMatcher(matcher).doesNotMatch("/actuator/foo");
assertMatcher(matcher).doesNotMatch("/actuator/bar"); assertMatcher(matcher).doesNotMatch("/actuator/bar");
assertMatcher(matcher).matches("/actuator"); assertMatcher(matcher).matches("/actuator");
assertMatcher(matcher).matches("/actuator/");
} }
@Test @Test

Loading…
Cancel
Save