Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
dd57f60d
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dd57f60d
编写于
10月 01, 2015
作者:
J
Jeremy Daer
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21836 from jeremy/no-nil-set-cookie-headers
Don't set a nil Set-Cookie header when there aren't any cookies
上级
2c41b530
be5e6cea
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
96 addition
and
75 deletion
+96
-75
actionpack/lib/action_dispatch/middleware/cookies.rb
actionpack/lib/action_dispatch/middleware/cookies.rb
+3
-1
actionpack/test/dispatch/cookies_test.rb
actionpack/test/dispatch/cookies_test.rb
+93
-74
未找到文件。
actionpack/lib/action_dispatch/middleware/cookies.rb
浏览文件 @
dd57f60d
...
...
@@ -396,7 +396,9 @@ def clear(options = {})
end
def
write
(
headers
)
headers
[
HTTP_HEADER
]
=
make_set_cookie_header
headers
[
HTTP_HEADER
]
if
header
=
make_set_cookie_header
(
headers
[
HTTP_HEADER
])
headers
[
HTTP_HEADER
]
=
header
end
end
mattr_accessor
:always_write_cookie
...
...
actionpack/test/dispatch/cookies_test.rb
浏览文件 @
dd57f60d
...
...
@@ -3,6 +3,75 @@
require
'active_support/key_generator'
require
'active_support/message_verifier'
class
CookieJarTest
<
ActiveSupport
::
TestCase
attr_reader
:request
def
setup
@request
=
ActionDispatch
::
Request
.
new
({})
end
def
test_fetch
x
=
Object
.
new
assert_not
request
.
cookie_jar
.
key?
(
'zzzzzz'
)
assert_equal
x
,
request
.
cookie_jar
.
fetch
(
'zzzzzz'
,
x
)
assert_not
request
.
cookie_jar
.
key?
(
'zzzzzz'
)
end
def
test_fetch_exists
x
=
Object
.
new
request
.
cookie_jar
[
'foo'
]
=
'bar'
assert_equal
'bar'
,
request
.
cookie_jar
.
fetch
(
'foo'
,
x
)
end
def
test_fetch_block
x
=
Object
.
new
assert_not
request
.
cookie_jar
.
key?
(
'zzzzzz'
)
assert_equal
x
,
request
.
cookie_jar
.
fetch
(
'zzzzzz'
)
{
x
}
end
def
test_key_is_to_s
request
.
cookie_jar
[
'foo'
]
=
'bar'
assert_equal
'bar'
,
request
.
cookie_jar
.
fetch
(
:foo
)
end
def
test_fetch_type_error
assert_raises
(
KeyError
)
do
request
.
cookie_jar
.
fetch
(
:omglolwut
)
end
end
def
test_each
request
.
cookie_jar
[
'foo'
]
=
:bar
list
=
[]
request
.
cookie_jar
.
each
do
|
k
,
v
|
list
<<
[
k
,
v
]
end
assert_equal
[[
'foo'
,
:bar
]],
list
end
def
test_enumerable
request
.
cookie_jar
[
'foo'
]
=
:bar
actual
=
request
.
cookie_jar
.
map
{
|
k
,
v
|
[
k
.
to_s
,
v
.
to_s
]
}
assert_equal
[[
'foo'
,
'bar'
]],
actual
end
def
test_key_methods
assert
!
request
.
cookie_jar
.
key?
(
:foo
)
assert
!
request
.
cookie_jar
.
has_key?
(
"foo"
)
request
.
cookie_jar
[
:foo
]
=
:bar
assert
request
.
cookie_jar
.
key?
(
:foo
)
assert
request
.
cookie_jar
.
has_key?
(
"foo"
)
end
def
test_write_doesnt_set_a_nil_header
headers
=
{}
request
.
cookie_jar
.
write
(
headers
)
assert
!
headers
.
include?
(
'Set-Cookie'
)
end
end
class
CookiesTest
<
ActionController
::
TestCase
class
CustomSerializer
def
self
.
load
(
value
)
...
...
@@ -14,16 +83,6 @@ def self.dump(value)
end
end
class
JSONWrapper
def
initialize
(
obj
)
@obj
=
obj
end
def
as_json
(
options
=
nil
)
"wrapped:
#{
@obj
.
as_json
(
options
)
}
"
end
end
class
TestController
<
ActionController
::
Base
def
authenticate
cookies
[
"user_name"
]
=
"david"
...
...
@@ -88,11 +147,6 @@ def set_signed_cookie
head
:ok
end
def
set_wrapped_signed_cookie
cookies
.
signed
[
:user_id
]
=
JSONWrapper
.
new
(
45
)
head
:ok
end
def
get_signed_cookie
cookies
.
signed
[
:user_id
]
head
:ok
...
...
@@ -103,6 +157,21 @@ def set_encrypted_cookie
head
:ok
end
class
JSONWrapper
def
initialize
(
obj
)
@obj
=
obj
end
def
as_json
(
options
=
nil
)
"wrapped:
#{
@obj
.
as_json
(
options
)
}
"
end
end
def
set_wrapped_signed_cookie
cookies
.
signed
[
:user_id
]
=
JSONWrapper
.
new
(
45
)
head
:ok
end
def
set_wrapped_encrypted_cookie
cookies
.
encrypted
[
:foo
]
=
JSONWrapper
.
new
(
'bar'
)
head
:ok
...
...
@@ -207,68 +276,18 @@ def noop
tests
TestController
SALT
=
'b3c631c314c0bbca50c1b2843150fe33'
def
setup
super
@request
.
env
[
"action_dispatch.key_generator"
]
=
ActiveSupport
::
KeyGenerator
.
new
(
"b3c631c314c0bbca50c1b2843150fe33"
,
iterations:
2
)
@request
.
env
[
"action_dispatch.signed_cookie_salt"
]
=
"b3c631c314c0bbca50c1b2843150fe33"
@request
.
env
[
"action_dispatch.encrypted_cookie_salt"
]
=
"b3c631c314c0bbca50c1b2843150fe33"
@request
.
env
[
"action_dispatch.encrypted_signed_cookie_salt"
]
=
"b3c631c314c0bbca50c1b2843150fe33"
@request
.
host
=
"www.nextangle.com"
end
def
test_fetch
x
=
Object
.
new
assert_not
request
.
cookie_jar
.
key?
(
'zzzzzz'
)
assert_equal
x
,
request
.
cookie_jar
.
fetch
(
'zzzzzz'
,
x
)
assert_not
request
.
cookie_jar
.
key?
(
'zzzzzz'
)
end
def
test_fetch_exists
x
=
Object
.
new
request
.
cookie_jar
[
'foo'
]
=
'bar'
assert_equal
'bar'
,
request
.
cookie_jar
.
fetch
(
'foo'
,
x
)
end
def
test_fetch_block
x
=
Object
.
new
assert_not
request
.
cookie_jar
.
key?
(
'zzzzzz'
)
assert_equal
x
,
request
.
cookie_jar
.
fetch
(
'zzzzzz'
)
{
x
}
end
def
test_key_is_to_s
request
.
cookie_jar
[
'foo'
]
=
'bar'
assert_equal
'bar'
,
request
.
cookie_jar
.
fetch
(
:foo
)
end
def
test_fetch_type_error
assert_raises
(
KeyError
)
do
request
.
cookie_jar
.
fetch
(
:omglolwut
)
end
end
def
test_each
request
.
cookie_jar
[
'foo'
]
=
:bar
list
=
[]
request
.
cookie_jar
.
each
do
|
k
,
v
|
list
<<
[
k
,
v
]
end
assert_equal
[[
'foo'
,
:bar
]],
list
end
@request
.
env
[
"action_dispatch.key_generator"
]
=
ActiveSupport
::
KeyGenerator
.
new
(
SALT
,
iterations:
2
)
def
test_enumerable
request
.
cookie_jar
[
'foo'
]
=
:bar
actual
=
request
.
cookie_jar
.
map
{
|
k
,
v
|
[
k
.
to_s
,
v
.
to_s
]
}
assert_equal
[[
'foo'
,
'bar'
]],
actual
end
@request
.
env
[
"action_dispatch.signed_cookie_salt"
]
=
@request
.
env
[
"action_dispatch.encrypted_cookie_salt"
]
=
@request
.
env
[
"action_dispatch.encrypted_signed_cookie_salt"
]
=
SALT
def
test_key_methods
assert
!
request
.
cookie_jar
.
key?
(
:foo
)
assert
!
request
.
cookie_jar
.
has_key?
(
"foo"
)
request
.
cookie_jar
[
:foo
]
=
:bar
assert
request
.
cookie_jar
.
key?
(
:foo
)
assert
request
.
cookie_jar
.
has_key?
(
"foo"
)
@request
.
host
=
"www.nextangle.com"
end
def
test_setting_cookie
...
...
@@ -1083,11 +1102,11 @@ def test_cookies_retained_across_requests
assert_equal
"david"
,
cookies
[
:user_name
]
get
:noop
assert
_nil
@response
.
headers
[
"Set-Cookie"
]
assert
!
@response
.
headers
.
include?
(
"Set-Cookie"
)
assert_equal
"david"
,
cookies
[
:user_name
]
get
:noop
assert
_nil
@response
.
headers
[
"Set-Cookie"
]
assert
!
@response
.
headers
.
include?
(
"Set-Cookie"
)
assert_equal
"david"
,
cookies
[
:user_name
]
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录