2011-03-27 15:05:14 -04:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
class ForceSSLController < ActionController::Base
|
|
|
|
def banana
|
|
|
|
render :text => "monkey"
|
|
|
|
end
|
|
|
|
|
|
|
|
def cheeseburger
|
|
|
|
render :text => "sikachu"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ForceSSLControllerLevel < ForceSSLController
|
|
|
|
force_ssl
|
|
|
|
end
|
|
|
|
|
2011-10-08 19:38:02 -04:00
|
|
|
class ForceSSLCustomDomain < ForceSSLController
|
|
|
|
force_ssl :host => "secure.test.host"
|
|
|
|
end
|
|
|
|
|
2011-03-27 15:05:14 -04:00
|
|
|
class ForceSSLOnlyAction < ForceSSLController
|
|
|
|
force_ssl :only => :cheeseburger
|
|
|
|
end
|
|
|
|
|
|
|
|
class ForceSSLExceptAction < ForceSSLController
|
|
|
|
force_ssl :except => :banana
|
|
|
|
end
|
|
|
|
|
2012-01-12 14:31:23 -05:00
|
|
|
class ForceSSLFlash < ForceSSLController
|
|
|
|
force_ssl :except => [:banana, :set_flash, :use_flash]
|
|
|
|
|
|
|
|
def set_flash
|
|
|
|
flash["that"] = "hello"
|
|
|
|
redirect_to '/force_ssl_flash/cheeseburger'
|
|
|
|
end
|
|
|
|
|
|
|
|
def use_flash
|
|
|
|
@flash_copy = {}.update flash
|
|
|
|
@flashy = flash["that"]
|
|
|
|
render :inline => "hello"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-27 15:05:14 -04:00
|
|
|
class ForceSSLControllerLevelTest < ActionController::TestCase
|
|
|
|
tests ForceSSLControllerLevel
|
|
|
|
|
|
|
|
def test_banana_redirects_to_https
|
|
|
|
get :banana
|
|
|
|
assert_response 301
|
|
|
|
assert_equal "https://test.host/force_ssl_controller_level/banana", redirect_to_url
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cheeseburger_redirects_to_https
|
|
|
|
get :cheeseburger
|
|
|
|
assert_response 301
|
|
|
|
assert_equal "https://test.host/force_ssl_controller_level/cheeseburger", redirect_to_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-08 19:38:02 -04:00
|
|
|
class ForceSSLCustomDomainTest < ActionController::TestCase
|
|
|
|
tests ForceSSLCustomDomain
|
|
|
|
|
|
|
|
def test_banana_redirects_to_https_with_custom_host
|
|
|
|
get :banana
|
|
|
|
assert_response 301
|
|
|
|
assert_equal "https://secure.test.host/force_ssl_custom_domain/banana", redirect_to_url
|
|
|
|
end
|
2012-01-12 14:31:23 -05:00
|
|
|
|
2011-10-08 19:38:02 -04:00
|
|
|
def test_cheeseburger_redirects_to_https_with_custom_host
|
|
|
|
get :cheeseburger
|
|
|
|
assert_response 301
|
|
|
|
assert_equal "https://secure.test.host/force_ssl_custom_domain/cheeseburger", redirect_to_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-27 15:05:14 -04:00
|
|
|
class ForceSSLOnlyActionTest < ActionController::TestCase
|
|
|
|
tests ForceSSLOnlyAction
|
|
|
|
|
|
|
|
def test_banana_not_redirects_to_https
|
|
|
|
get :banana
|
|
|
|
assert_response 200
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cheeseburger_redirects_to_https
|
|
|
|
get :cheeseburger
|
|
|
|
assert_response 301
|
|
|
|
assert_equal "https://test.host/force_ssl_only_action/cheeseburger", redirect_to_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ForceSSLExceptActionTest < ActionController::TestCase
|
|
|
|
tests ForceSSLExceptAction
|
|
|
|
|
|
|
|
def test_banana_not_redirects_to_https
|
|
|
|
get :banana
|
|
|
|
assert_response 200
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cheeseburger_redirects_to_https
|
|
|
|
get :cheeseburger
|
|
|
|
assert_response 301
|
|
|
|
assert_equal "https://test.host/force_ssl_except_action/cheeseburger", redirect_to_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ForceSSLExcludeDevelopmentTest < ActionController::TestCase
|
|
|
|
tests ForceSSLControllerLevel
|
|
|
|
|
|
|
|
def setup
|
|
|
|
Rails.env.stubs(:development?).returns(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_development_environment_not_redirects_to_https
|
|
|
|
Rails.env.stubs(:development?).returns(true)
|
|
|
|
get :banana
|
|
|
|
assert_response 200
|
|
|
|
end
|
2011-10-08 19:38:02 -04:00
|
|
|
end
|
2012-01-12 14:31:23 -05:00
|
|
|
|
|
|
|
class ForceSSLFlashTest < ActionController::TestCase
|
|
|
|
tests ForceSSLFlash
|
|
|
|
|
|
|
|
def test_cheeseburger_redirects_to_https
|
|
|
|
get :set_flash
|
|
|
|
assert_response 302
|
|
|
|
assert_equal "http://test.host/force_ssl_flash/cheeseburger", redirect_to_url
|
|
|
|
|
|
|
|
get :cheeseburger
|
|
|
|
assert_response 301
|
|
|
|
assert_equal "https://test.host/force_ssl_flash/cheeseburger", redirect_to_url
|
|
|
|
|
|
|
|
get :use_flash
|
|
|
|
assert_equal "hello", assigns["flash_copy"]["that"]
|
|
|
|
assert_equal "hello", assigns["flashy"]
|
|
|
|
end
|
|
|
|
end
|