diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 112f712..dbff29b 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -35,6 +35,9 @@ class ApplicationController < ActionController::Base end def check_ssl return true if (request.ssl? || ENV['RAILS_ENV'] == 'development') + redirect_to_ssl + end + def redirect_to_ssl redirect_to(params.merge(:protocol => 'https://')) end diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index a8e4470..37a4763 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -29,7 +29,7 @@ class ContentViewerController < ApplicationController end if !@page.public? && !request.ssl? - redirect_to :protocol => 'https://' + redirect_to_ssl return end diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index c401f2d..c97f7e2 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -291,4 +291,10 @@ class ApplicationControllerTest < Test::Unit::TestCase assert_redirected_to :protocol => 'http://', :x => '1', :y => '2' end + should 'add https protocols on redirect_to_ssl' do + @controller.expects(:params).returns(:x => '1', :y => '1') + @controller.expects(:redirect_to).with(:x => '1', :y => '1', :protocol => 'https://') + @controller.redirect_to_ssl + end + end diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index ae7f2bb..d9d3ea5 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -421,7 +421,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase should 'require SSL for viewing non-public articles' do page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :public_article => false) get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ] - assert_redirected_to :protocol => 'https://' + assert_redirected_to :protocol => 'https://', :profile => 'testinguser', :page => [ 'myarticle' ] end should 'not redirect to SSL if already on SSL' do -- libgit2 0.21.2