Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
43c09383
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,发现更多精彩内容 >>
提交
43c09383
编写于
2月 06, 2009
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure session id is set in session options hash [#1880 state:resolved]
上级
78c6f48b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
18 deletion
+45
-18
actionpack/lib/action_controller/session/abstract_store.rb
actionpack/lib/action_controller/session/abstract_store.rb
+8
-16
actionpack/lib/action_controller/session/cookie_store.rb
actionpack/lib/action_controller/session/cookie_store.rb
+1
-1
actionpack/test/controller/session/cookie_store_test.rb
actionpack/test/controller/session/cookie_store_test.rb
+18
-0
actionpack/test/controller/session/mem_cache_store_test.rb
actionpack/test/controller/session/mem_cache_store_test.rb
+18
-1
未找到文件。
actionpack/lib/action_controller/session/abstract_store.rb
浏览文件 @
43c09383
...
...
@@ -17,16 +17,11 @@ def initialize(by, env)
@loaded
=
false
end
def
id
load
!
unless
@loaded
@id
end
def
session_id
ActiveSupport
::
Deprecation
.
warn
(
"ActionController::Session::AbstractStore::SessionHash#session_id"
+
"has been deprecated.
Please use #id
instead."
,
caller
)
id
"ActionController::Session::AbstractStore::SessionHash#session_id
"
+
"has been deprecated.
Please use request.session_options[:id]
instead."
,
caller
)
@env
[
ENV_SESSION_OPTIONS_KEY
][
:id
]
end
def
[]
(
key
)
...
...
@@ -47,8 +42,8 @@ def to_hash
def
data
ActiveSupport
::
Deprecation
.
warn
(
"ActionController::Session::AbstractStore::SessionHash#data"
+
"has been deprecated.Please use #to_hash instead."
,
caller
)
"ActionController::Session::AbstractStore::SessionHash#data
"
+
"has been deprecated.
Please use #to_hash instead."
,
caller
)
to_hash
end
...
...
@@ -59,7 +54,8 @@ def loaded?
def
load!
stale_session_check!
do
@id
,
session
=
@by
.
send
(
:load_session
,
@env
)
id
,
session
=
@by
.
send
(
:load_session
,
@env
)
(
@env
[
ENV_SESSION_OPTIONS_KEY
]
||=
{})[
:id
]
=
id
replace
(
session
)
@loaded
=
true
end
...
...
@@ -126,11 +122,7 @@ def call(env)
if
!
session_data
.
is_a?
(
AbstractStore
::
SessionHash
)
||
session_data
.
send
(
:loaded?
)
||
options
[
:expire_after
]
session_data
.
send
(
:load!
)
if
session_data
.
is_a?
(
AbstractStore
::
SessionHash
)
&&
!
session_data
.
send
(
:loaded?
)
if
session_data
.
is_a?
(
AbstractStore
::
SessionHash
)
sid
=
session_data
.
id
else
sid
=
generate_sid
end
sid
=
options
[
:id
]
||
generate_sid
unless
set_session
(
env
,
sid
,
session_data
.
to_hash
)
return
response
...
...
actionpack/lib/action_controller/session/cookie_store.rb
浏览文件 @
43c09383
...
...
@@ -88,7 +88,7 @@ def initialize(app, options = {})
def
call
(
env
)
env
[
ENV_SESSION_KEY
]
=
AbstractStore
::
SessionHash
.
new
(
self
,
env
)
env
[
ENV_SESSION_OPTIONS_KEY
]
=
@default_options
env
[
ENV_SESSION_OPTIONS_KEY
]
=
@default_options
.
dup
status
,
headers
,
body
=
@app
.
call
(
env
)
...
...
actionpack/test/controller/session/cookie_store_test.rb
浏览文件 @
43c09383
...
...
@@ -30,6 +30,10 @@ def get_session_value
render
:text
=>
"foo:
#{
session
[
:foo
].
inspect
}
"
end
def
get_session_id
render
:text
=>
"foo:
#{
session
[
:foo
].
inspect
}
; id:
#{
request
.
session_options
[
:id
]
}
"
end
def
call_reset_session
reset_session
head
:ok
...
...
@@ -106,6 +110,20 @@ def test_getting_session_value
end
end
def
test_getting_session_id
with_test_route_set
do
cookies
[
SessionKey
]
=
SignedBar
get
'/persistent_session_id'
assert_response
:success
assert_equal
response
.
body
.
size
,
32
session_id
=
response
.
body
get
'/get_session_id'
assert_response
:success
assert_equal
"foo:
\"
bar
\"
; id:
#{
session_id
}
"
,
response
.
body
end
end
def
test_disregards_tampered_sessions
with_test_route_set
do
cookies
[
SessionKey
]
=
"BAh7BjoIZm9vIghiYXI%3D--123456780"
...
...
actionpack/test/controller/session/mem_cache_store_test.rb
浏览文件 @
43c09383
...
...
@@ -16,6 +16,10 @@ def get_session_value
render
:text
=>
"foo:
#{
session
[
:foo
].
inspect
}
"
end
def
get_session_id
render
:text
=>
"foo:
#{
session
[
:foo
].
inspect
}
; id:
#{
request
.
session_options
[
:id
]
}
"
end
def
call_reset_session
reset_session
head
:ok
...
...
@@ -50,7 +54,20 @@ def test_getting_nil_session_value
with_test_route_set
do
get
'/get_session_value'
assert_response
:success
assert_equal
'foo: nil'
,
response
.
body
assert_equal
'foo: nil'
,
response
.
body
end
end
def
test_getting_session_id
with_test_route_set
do
get
'/set_session_value'
assert_response
:success
assert
cookies
[
'_session_id'
]
session_id
=
cookies
[
'_session_id'
]
get
'/get_session_id'
assert_response
:success
assert_equal
"foo:
\"
bar
\"
; id:
#{
session_id
}
"
,
response
.
body
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录