Skip to content

Commit dd97ee4

Browse files
justin-taysbrannen
authored andcommitted
Support SameSite cookie attribute in MockMvcHttpConnector
Closes gh-30264
1 parent 90b0f45 commit dd97ee4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -197,6 +197,7 @@ private MockClientHttpResponse adaptResponse(MvcResult mvcResult) {
197197
.path(cookie.getPath())
198198
.secure(cookie.getSecure())
199199
.httpOnly(cookie.isHttpOnly())
200+
.sameSite(cookie.getAttribute("samesite"))
200201
.build();
201202
clientResponse.getCookies().add(httpCookie.getName(), httpCookie);
202203
}

spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/CookieAssertionTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,6 +50,7 @@ public void setup() {
5050
CookieLocaleResolver localeResolver = new CookieLocaleResolver();
5151
localeResolver.setCookieDomain("domain");
5252
localeResolver.setCookieHttpOnly(true);
53+
localeResolver.setCookieSameSite("Strict");
5354

5455
client = MockMvcWebTestClient.bindToController(new SimpleController())
5556
.interceptors(new LocaleChangeInterceptor())
@@ -107,6 +108,10 @@ public void testHttpOnly() {
107108
client.get().uri("/").exchange().expectCookie().httpOnly(COOKIE_NAME, true);
108109
}
109110

111+
@Test
112+
public void testSameSite() {
113+
client.get().uri("/").exchange().expectCookie().sameSite(COOKIE_NAME, "Strict");
114+
}
110115

111116
@Controller
112117
private static class SimpleController {

0 commit comments

Comments
 (0)