我正在编写一个集成测试以确保我的 webapp 不会受到会话固定的影响。
我已经手动验证了reset_session
它实际上是在身份验证逻辑中触发的,而且当我使用我的网络浏览器登录时,cookie 确实发生了变化(因此,我不再容易受到会话固定的影响),但我无法得到我的RSpec 集成测试成功验证了这一点。
这是我的 RSpec 集成测试。
require 'spec_helper'
describe "security" do
self.use_transactional_fixtures = false
append_after(:each) do
ALL_MODELS.each &:delete_all
end
describe "session fixation" do
it "should change the cookie session id after logging in" do
u = test_user :active_user => true,
:username => "nobody@example.com",
:password => "asdfasdf"
u.save!
https!
get_via_redirect "/login"
assert_response :success
cookie = response.header["Set-Cookie"].split(";").select{|x| x.match(/_session/)}[0].split("=")[1].strip
post_via_redirect "/login", "user[email]" => "nobody@example.com",
"user[password]" => "asdfasdf",
"user[remember_me]" => "1"
assert_response :success
path.should eql("/dashboard")
cookie.should_not eql(response.header["Set-Cookie"].split(";").select{|x| x.match(/_session/)}[0].split("=")[1].strip)
end
end
end
除了最后一个断言外,一切正常。cookie 没有变化。
RSpec/Rails 集成测试是否有任何已知问题reset_session
无法按预期工作?我可以做些什么来编写一个验证会话固定不是问题的测试?