Support cookies with the same name with Reactor Netty

Ignore the related test with Undertow due to a bug in
their cookies handling.

Closes gh-28490
This commit is contained in:
Sébastien Deleuze
2023-12-06 14:55:59 +01:00
parent b53ffa3855
commit 8fe2c780df
3 changed files with 26 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,11 +30,14 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.testfixture.http.server.reactive.bootstrap.AbstractHttpHandlerIntegrationTests;
import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
/**
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
*/
public class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests {
@@ -81,6 +84,23 @@ public class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests
.containsExactlyInAnyOrder("path=/", "domain=example.com");
}
@ParameterizedHttpServerTest
public void cookiesWithSameNameTest(HttpServer httpServer) throws Exception {
assumeFalse(httpServer instanceof UndertowHttpServer, "Bug in Undertow in Cookies with same name handling");
startServer(httpServer);
URI url = new URI("http://localhost:" + port);
String header = "SID=31d4d96e407aad42; lang=en-US; lang=zh-CN";
new RestTemplate().exchange(
RequestEntity.get(url).header("Cookie", header).build(), Void.class);
Map<String, List<HttpCookie>> requestCookies = this.cookieHandler.requestCookies;
assertThat(requestCookies.size()).isEqualTo(2);
assertThat(requestCookies.get("SID")).extracting(HttpCookie::getValue).containsExactly("31d4d96e407aad42");
assertThat(requestCookies.get("lang")).extracting(HttpCookie::getValue).containsExactly("en-US", "zh-CN");
}
// No client side HttpCookie support yet
private List<String> splitCookie(String value) {
List<String> list = new ArrayList<>();