blob: 3cbc111ebb787b430dc5f8c725a1f02281705873 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
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
class ForceSSLCustomDomain < ForceSSLController
force_ssl :host => "secure.test.host"
end
class ForceSSLOnlyAction < ForceSSLController
force_ssl :only => :cheeseburger
end
class ForceSSLExceptAction < ForceSSLController
force_ssl :except => :banana
end
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_banana_redirects_to_https_with_extra_params
get :banana, :token => "secret"
assert_response 301
assert_equal "https://test.host/force_ssl_controller_level/banana?token=secret", 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
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
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
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
end
|