1
require 'abstract_unit'
3
# You need to start a memcached server inorder to run these tests
4
class MemCacheStoreTest < ActionController::IntegrationTest
5
class TestController < ActionController::Base
16
render :text => "foo: #{session[:foo].inspect}"
21
render :text => "#{request.session_options[:id]}"
24
def call_reset_session
31
def rescue_action(e) raise end
35
DispatcherApp = ActionController::Dispatcher.new
36
MemCacheStoreApp = ActionController::Session::MemCacheStore.new(
37
DispatcherApp, :key => '_session_id')
41
@integration_session = open_session(MemCacheStoreApp)
44
def test_setting_and_getting_session_value
45
with_test_route_set do
46
get '/set_session_value'
47
assert_response :success
48
assert cookies['_session_id']
50
get '/get_session_value'
51
assert_response :success
52
assert_equal 'foo: "bar"', response.body
56
def test_getting_nil_session_value
57
with_test_route_set do
58
get '/get_session_value'
59
assert_response :success
60
assert_equal 'foo: nil', response.body
64
def test_setting_session_value_after_session_reset
65
with_test_route_set do
66
get '/set_session_value'
67
assert_response :success
68
assert cookies['_session_id']
69
session_id = cookies['_session_id']
71
get '/call_reset_session'
72
assert_response :success
73
assert_not_equal [], headers['Set-Cookie']
75
get '/get_session_value'
76
assert_response :success
77
assert_equal 'foo: nil', response.body
80
assert_response :success
81
assert_not_equal session_id, response.body
85
def test_getting_session_id
86
with_test_route_set do
87
get '/set_session_value'
88
assert_response :success
89
assert cookies['_session_id']
90
session_id = cookies['_session_id']
93
assert_response :success
94
assert_equal session_id, response.body
98
def test_prevents_session_fixation
99
with_test_route_set do
100
get '/get_session_value'
101
assert_response :success
102
assert_equal 'foo: nil', response.body
103
session_id = cookies['_session_id']
107
get '/set_session_value', :_session_id => session_id
108
assert_response :success
109
assert_equal nil, cookies['_session_id']
112
rescue LoadError, RuntimeError
113
$stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again."
117
def with_test_route_set
118
with_routing do |set|
120
map.with_options :controller => "mem_cache_store_test/test" do |c|