Commit e99eb5ca9cad3c5c787aa82fdf05485b7c4a48e0

Authored by AntonioTerceiro
1 parent 1533ee71

ActionItem438: don't loose parameters in custom SSL handling

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2477 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/application.rb
@@ -35,6 +35,9 @@ class ApplicationController < ActionController::Base @@ -35,6 +35,9 @@ class ApplicationController < ActionController::Base
35 end 35 end
36 def check_ssl 36 def check_ssl
37 return true if (request.ssl? || ENV['RAILS_ENV'] == 'development') 37 return true if (request.ssl? || ENV['RAILS_ENV'] == 'development')
  38 + redirect_to_ssl
  39 + end
  40 + def redirect_to_ssl
38 redirect_to(params.merge(:protocol => 'https://')) 41 redirect_to(params.merge(:protocol => 'https://'))
39 end 42 end
40 43
app/controllers/public/content_viewer_controller.rb
@@ -29,7 +29,7 @@ class ContentViewerController < ApplicationController @@ -29,7 +29,7 @@ class ContentViewerController < ApplicationController
29 end 29 end
30 30
31 if !@page.public? && !request.ssl? 31 if !@page.public? && !request.ssl?
32 - redirect_to :protocol => 'https://' 32 + redirect_to_ssl
33 return 33 return
34 end 34 end
35 35
test/functional/application_controller_test.rb
@@ -291,4 +291,10 @@ class ApplicationControllerTest < Test::Unit::TestCase @@ -291,4 +291,10 @@ class ApplicationControllerTest < Test::Unit::TestCase
291 assert_redirected_to :protocol => 'http://', :x => '1', :y => '2' 291 assert_redirected_to :protocol => 'http://', :x => '1', :y => '2'
292 end 292 end
293 293
  294 + should 'add https protocols on redirect_to_ssl' do
  295 + @controller.expects(:params).returns(:x => '1', :y => '1')
  296 + @controller.expects(:redirect_to).with(:x => '1', :y => '1', :protocol => 'https://')
  297 + @controller.redirect_to_ssl
  298 + end
  299 +
294 end 300 end
test/functional/content_viewer_controller_test.rb
@@ -421,7 +421,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase @@ -421,7 +421,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase
421 should 'require SSL for viewing non-public articles' do 421 should 'require SSL for viewing non-public articles' do
422 page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :public_article => false) 422 page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :public_article => false)
423 get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ] 423 get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ]
424 - assert_redirected_to :protocol => 'https://' 424 + assert_redirected_to :protocol => 'https://', :profile => 'testinguser', :page => [ 'myarticle' ]
425 end 425 end
426 426
427 should 'not redirect to SSL if already on SSL' do 427 should 'not redirect to SSL if already on SSL' do