Adapt to API change in Spring Framework 5.3.0 snapshots

See gh-23534
This commit is contained in:
Stephane Nicoll
2020-09-30 16:03:33 +02:00
parent f4ce77fcae
commit de32fab324
4 changed files with 33 additions and 36 deletions

View File

@@ -20,13 +20,12 @@ import java.time.Duration;
import java.util.Base64;
import org.junit.jupiter.api.Test;
import reactor.util.function.Tuples;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
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 static org.assertj.core.api.Assertions.assertThat;
@@ -47,19 +46,25 @@ class SampleSessionWebFluxApplicationTests {
private WebClient.Builder webClientBuilder;
@Test
void userDefinedMappingsSecureByDefault() throws Exception {
WebClient webClient = this.webClientBuilder.baseUrl("http://localhost:" + this.port + "/").build();
ClientResponse response = webClient.get().header("Authorization", getBasicAuth()).exchange()
.block(Duration.ofSeconds(30));
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
ResponseCookie sessionCookie = response.cookies().getFirst("SESSION");
String sessionId = response.bodyToMono(String.class).block(Duration.ofSeconds(30));
response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30));
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.bodyToMono(String.class).block(Duration.ofSeconds(30))).isEqualTo(sessionId);
Thread.sleep(2000);
response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30));
assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
void userDefinedMappingsSecureByDefault() {
WebClient client = this.webClientBuilder.baseUrl("http://localhost:" + this.port + "/").build();
client.get().header("Authorization", getBasicAuth()).exchangeToMono((response) -> {
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
return response.bodyToMono(String.class)
.map((sessionId) -> Tuples.of(response.cookies().getFirst("SESSION").getValue(), sessionId));
}).flatMap((tuple) -> {
String sesssionCookie = tuple.getT1();
return client.get().cookie("SESSION", sesssionCookie).exchangeToMono((response) -> {
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
return response.bodyToMono(String.class)
.doOnNext((sessionId) -> assertThat(sessionId).isEqualTo(tuple.getT2()))
.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() {