Merge branch '2.1.x'

This commit is contained in:
Stephane Nicoll
2018-12-20 17:54:08 +01:00
19 changed files with 80 additions and 236 deletions

View File

@@ -19,7 +19,6 @@ package org.springframework.boot.actuate.endpoint.web.reactive;
import java.util.Arrays;
import org.junit.Test;
import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
@@ -44,9 +43,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.assertj.core.api.Assertions.assertThat;
@@ -148,20 +145,11 @@ public class WebFluxEndpointIntegrationTests extends
@Bean
public WebFilter webFilter() {
return new WebFilter() {
@Override
public Mono<Void> filter(ServerWebExchange exchange,
WebFilterChain chain) {
return chain.filter(exchange).subscriberContext(
ReactiveSecurityContextHolder.withAuthentication(
new UsernamePasswordAuthenticationToken("Alice",
"secret",
Arrays.asList(new SimpleGrantedAuthority(
"ROLE_ACTUATOR")))));
}
};
return (exchange, chain) -> chain.filter(exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(
new UsernamePasswordAuthenticationToken("Alice", "secret",
Arrays.asList(new SimpleGrantedAuthority(
"ROLE_ACTUATOR")))));
}
}

View File

@@ -33,9 +33,7 @@ import org.springframework.boot.actuate.trace.http.Include;
import org.springframework.boot.actuate.web.trace.reactive.HttpTraceWebFilter;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.ServerWebExchangeDecorator;
import org.springframework.web.server.WebFilterChain;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
@@ -62,14 +60,7 @@ public class HttpTraceWebFilterTests {
this.filter.filter(
MockServerWebExchange
.from(MockServerHttpRequest.get("https://api.example.com")),
new WebFilterChain() {
@Override
public Mono<Void> filter(ServerWebExchange exchange) {
return Mono.empty();
}
}).block(Duration.ofSeconds(30));
(exchange) -> Mono.empty()).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1);
}
@@ -79,15 +70,10 @@ public class HttpTraceWebFilterTests {
this.filter.filter(
MockServerWebExchange
.from(MockServerHttpRequest.get("https://api.example.com")),
new WebFilterChain() {
@Override
public Mono<Void> filter(ServerWebExchange exchange) {
exchange.getSession().block(Duration.ofSeconds(30))
.getAttributes().put("a", "alpha");
return Mono.empty();
}
(exchange) -> {
exchange.getSession().block(Duration.ofSeconds(30)).getAttributes()
.put("a", "alpha");
return Mono.empty();
}).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1);
Session session = this.repository.findAll().get(0).getSession();
@@ -101,14 +87,9 @@ public class HttpTraceWebFilterTests {
this.filter.filter(
MockServerWebExchange
.from(MockServerHttpRequest.get("https://api.example.com")),
new WebFilterChain() {
@Override
public Mono<Void> filter(ServerWebExchange exchange) {
exchange.getSession().block(Duration.ofSeconds(30));
return Mono.empty();
}
(exchange) -> {
exchange.getSession().block(Duration.ofSeconds(30));
return Mono.empty();
}).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1);
Session session = this.repository.findAll().get(0).getSession();
@@ -127,15 +108,10 @@ public class HttpTraceWebFilterTests {
return Mono.just(principal);
}
}, new WebFilterChain() {
@Override
public Mono<Void> filter(ServerWebExchange exchange) {
exchange.getSession().block(Duration.ofSeconds(30)).getAttributes()
.put("a", "alpha");
return Mono.empty();
}
}, (exchange) -> {
exchange.getSession().block(Duration.ofSeconds(30)).getAttributes().put("a",
"alpha");
return Mono.empty();
}).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1);
org.springframework.boot.actuate.trace.http.HttpTrace.Principal tracedPrincipal = this.repository
@@ -148,17 +124,11 @@ public class HttpTraceWebFilterTests {
public void statusIsAssumedToBe500WhenChainFails()
throws ServletException, IOException {
try {
this.filter.filter(
MockServerWebExchange
this.filter
.filter(MockServerWebExchange
.from(MockServerHttpRequest.get("https://api.example.com")),
new WebFilterChain() {
@Override
public Mono<Void> filter(ServerWebExchange exchange) {
return Mono.error(new RuntimeException());
}
}).block(Duration.ofSeconds(30));
(exchange) -> Mono.error(new RuntimeException()))
.block(Duration.ofSeconds(30));
fail();
}
catch (Exception ex) {