Add Partitioned cookie attribute support for servers
This commit adds support for the "Partitioned" cookie attribute in WebFlux servers and the related testing infrastructure. Note, Undertow does not support this feature at the moment. Closes gh-31454
This commit is contained in:
@@ -71,7 +71,7 @@ class MockCookieTests {
|
||||
@Test
|
||||
void parseHeaderWithAttributes() {
|
||||
MockCookie cookie = MockCookie.parse("SESSION=123; Domain=example.com; Max-Age=60; " +
|
||||
"Expires=Tue, 8 Oct 2019 19:50:00 GMT; Path=/; Secure; HttpOnly; SameSite=Lax");
|
||||
"Expires=Tue, 8 Oct 2019 19:50:00 GMT; Path=/; Secure; HttpOnly; Partitioned; SameSite=Lax");
|
||||
|
||||
assertCookie(cookie, "SESSION", "123");
|
||||
assertThat(cookie.getDomain()).isEqualTo("example.com");
|
||||
@@ -79,6 +79,7 @@ class MockCookieTests {
|
||||
assertThat(cookie.getPath()).isEqualTo("/");
|
||||
assertThat(cookie.getSecure()).isTrue();
|
||||
assertThat(cookie.isHttpOnly()).isTrue();
|
||||
assertThat(cookie.isPartitioned()).isTrue();
|
||||
assertThat(cookie.getExpires()).isEqualTo(ZonedDateTime.parse("Tue, 8 Oct 2019 19:50:00 GMT",
|
||||
DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||
assertThat(cookie.getSameSite()).isEqualTo("Lax");
|
||||
@@ -203,4 +204,12 @@ class MockCookieTests {
|
||||
assertThatThrownBy(() -> cookie.setAttribute("expires", "12345")).isInstanceOf(DateTimeParseException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setPartitioned() {
|
||||
MockCookie cookie = new MockCookie("SESSION", "123");
|
||||
cookie.setAttribute("Partitioned", "");
|
||||
|
||||
assertThat(cookie.isPartitioned()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -274,12 +274,13 @@ class MockHttpServletResponseTests {
|
||||
cookie.setMaxAge(0);
|
||||
cookie.setSecure(true);
|
||||
cookie.setHttpOnly(true);
|
||||
cookie.setAttribute("Partitioned", "");
|
||||
|
||||
response.addCookie(cookie);
|
||||
|
||||
assertThat(response.getHeader(SET_COOKIE)).isEqualTo(("foo=bar; Path=/path; Domain=example.com; " +
|
||||
"Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; " +
|
||||
"Secure; HttpOnly"));
|
||||
"Secure; HttpOnly; Partitioned"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class CookieAssertionTests {
|
||||
public class CookieAssertionsTests {
|
||||
|
||||
private final ResponseCookie cookie = ResponseCookie.from("foo", "bar")
|
||||
.maxAge(Duration.ofMinutes(30))
|
||||
@@ -45,6 +45,7 @@ public class CookieAssertionTests {
|
||||
.path("/foo")
|
||||
.secure(true)
|
||||
.httpOnly(true)
|
||||
.partitioned(true)
|
||||
.sameSite("Lax")
|
||||
.build();
|
||||
|
||||
@@ -117,6 +118,12 @@ public class CookieAssertionTests {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertions.httpOnly("foo", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void partitioned() {
|
||||
assertions.partitioned("foo", true);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertions.partitioned("foo", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameSite() {
|
||||
assertions.sameSite("foo", "Lax");
|
||||
Reference in New Issue
Block a user