0
+require File.dirname(__FILE__) + '/../abstract_unit'
0
+class SessionFixationTest < Test::Unit::TestCase
0
+ class MockCGI < CGI #:nodoc:
0
+ attr_accessor :stdoutput, :env_table
0
+ def initialize(env, data = '')
0
+ self.stdoutput = StringIO.new
0
+ super(StringIO.new(data))
0
+ class TestController < ActionController::Base
0
+ session :session_key => '_myapp_session_id', :secret => 'secret', :except => :default_session_key
0
+ session :cookie_only => false, :only => :allow_session_fixation
0
+ def default_session_key
0
+ render :text => "default_session_key"
0
+ def custom_session_key
0
+ render :text => "custom_session_key: #{params[:id]}"
0
+ def allow_session_fixation
0
+ render :text => "allow_session_fixation"
0
+ def rescue_action(e) raise end
0
+ @controller = TestController.new
0
+ def test_should_be_able_to_make_a_successful_request
0
+ cgi = mock_cgi_for_request_to(:custom_session_key, :id => 1)
0
+ assert_nothing_raised do
0
+ @controller.send(:process, mock_request(cgi), ActionController::CgiResponse.new(cgi))
0
+ assert_equal 'custom_session_key: 1', @controller.response.body
0
+ assert_not_nil @controller.session
0
+ def test_should_catch_session_fixation_attempt
0
+ cgi = mock_cgi_for_request_to(:custom_session_key, :_myapp_session_id => 42)
0
+ assert_raises ActionController::CgiRequest::SessionFixationAttempt do
0
+ @controller.send(:process, mock_request(cgi), ActionController::CgiResponse.new(cgi))
0
+ assert_nil @controller.session
0
+ def test_should_not_catch_session_fixation_attempt_when_cookie_only_setting_is_disabled
0
+ cgi = mock_cgi_for_request_to(:allow_session_fixation, :_myapp_session_id => 42)
0
+ assert_nothing_raised do
0
+ @controller.send(:process, mock_request(cgi), ActionController::CgiResponse.new(cgi))
0
+ assert !@controller.response.body.blank?
0
+ assert_not_nil @controller.session
0
+ def test_should_catch_session_fixation_attempt_with_default_session_key
0
+ ActionController::Base.session_store = :p_store # using the default session_key is not possible with cookie store
0
+ cgi = mock_cgi_for_request_to(:default_session_key, :_session_id => 42)
0
+ assert_raises ActionController::CgiRequest::SessionFixationAttempt do
0
+ @controller.send(:process, mock_request(cgi) , ActionController::CgiResponse.new(cgi))
0
+ assert @controller.response.body.blank?
0
+ assert_nil @controller.session
0
+ def mock_cgi_for_request_to(action, params = {})
0
+ "REQUEST_METHOD" => "GET",
0
+ "QUERY_STRING" => "action=#{action}&#{params.to_query}",
0
+ "SERVER_PORT" => "80",
0
+ "HTTP_HOST" => "testdomain.com" }, '')
0
+ ActionController::CgiRequest.new(cgi, {})
Comments
No one has commented yet.