1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

reset_session should force a new session id to be generated [#2173]

This commit is contained in:
Joshua Peek 2009-03-09 22:45:38 -05:00
parent 4458edc882
commit 224a534400
3 changed files with 52 additions and 18 deletions

View file

@ -442,6 +442,7 @@ EOM
end end
def reset_session def reset_session
@env['rack.session.options'].delete(:id)
@env['rack.session'] = {} @env['rack.session'] = {}
end end

View file

@ -21,8 +21,15 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
render :text => "foo: #{session[:foo].inspect}" render :text => "foo: #{session[:foo].inspect}"
end end
def get_session_id
session[:foo]
render :text => "#{request.session_options[:id]}"
end
def call_reset_session def call_reset_session
session[:bar]
reset_session reset_session
session[:bar] = "baz"
head :ok head :ok
end end
@ -71,6 +78,7 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
get '/set_session_value' get '/set_session_value'
assert_response :success assert_response :success
assert cookies['_session_id'] assert cookies['_session_id']
session_id = cookies['_session_id']
get '/call_reset_session' get '/call_reset_session'
assert_response :success assert_response :success
@ -79,6 +87,23 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
get '/get_session_value' get '/get_session_value'
assert_response :success assert_response :success
assert_equal 'foo: nil', response.body assert_equal 'foo: nil', response.body
get '/get_session_id'
assert_response :success
assert_not_equal session_id, 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 session_id, response.body
end end
end end

View file

@ -17,11 +17,14 @@ class MemCacheStoreTest < ActionController::IntegrationTest
end end
def get_session_id def get_session_id
render :text => "foo: #{session[:foo].inspect}; id: #{request.session_options[:id]}" session[:foo]
render :text => "#{request.session_options[:id]}"
end end
def call_reset_session def call_reset_session
session[:bar]
reset_session reset_session
session[:bar] = "baz"
head :ok head :ok
end end
@ -58,6 +61,27 @@ class MemCacheStoreTest < ActionController::IntegrationTest
end end
end end
def test_setting_session_value_after_session_reset
with_test_route_set do
get '/set_session_value'
assert_response :success
assert cookies['_session_id']
session_id = cookies['_session_id']
get '/call_reset_session'
assert_response :success
assert_not_equal [], headers['Set-Cookie']
get '/get_session_value'
assert_response :success
assert_equal 'foo: nil', response.body
get '/get_session_id'
assert_response :success
assert_not_equal session_id, response.body
end
end
def test_getting_session_id def test_getting_session_id
with_test_route_set do with_test_route_set do
get '/set_session_value' get '/set_session_value'
@ -67,7 +91,7 @@ class MemCacheStoreTest < ActionController::IntegrationTest
get '/get_session_id' get '/get_session_id'
assert_response :success assert_response :success
assert_equal "foo: \"bar\"; id: #{session_id}", response.body assert_equal session_id, response.body
end end
end end
@ -85,22 +109,6 @@ class MemCacheStoreTest < ActionController::IntegrationTest
assert_equal nil, cookies['_session_id'] assert_equal nil, cookies['_session_id']
end end
end end
def test_setting_session_value_after_session_reset
with_test_route_set do
get '/set_session_value'
assert_response :success
assert cookies['_session_id']
get '/call_reset_session'
assert_response :success
assert_not_equal [], headers['Set-Cookie']
get '/get_session_value'
assert_response :success
assert_equal 'foo: nil', response.body
end
end
rescue LoadError, RuntimeError rescue LoadError, RuntimeError
$stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again." $stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again."
end end