Merge branch '4.0.x'

Closes gh-49944
This commit is contained in:
Brian Clozel
2026-04-07 17:09:21 +02:00
4 changed files with 58 additions and 6 deletions
@@ -310,17 +310,17 @@ public final class EndpointRequest {
public EndpointServerWebExchangeMatcher excluding(Class<?>... endpoints) {
List<Object> excludes = new ArrayList<>(this.excludes);
excludes.addAll(Arrays.asList((Object[]) endpoints));
return new EndpointServerWebExchangeMatcher(this.includes, excludes, this.includeLinks, null);
return new EndpointServerWebExchangeMatcher(this.includes, excludes, this.includeLinks, this.httpMethod);
}
public EndpointServerWebExchangeMatcher excluding(String... endpoints) {
List<Object> excludes = new ArrayList<>(this.excludes);
excludes.addAll(Arrays.asList((Object[]) endpoints));
return new EndpointServerWebExchangeMatcher(this.includes, excludes, this.includeLinks, null);
return new EndpointServerWebExchangeMatcher(this.includes, excludes, this.includeLinks, this.httpMethod);
}
public EndpointServerWebExchangeMatcher excludingLinks() {
return new EndpointServerWebExchangeMatcher(this.includes, this.excludes, false, null);
return new EndpointServerWebExchangeMatcher(this.includes, this.excludes, false, this.httpMethod);
}
/**
@@ -318,17 +318,17 @@ public final class EndpointRequest {
public EndpointRequestMatcher excluding(Class<?>... endpoints) {
List<Object> excludes = new ArrayList<>(this.excludes);
excludes.addAll(Arrays.asList((Object[]) endpoints));
return new EndpointRequestMatcher(this.includes, excludes, this.includeLinks, null);
return new EndpointRequestMatcher(this.includes, excludes, this.includeLinks, this.httpMethod);
}
public EndpointRequestMatcher excluding(String... endpoints) {
List<Object> excludes = new ArrayList<>(this.excludes);
excludes.addAll(Arrays.asList((Object[]) endpoints));
return new EndpointRequestMatcher(this.includes, excludes, this.includeLinks, null);
return new EndpointRequestMatcher(this.includes, excludes, this.includeLinks, this.httpMethod);
}
public EndpointRequestMatcher excludingLinks() {
return new EndpointRequestMatcher(this.includes, this.excludes, false, null);
return new EndpointRequestMatcher(this.includes, this.excludes, false, this.httpMethod);
}
/**
@@ -236,6 +236,33 @@ class EndpointRequestTests {
assertMatcher.matches("/bar/");
}
@Test
void toAnyEndpointWithHttpMethodExcludingShouldPreserveHttpMethod() {
ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint()
.withHttpMethod(HttpMethod.POST)
.excluding(FooEndpoint.class)
.excluding("baz");
List<ExposableEndpoint<?>> endpoints = new ArrayList<>();
endpoints.add(mockEndpoint(EndpointId.of("foo"), "foo"));
endpoints.add(mockEndpoint(EndpointId.of("bar"), "bar"));
endpoints.add(mockEndpoint(EndpointId.of("baz"), "baz"));
PathMappedEndpoints pathMappedEndpoints = new PathMappedEndpoints("/actuator", () -> endpoints);
assertMatcher(matcher, pathMappedEndpoints).matches(HttpMethod.POST, "/actuator/bar");
assertMatcher(matcher, pathMappedEndpoints).doesNotMatch(HttpMethod.GET, "/actuator/bar");
assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/foo");
assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/baz");
}
@Test
void toAnyEndpointWithHttpMethodExcludingLinksShouldPreserveHttpMethod() {
ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint()
.withHttpMethod(HttpMethod.POST)
.excludingLinks();
assertMatcher(matcher).matches(HttpMethod.POST, "/actuator/foo");
assertMatcher(matcher).doesNotMatch(HttpMethod.GET, "/actuator/foo");
assertMatcher(matcher).doesNotMatch("/actuator");
}
@Test
void noEndpointPathsBeansShouldNeverMatch() {
ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint();
@@ -223,6 +223,31 @@ class EndpointRequestTests {
assertMatcher.matches("/bar");
}
@Test
void toAnyEndpointWithHttpMethodExcludingShouldPreserveHttpMethod() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint()
.withHttpMethod(HttpMethod.POST)
.excluding(FooEndpoint.class)
.excluding("baz");
List<ExposableEndpoint<?>> endpoints = new ArrayList<>();
endpoints.add(mockEndpoint(EndpointId.of("foo"), "foo"));
endpoints.add(mockEndpoint(EndpointId.of("bar"), "bar"));
endpoints.add(mockEndpoint(EndpointId.of("baz"), "baz"));
PathMappedEndpoints pathMappedEndpoints = new PathMappedEndpoints("/actuator", () -> endpoints);
assertMatcher(matcher, pathMappedEndpoints).matches(HttpMethod.POST, "/actuator/bar");
assertMatcher(matcher, pathMappedEndpoints).doesNotMatch(HttpMethod.GET, "/actuator/bar");
assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/foo");
assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/baz");
}
@Test
void toAnyEndpointWithHttpMethodExcludingLinksShouldPreserveHttpMethod() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint().withHttpMethod(HttpMethod.POST).excludingLinks();
assertMatcher(matcher).matches(HttpMethod.POST, "/actuator/foo");
assertMatcher(matcher).doesNotMatch(HttpMethod.GET, "/actuator/foo");
assertMatcher(matcher).doesNotMatch("/actuator");
}
@Test
void endpointRequestMatcherShouldUseCustomRequestMatcherProvider() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();