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 35 end
36 36 def check_ssl
37 37 return true if (request.ssl? || ENV['RAILS_ENV'] == 'development')
  38 + redirect_to_ssl
  39 + end
  40 + def redirect_to_ssl
38 41 redirect_to(params.merge(:protocol => 'https://'))
39 42 end
40 43  
... ...
app/controllers/public/content_viewer_controller.rb
... ... @@ -29,7 +29,7 @@ class ContentViewerController < ApplicationController
29 29 end
30 30  
31 31 if !@page.public? && !request.ssl?
32   - redirect_to :protocol => 'https://'
  32 + redirect_to_ssl
33 33 return
34 34 end
35 35  
... ...
test/functional/application_controller_test.rb
... ... @@ -291,4 +291,10 @@ class ApplicationControllerTest < Test::Unit::TestCase
291 291 assert_redirected_to :protocol => 'http://', :x => '1', :y => '2'
292 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 300 end
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -421,7 +421,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase
421 421 should 'require SSL for viewing non-public articles' do
422 422 page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :public_article => false)
423 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 425 end
426 426  
427 427 should 'not redirect to SSL if already on SSL' do
... ...