diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 08745e5..112f712 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -35,7 +35,7 @@ class ApplicationController < ActionController::Base end def check_ssl return true if (request.ssl? || ENV['RAILS_ENV'] == 'development') - redirect_to :protocol => 'https://' + redirect_to(params.merge(:protocol => 'https://')) end def self.refuse_ssl(*options) @@ -43,7 +43,7 @@ class ApplicationController < ActionController::Base end def avoid_ssl return true if (!request.ssl? || ENV['RAILS_ENV'] == 'development') - redirect_to :protocol => 'http://' + redirect_to(params.merge(:protocol => 'http://')) end before_init_gettext :maybe_save_locale diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index ac5a38c..4d0aaa3 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -8,7 +8,6 @@ class CmsController < MyProfileController # publication" button on article's public view. def check_ssl if ((params[:action] == 'new') && (!request.xhr?)) || (params[:action] != 'new') - #raise 'bli' check_ssl_orig end end diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index 2b12c23..8032d78 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -249,6 +249,12 @@ class ApplicationControllerTest < Test::Unit::TestCase assert_response :success end + should 'keep arguments when redirecting to ssl' do + @request.expects(:ssl?).returns(false).at_least_once + get :sslonly, :x => '1', :y => '2' + assert_redirected_to :protocol => 'https://', :x => '1', :y => '2' + end + should 'refuse ssl when told to' do @request.expects(:ssl?).returns(true).at_least_once get :nossl @@ -272,4 +278,10 @@ class ApplicationControllerTest < Test::Unit::TestCase assert_response :success end + should 'keep arguments when redirecting to non-ssl' do + @request.expects(:ssl?).returns(true).at_least_once + get :nossl, :x => '1', :y => '2' + assert_redirected_to :protocol => 'http://', :x => '1', :y => '2' + end + end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 197b358..057ff39 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -604,6 +604,12 @@ class CmsControllerTest < Test::Unit::TestCase assert_response :success end + should 'not loose type argument in new action when redirecting to ssl' do + @request.expects(:ssl?).returns(false).at_least_once + get :new, :profile => 'testinguser', :type => 'Folder' + assert_redirected_to :protocol => 'https://', :action => 'new', :type => 'Folder' + end + should 'not accept non-ajax connections to new action without ssl' do @request.expects(:ssl?).returns(false).at_least_once get :new, :profile => 'testinguser' diff --git a/test/functional/edit_template_controller_test.rb b/test/functional/edit_template_controller_test.rb index fb096f2..0ebf0b5 100644 --- a/test/functional/edit_template_controller_test.rb +++ b/test/functional/edit_template_controller_test.rb @@ -11,6 +11,7 @@ class EditTemplateControllerTest < Test::Unit::TestCase def setup @controller = EditTemplateController.new @request = ActionController::TestRequest.new + @request.stubs(:ssl?).returns(true) @response = ActionController::TestResponse.new login_as 'ze' end -- libgit2 0.21.2