Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
ce0b012f
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ce0b012f
编写于
10月 29, 2019
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish contribution
See gh-23769
上级
9b208761
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
48 addition
and
25 deletion
+48
-25
spring-test/src/main/java/org/springframework/mock/web/MockCookie.java
...rc/main/java/org/springframework/mock/web/MockCookie.java
+12
-8
spring-test/src/test/java/org/springframework/mock/web/MockCookieTests.java
...st/java/org/springframework/mock/web/MockCookieTests.java
+8
-8
spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java
...pringframework/mock/web/MockHttpServletResponseTests.java
+16
-1
spring-web/src/test/java/org/springframework/mock/web/test/MockCookie.java
...st/java/org/springframework/mock/web/test/MockCookie.java
+12
-8
未找到文件。
spring-test/src/main/java/org/springframework/mock/web/MockCookie.java
浏览文件 @
ce0b012f
...
...
@@ -46,7 +46,7 @@ public class MockCookie extends Cookie {
/**
* Construct
or with the cookie
name and value.
* Construct
a new {@link MockCookie} with the supplied
name and value.
* @param name the name
* @param value the value
* @see Cookie#Cookie(String, String)
...
...
@@ -56,14 +56,17 @@ public class MockCookie extends Cookie {
}
/**
* Add the "Expires" attribute to the cookie.
* Set the "Expires" attribute for this cookie.
* @since 5.1.11
*/
public
void
setExpires
(
@Nullable
ZonedDateTime
expires
)
{
this
.
expires
=
expires
;
}
/**
* Return the "Expires" attribute, or {@code null} if not set.
* Get the "Expires" attribute for this cookie.
* @since 5.1.11
* @return the "Expires" attribute for this cookie, or {@code null} if not set
*/
@Nullable
public
ZonedDateTime
getExpires
()
{
...
...
@@ -71,10 +74,10 @@ public class MockCookie extends Cookie {
}
/**
*
Add the "SameSite" attribute to the
cookie.
*
Set the "SameSite" attribute for this
cookie.
* <p>This limits the scope of the cookie such that it will only be attached
* to same
site requests if {@code "Strict"} or cross-site requests if
* {@code "Lax"}.
* to same
-site requests if the supplied value is {@code "Strict"} or cross-site
*
requests if the supplied value is
{@code "Lax"}.
* @see <a href="https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis#section-4.1.2.7">RFC6265 bis</a>
*/
public
void
setSameSite
(
@Nullable
String
sameSite
)
{
...
...
@@ -82,7 +85,8 @@ public class MockCookie extends Cookie {
}
/**
* Return the "SameSite" attribute, or {@code null} if not set.
* Get the "SameSite" attribute for this cookie.
* @return the "SameSite" attribute for this cookie, or {@code null} if not set
*/
@Nullable
public
String
getSameSite
()
{
...
...
@@ -91,7 +95,7 @@ public class MockCookie extends Cookie {
/**
* Factory method that parses the value of
a
"Set-Cookie" header.
* Factory method that parses the value of
the supplied
"Set-Cookie" header.
* @param setCookieHeader the "Set-Cookie" value; never {@code null} or empty
* @return the created cookie
*/
...
...
spring-test/src/test/java/org/springframework/mock/web/MockCookieTests.java
浏览文件 @
ce0b012f
...
...
@@ -16,11 +16,11 @@
package
org.springframework.mock.web
;
import
org.junit.jupiter.api.Test
;
import
java.time.ZonedDateTime
;
import
java.time.format.DateTimeFormatter
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalArgumentException
;
...
...
@@ -86,15 +86,15 @@ class MockCookieTests {
@Test
void
parseNullHeader
()
{
assertThatIllegalArgumentException
()
.
isThrownBy
(()
->
MockCookie
.
parse
(
null
))
assertThatIllegalArgumentException
()
.
isThrownBy
(()
->
MockCookie
.
parse
(
null
))
.
withMessageContaining
(
"Set-Cookie header must not be null"
);
}
@Test
void
parseInvalidHeader
()
{
assertThatIllegalArgumentException
()
.
isThrownBy
(()
->
MockCookie
.
parse
(
"BOOM"
))
assertThatIllegalArgumentException
()
.
isThrownBy
(()
->
MockCookie
.
parse
(
"BOOM"
))
.
withMessageContaining
(
"Invalid Set-Cookie header 'BOOM'"
);
}
...
...
@@ -102,8 +102,8 @@ class MockCookieTests {
void
parseInvalidAttribute
()
{
String
header
=
"SESSION=123; Path="
;
assertThatIllegalArgumentException
()
.
isThrownBy
(()
->
MockCookie
.
parse
(
header
))
assertThatIllegalArgumentException
()
.
isThrownBy
(()
->
MockCookie
.
parse
(
header
))
.
withMessageContaining
(
"No value in attribute 'Path' for Set-Cookie header '"
+
header
+
"'"
);
}
...
...
spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java
浏览文件 @
ce0b012f
...
...
@@ -350,6 +350,18 @@ class MockHttpServletResponseTests {
assertPrimarySessionCookie
(
"999"
);
}
/**
* @since 5.1.11
*/
@Test
void
setCookieHeaderWithExpiresAttribute
()
{
String
cookieValue
=
"SESSION=123; Path=/; Max-Age=100; Expires=Tue, 8 Oct 2019 19:50:00 GMT; Secure; "
+
"HttpOnly; SameSite=Lax"
;
response
.
setHeader
(
HttpHeaders
.
SET_COOKIE
,
cookieValue
);
assertNumCookies
(
1
);
assertThat
(
response
.
getHeader
(
HttpHeaders
.
SET_COOKIE
)).
isEqualTo
(
cookieValue
);
}
@Test
void
addCookieHeader
()
{
response
.
addHeader
(
HttpHeaders
.
SET_COOKIE
,
"SESSION=123; Path=/; Secure; HttpOnly; SameSite=Lax"
);
...
...
@@ -363,8 +375,11 @@ class MockHttpServletResponseTests {
assertCookieValues
(
"123"
,
"999"
);
}
/**
* @since 5.1.11
*/
@Test
void
addCookieHeaderWithExpires
()
{
void
addCookieHeaderWithExpires
Attribute
()
{
String
cookieValue
=
"SESSION=123; Path=/; Max-Age=100; Expires=Tue, 8 Oct 2019 19:50:00 GMT; Secure; "
+
"HttpOnly; SameSite=Lax"
;
response
.
addHeader
(
HttpHeaders
.
SET_COOKIE
,
cookieValue
);
...
...
spring-web/src/test/java/org/springframework/mock/web/test/MockCookie.java
浏览文件 @
ce0b012f
...
...
@@ -46,7 +46,7 @@ public class MockCookie extends Cookie {
/**
* Construct
or with the cookie
name and value.
* Construct
a new {@link MockCookie} with the supplied
name and value.
* @param name the name
* @param value the value
* @see Cookie#Cookie(String, String)
...
...
@@ -56,14 +56,17 @@ public class MockCookie extends Cookie {
}
/**
* Add the "Expires" attribute to the cookie.
* Set the "Expires" attribute for this cookie.
* @since 5.1.11
*/
public
void
setExpires
(
@Nullable
ZonedDateTime
expires
)
{
this
.
expires
=
expires
;
}
/**
* Return the "Expires" attribute, or {@code null} if not set.
* Get the "Expires" attribute for this cookie.
* @since 5.1.11
* @return the "Expires" attribute for this cookie, or {@code null} if not set
*/
@Nullable
public
ZonedDateTime
getExpires
()
{
...
...
@@ -71,10 +74,10 @@ public class MockCookie extends Cookie {
}
/**
*
Add the "SameSite" attribute to the
cookie.
*
Set the "SameSite" attribute for this
cookie.
* <p>This limits the scope of the cookie such that it will only be attached
* to same
site requests if {@code "Strict"} or cross-site requests if
* {@code "Lax"}.
* to same
-site requests if the supplied value is {@code "Strict"} or cross-site
*
requests if the supplied value is
{@code "Lax"}.
* @see <a href="https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis#section-4.1.2.7">RFC6265 bis</a>
*/
public
void
setSameSite
(
@Nullable
String
sameSite
)
{
...
...
@@ -82,7 +85,8 @@ public class MockCookie extends Cookie {
}
/**
* Return the "SameSite" attribute, or {@code null} if not set.
* Get the "SameSite" attribute for this cookie.
* @return the "SameSite" attribute for this cookie, or {@code null} if not set
*/
@Nullable
public
String
getSameSite
()
{
...
...
@@ -91,7 +95,7 @@ public class MockCookie extends Cookie {
/**
* Factory method that parses the value of
a
"Set-Cookie" header.
* Factory method that parses the value of
the supplied
"Set-Cookie" header.
* @param setCookieHeader the "Set-Cookie" value; never {@code null} or empty
* @return the created cookie
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录