Adapt to API change in Spring Framework 5.3.0 snapshots
See gh-23534
This commit is contained in:
parent
f4ce77fcae
commit
de32fab324
|
|
@ -67,7 +67,6 @@ import org.springframework.security.web.server.WebFilterChainProxy;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
@ -270,7 +269,7 @@ class ReactiveCloudFoundryActuatorAutoConfigurationTests {
|
||||||
"cloudFoundrySecurityService");
|
"cloudFoundrySecurityService");
|
||||||
WebClient webClient = (WebClient) ReflectionTestUtils.getField(interceptorSecurityService,
|
WebClient webClient = (WebClient) ReflectionTestUtils.getField(interceptorSecurityService,
|
||||||
"webClient");
|
"webClient");
|
||||||
webClient.get().uri("https://self-signed.badssl.com/").exchangeToMono(ClientResponse::releaseBody)
|
webClient.get().uri("https://self-signed.badssl.com/").retrieve().toBodilessEntity()
|
||||||
.block(Duration.ofSeconds(30));
|
.block(Duration.ofSeconds(30));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -288,8 +287,8 @@ class ReactiveCloudFoundryActuatorAutoConfigurationTests {
|
||||||
WebClient webClient = (WebClient) ReflectionTestUtils.getField(interceptorSecurityService,
|
WebClient webClient = (WebClient) ReflectionTestUtils.getField(interceptorSecurityService,
|
||||||
"webClient");
|
"webClient");
|
||||||
assertThatExceptionOfType(RuntimeException.class)
|
assertThatExceptionOfType(RuntimeException.class)
|
||||||
.isThrownBy(() -> webClient.get().uri("https://self-signed.badssl.com/")
|
.isThrownBy(() -> webClient.get().uri("https://self-signed.badssl.com/").retrieve()
|
||||||
.exchangeToMono(ClientResponse::releaseBody).block(Duration.ofSeconds(30)))
|
.toBodilessEntity().block(Duration.ofSeconds(30)))
|
||||||
.withCauseInstanceOf(SSLException.class);
|
.withCauseInstanceOf(SSLException.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.client.reactive.ClientHttpConnector;
|
import org.springframework.http.client.reactive.ClientHttpConnector;
|
||||||
import org.springframework.mock.http.client.reactive.MockClientHttpResponse;
|
import org.springframework.mock.http.client.reactive.MockClientHttpResponse;
|
||||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
@ -112,7 +111,7 @@ class WebClientMetricsConfigurationTests {
|
||||||
WebClient webClient = mockWebClient(context.getBean(WebClient.Builder.class));
|
WebClient webClient = mockWebClient(context.getBean(WebClient.Builder.class));
|
||||||
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
webClient.get().uri("https://example.org/projects/" + i).exchangeToMono(ClientResponse::releaseBody)
|
webClient.get().uri("https://example.org/projects/" + i).retrieve().toBodilessEntity()
|
||||||
.block(Duration.ofSeconds(30));
|
.block(Duration.ofSeconds(30));
|
||||||
}
|
}
|
||||||
return registry;
|
return registry;
|
||||||
|
|
@ -121,8 +120,8 @@ class WebClientMetricsConfigurationTests {
|
||||||
private void validateWebClient(WebClient.Builder builder, MeterRegistry registry) {
|
private void validateWebClient(WebClient.Builder builder, MeterRegistry registry) {
|
||||||
WebClient webClient = mockWebClient(builder);
|
WebClient webClient = mockWebClient(builder);
|
||||||
assertThat(registry.find("http.client.requests").meter()).isNull();
|
assertThat(registry.find("http.client.requests").meter()).isNull();
|
||||||
webClient.get().uri("https://example.org/projects/{project}", "spring-boot")
|
webClient.get().uri("https://example.org/projects/{project}", "spring-boot").retrieve().toBodilessEntity()
|
||||||
.exchangeToMono(ClientResponse::releaseBody).block(Duration.ofSeconds(30));
|
.block(Duration.ofSeconds(30));
|
||||||
assertThat(registry.find("http.client.requests").tags("uri", "/projects/{project}").meter()).isNotNull();
|
assertThat(registry.find("http.client.requests").tags("uri", "/projects/{project}").meter()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,6 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||||
import org.springframework.util.SocketUtils;
|
import org.springframework.util.SocketUtils;
|
||||||
import org.springframework.util.unit.DataSize;
|
import org.springframework.util.unit.DataSize;
|
||||||
import org.springframework.web.reactive.function.BodyInserters;
|
import org.springframework.web.reactive.function.BodyInserters;
|
||||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
import org.springframework.web.reactive.function.client.WebClientRequestException;
|
import org.springframework.web.reactive.function.client.WebClientRequestException;
|
||||||
|
|
||||||
|
|
@ -282,16 +281,14 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||||
@Test
|
@Test
|
||||||
protected void compressionOfResponseToGetRequest() {
|
protected void compressionOfResponseToGetRequest() {
|
||||||
WebClient client = prepareCompressionTest();
|
WebClient client = prepareCompressionTest();
|
||||||
ResponseEntity<Void> response = client.get().exchangeToMono(ClientResponse::toBodilessEntity)
|
ResponseEntity<Void> response = client.get().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
|
||||||
.block(Duration.ofSeconds(30));
|
|
||||||
assertResponseIsCompressed(response);
|
assertResponseIsCompressed(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
protected void compressionOfResponseToPostRequest() {
|
protected void compressionOfResponseToPostRequest() {
|
||||||
WebClient client = prepareCompressionTest();
|
WebClient client = prepareCompressionTest();
|
||||||
ResponseEntity<Void> response = client.post().exchangeToMono(ClientResponse::toBodilessEntity)
|
ResponseEntity<Void> response = client.post().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
|
||||||
.block(Duration.ofSeconds(30));
|
|
||||||
assertResponseIsCompressed(response);
|
assertResponseIsCompressed(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -301,8 +298,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||||
compression.setEnabled(true);
|
compression.setEnabled(true);
|
||||||
compression.setMinResponseSize(DataSize.ofBytes(3001));
|
compression.setMinResponseSize(DataSize.ofBytes(3001));
|
||||||
WebClient client = prepareCompressionTest(compression);
|
WebClient client = prepareCompressionTest(compression);
|
||||||
ResponseEntity<Void> response = client.get().exchangeToMono(ClientResponse::toBodilessEntity)
|
ResponseEntity<Void> response = client.get().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
|
||||||
.block(Duration.ofSeconds(30));
|
|
||||||
assertResponseIsNotCompressed(response);
|
assertResponseIsNotCompressed(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -312,8 +308,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||||
compression.setEnabled(true);
|
compression.setEnabled(true);
|
||||||
compression.setMimeTypes(new String[] { "application/json" });
|
compression.setMimeTypes(new String[] { "application/json" });
|
||||||
WebClient client = prepareCompressionTest(compression);
|
WebClient client = prepareCompressionTest(compression);
|
||||||
ResponseEntity<Void> response = client.get().exchangeToMono(ClientResponse::toBodilessEntity)
|
ResponseEntity<Void> response = client.get().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
|
||||||
.block(Duration.ofSeconds(30));
|
|
||||||
assertResponseIsNotCompressed(response);
|
assertResponseIsNotCompressed(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -323,8 +318,8 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||||
compression.setEnabled(true);
|
compression.setEnabled(true);
|
||||||
compression.setExcludedUserAgents(new String[] { "testUserAgent" });
|
compression.setExcludedUserAgents(new String[] { "testUserAgent" });
|
||||||
WebClient client = prepareCompressionTest(compression);
|
WebClient client = prepareCompressionTest(compression);
|
||||||
ResponseEntity<Void> response = client.get().header("User-Agent", "testUserAgent")
|
ResponseEntity<Void> response = client.get().header("User-Agent", "testUserAgent").retrieve().toBodilessEntity()
|
||||||
.exchangeToMono(ClientResponse::toBodilessEntity).block(Duration.ofSeconds(30));
|
.block(Duration.ofSeconds(30));
|
||||||
assertResponseIsNotCompressed(response);
|
assertResponseIsNotCompressed(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -334,8 +329,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||||
compression.setEnabled(true);
|
compression.setEnabled(true);
|
||||||
compression.setMimeTypes(new String[] { "application/json" });
|
compression.setMimeTypes(new String[] { "application/json" });
|
||||||
WebClient client = prepareCompressionTest(compression, "test~plain");
|
WebClient client = prepareCompressionTest(compression, "test~plain");
|
||||||
ResponseEntity<Void> response = client.get().exchangeToMono(ClientResponse::toBodilessEntity)
|
ResponseEntity<Void> response = client.get().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
|
||||||
.block(Duration.ofSeconds(30));
|
|
||||||
assertResponseIsNotCompressed(response);
|
assertResponseIsNotCompressed(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,12 @@ import java.time.Duration;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import reactor.util.function.Tuples;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.web.server.LocalServerPort;
|
import org.springframework.boot.web.server.LocalServerPort;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseCookie;
|
|
||||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
@ -47,19 +46,25 @@ class SampleSessionWebFluxApplicationTests {
|
||||||
private WebClient.Builder webClientBuilder;
|
private WebClient.Builder webClientBuilder;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void userDefinedMappingsSecureByDefault() throws Exception {
|
void userDefinedMappingsSecureByDefault() {
|
||||||
WebClient webClient = this.webClientBuilder.baseUrl("http://localhost:" + this.port + "/").build();
|
WebClient client = this.webClientBuilder.baseUrl("http://localhost:" + this.port + "/").build();
|
||||||
ClientResponse response = webClient.get().header("Authorization", getBasicAuth()).exchange()
|
client.get().header("Authorization", getBasicAuth()).exchangeToMono((response) -> {
|
||||||
.block(Duration.ofSeconds(30));
|
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
|
||||||
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
|
return response.bodyToMono(String.class)
|
||||||
ResponseCookie sessionCookie = response.cookies().getFirst("SESSION");
|
.map((sessionId) -> Tuples.of(response.cookies().getFirst("SESSION").getValue(), sessionId));
|
||||||
String sessionId = response.bodyToMono(String.class).block(Duration.ofSeconds(30));
|
}).flatMap((tuple) -> {
|
||||||
response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30));
|
String sesssionCookie = tuple.getT1();
|
||||||
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
|
return client.get().cookie("SESSION", sesssionCookie).exchangeToMono((response) -> {
|
||||||
assertThat(response.bodyToMono(String.class).block(Duration.ofSeconds(30))).isEqualTo(sessionId);
|
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
|
||||||
Thread.sleep(2000);
|
return response.bodyToMono(String.class)
|
||||||
response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30));
|
.doOnNext((sessionId) -> assertThat(sessionId).isEqualTo(tuple.getT2()))
|
||||||
assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
.thenReturn(sesssionCookie);
|
||||||
|
});
|
||||||
|
}).delayElement(Duration.ofSeconds(2))
|
||||||
|
.flatMap((sessionCookie) -> client.get().cookie("SESSION", sessionCookie).exchangeToMono((response) -> {
|
||||||
|
assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||||
|
return response.releaseBody();
|
||||||
|
})).block(Duration.ofSeconds(30));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getBasicAuth() {
|
private String getBasicAuth() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue