bcurren-ssl_requirement 1.0.8 → 1.0.200807043

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -7,30 +7,30 @@ they should be redirected.
7
7
 
8
8
  Example:
9
9
 
10
- class ApplicationController < ActionController::Base
11
- include SslRequirement
10
+ class ApplicationController < ActionController::Base
11
+ include SslRequirement
12
+ end
13
+
14
+ class AccountController < ApplicationController
15
+ ssl_required :signup, :payment
16
+ ssl_allowed :index
17
+
18
+ def signup
19
+ # Non-SSL access will be redirected to SSL
20
+ end
21
+
22
+ def payment
23
+ # Non-SSL access will be redirected to SSL
12
24
  end
13
25
 
14
- class AccountController < ApplicationController
15
- ssl_required :signup, :payment
16
- ssl_allowed :index
17
-
18
- def signup
19
- # Non-SSL access will be redirected to SSL
20
- end
21
-
22
- def payment
23
- # Non-SSL access will be redirected to SSL
24
- end
25
-
26
- def index
27
- # This action will work either with or without SSL
28
- end
29
-
30
- def other
31
- # SSL access will be redirected to non-SSL
32
- end
26
+ def index
27
+ # This action will work either with or without SSL
33
28
  end
29
+
30
+ def other
31
+ # SSL access will be redirected to non-SSL
32
+ end
33
+ end
34
34
 
35
35
  If a majority (or all) of your actions require SSL, then use ssl_exceptions instead of ssl_required.
36
36
  You can list out the actions that you do NOT want to be SSL protected. Calling ssl_exceptions without
@@ -42,24 +42,14 @@ than just the declarative specification. Say, only premium accounts get SSL.
42
42
  For SSL domains that differ from the domain of the redirecting site, add the
43
43
  following code to development.rb / test.rb / production.rb:
44
44
 
45
- # Redirects to https://secure.example.com instead of the default
46
- # https://www.example.com.
47
- config.after_initialize do
48
- SslRequirement.ssl_host = 'secure.example.com'
49
- end
50
-
51
- For non-SSL domains that differ from domain of redirecting site, add the
52
- following code to development.rb / test.rb / production.rb:
53
-
54
- # Redirects to http://nonsecure.example.com instead of the default
55
- # http://www.example.com.
45
+ # Redirects to https://secure.example.com instead of the default
46
+ # https://www.example.com.
56
47
  config.after_initialize do
57
- SslRequirement.non_ssl_host = 'nonsecure.example.com'
48
+ SslRequirement.ssl_host = 'secure.example.com'
58
49
  end
59
50
 
60
51
  You are able to turn disable ssl redirects by adding the following environment configuration file:
61
-
62
- SslRequirement.disable_ssl_check = true
52
+ SslRequirement.disable_ssl_check = true
63
53
 
64
54
  P.S.: Beware when you include the SslRequirement module. At the time of
65
55
  inclusion, it'll add the before_filter that validates the declarations. Some
@@ -70,61 +60,30 @@ SSL URL Helper
70
60
  ==============
71
61
  This plugin also adds a helper a :secure option to url_for and named_routes. This property
72
62
  allows you to set a url as secure or not secure. It uses the disable_ssl_check to determine
73
- if the option should be ignored or not so you can develop as normal. It also
74
- will obey if you override SslRequirement.ssl_host or
75
- SslRequirement.non_ssl_host (see above)
63
+ if the option should be ignored or not so you can develop as normal.
76
64
 
77
65
  Here is an example of creating a secure url:
78
66
 
79
- <%= url_for(:controller => "c", :action => "a", :secure => true) %>
67
+ <%= url_for(:controller => "c", :action => "a", :secure => true) %>
80
68
 
81
69
  If disable_ssl_check returns false url_for will return the following:
82
70
 
83
- https://yoursite.com/c/a
71
+ https://yoursite.com/c/a
84
72
 
85
73
  Furthermore, you can use the secure option in a named route to create a secure form as follows:
86
74
 
87
- <% form_tag session_path(:secure => true), :class => 'home_login' do -%>
88
- <p>
89
- <label for="name">Email</label>
90
- <%= text_field_tag 'email', '', :class => 'text', :tabindex => 1 %>
91
- </p>
92
- <p>
93
- <label for="password">Password</label>
94
- <%= password_field_tag 'password', '', :class => 'text', :tabindex => 2 %>
95
- </p>
96
- <p>
97
- <%= submit_tag "Login", :id => 'login_submit', :value => "", :alt => "Login" %>
98
- </p>
99
- <% end -%>
100
-
101
- Testing with Shoulda
102
- ====================
103
-
104
- If you are using Shoulda, a few contexts and macros are provided:
105
-
106
- class RegistrationsControllerTest < ActionController::TestCase
107
- without_ssl_context do
108
- context "GET to :new" do
109
- setup do
110
- get :new
111
- end
112
- should_redirect_to_ssl
113
- end
114
- end
115
-
116
- with_ssl_context do
117
- context "GET to :new" do
118
- setup do
119
- get :new
120
- end
121
- # your usual testing goes here
122
- end
123
- end
124
- end
125
-
126
-
127
- Copyright
128
- =========
75
+ <% form_tag session_path(:secure => true), :class => 'home_login' do -%>
76
+ <p>
77
+ <label for="name">Email</label>
78
+ <%= text_field_tag 'email', '', :class => 'text', :tabindex => 1 %>
79
+ </p>
80
+ <p>
81
+ <label for="password">Password</label>
82
+ <%= password_field_tag 'password', '', :class => 'text', :tabindex => 2 %>
83
+ </p>
84
+ <p>
85
+ <%= submit_tag "Login", :id => 'login_submit', :value => "", :alt => "Login" %>
86
+ </p>
87
+ <% end -%>
129
88
 
130
89
  Copyright (c) 2005 David Heinemeier Hansson, released under the MIT license
@@ -21,7 +21,11 @@ require "#{File.dirname(__FILE__)}/url_rewriter"
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  module SslRequirement
24
- mattr_accessor :ssl_host, :non_ssl_host
24
+ mattr_reader :ssl_host
25
+
26
+ def self.ssl_host=(host)
27
+ @@ssl_host = host
28
+ end
25
29
 
26
30
  def self.included(controller)
27
31
  controller.extend(ClassMethods)
@@ -78,7 +82,7 @@ module SslRequirement
78
82
  flash.keep
79
83
  return false
80
84
  elsif request.ssl? && !ssl_required?
81
- redirect_to "http://" + (non_ssl_host || request.host) + request.request_uri
85
+ redirect_to "http://" + request.host + request.request_uri
82
86
  flash.keep
83
87
  return false
84
88
  end
data/lib/url_rewriter.rb CHANGED
@@ -6,44 +6,22 @@ module ActionController
6
6
  # Add a secure option to the rewrite method.
7
7
  def rewrite_with_secure_option(options = {})
8
8
  secure = options.delete(:secure)
9
-
10
- # if secure && ssl check is not disabled, convert to full url with https
11
9
  if !secure.nil? && !SslRequirement.disable_ssl_check?
12
10
  if secure == true || secure == 1 || secure.to_s.downcase == "true"
13
11
  options.merge!({
14
12
  :only_path => false,
15
13
  :protocol => 'https'
16
14
  })
17
-
18
- # if we've been told to use different host for ssl, use it
19
- unless SslRequirement.ssl_host.nil?
20
- options.merge! :host => SslRequirement.ssl_host
21
- end
22
-
23
- # make it non-ssl and use specified options
24
15
  else
25
16
  options.merge!({
17
+ :only_path => false,
26
18
  :protocol => 'http'
27
19
  })
28
20
  end
29
21
  end
30
-
22
+
31
23
  rewrite_without_secure_option(options)
32
24
  end
33
-
34
- # if full URL is requested for http and we've been told to use a
35
- # non-ssl host override, then use it
36
- def rewrite_with_non_ssl_host(options)
37
- if !options[:only_path] && !SslRequirement.non_ssl_host.nil?
38
- if !(/^https/ =~ (options[:protocol] || @request.protocol))
39
- options.merge! :host => SslRequirement.non_ssl_host
40
- end
41
- end
42
- rewrite_without_non_ssl_host(options)
43
- end
44
-
45
- # want with_secure_option to get run first (so chain it last)
46
- alias_method_chain :rewrite, :non_ssl_host
47
25
  alias_method_chain :rewrite, :secure_option
48
26
  end
49
27
  end
@@ -1,20 +1,20 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ssl_requirement'
3
- s.version = '1.0.8'
4
- s.date = '2009-06-22'
3
+ s.version = '1.0.200807043'
4
+ s.date = '2008-07-04'
5
5
 
6
6
  s.summary = "Allow controller actions to force SSL on specific parts of the site."
7
7
  s.description = "SSL requirement adds a declarative way of specifying that certain actions should only be allowed to run under SSL, and if they're accessed without it, they should be redirected."
8
8
 
9
- s.authors = ['RailsJedi', 'David Heinemeier Hansson', 'jcnetdev', 'bcurren', 'bmpercy']
10
- s.email = 'percival@umamibud.com'
11
- s.homepage = 'http://github.com/bmpercy/ssl_requirement'
9
+ s.authors = ['RailsJedi', 'David Heinemeier Hansson']
10
+ s.email = 'railsjedi@gmail.com'
11
+ s.homepage = 'http://github.com/jcnetdev/ssl_requirement'
12
12
 
13
13
  s.has_rdoc = true
14
14
  s.rdoc_options = ["--main", "README"]
15
15
  s.extra_rdoc_files = ["README"]
16
16
 
17
- s.add_dependency 'rails', ['>= 2.2.2']
17
+ s.add_dependency 'rails', ['>= 2.1']
18
18
 
19
19
  s.files = ["README",
20
20
  "init.rb",
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
23
23
  "rails/init.rb",
24
24
  "ssl_requirement.gemspec"]
25
25
 
26
- s.test_files = ["test/ssl_requirement_test.rb",
27
- "test/url_rewriter_test.rb"]
26
+ s.test_files = ["test/ssl_requirement_test.rb"]
27
+
28
28
  end
@@ -26,12 +26,6 @@ require "#{File.dirname(__FILE__)}/../lib/ssl_requirement"
26
26
  ActionController::Base.logger = nil
27
27
  ActionController::Routing::Routes.reload rescue nil
28
28
 
29
- # several test controllers to cover different combinations of requiring/
30
- # allowing/exceptions-ing SSL for controller actions
31
-
32
- # this first controller modifies the flash in every action so that flash
33
- # set in set_flash is eventually expired (see NOTE below...)
34
-
35
29
  class SslRequirementController < ActionController::Base
36
30
  include SslRequirement
37
31
 
@@ -39,25 +33,21 @@ class SslRequirementController < ActionController::Base
39
33
  ssl_allowed :c
40
34
 
41
35
  def a
42
- flash[:abar] = "foo"
43
36
  render :nothing => true
44
37
  end
45
38
 
46
39
  def b
47
- flash[:bbar] = "foo"
48
40
  render :nothing => true
49
41
  end
50
42
 
51
43
  def c
52
- flash[:cbar] = "foo"
53
44
  render :nothing => true
54
45
  end
55
46
 
56
47
  def d
57
- flash[:dbar] = "foo"
58
48
  render :nothing => true
59
49
  end
60
-
50
+
61
51
  def set_flash
62
52
  flash[:foo] = "bar"
63
53
  end
@@ -86,6 +76,9 @@ class SslExceptionController < ActionController::Base
86
76
  render :nothing => true
87
77
  end
88
78
 
79
+ def set_flash
80
+ flash[:foo] = "bar"
81
+ end
89
82
  end
90
83
 
91
84
  class SslAllActionsController < ActionController::Base
@@ -99,74 +92,42 @@ class SslAllActionsController < ActionController::Base
99
92
 
100
93
  end
101
94
 
102
- # NOTE: The only way I could get the flash tests to work under Rails 2.3.2
103
- # (without resorting to IntegrationTest with some artificial session
104
- # store) was to use TestCase. In TestCases, it appears that flash
105
- # messages are effectively persisted in session after the last controller
106
- # action that consumed them...so that when the TestCase inspects
107
- # the FlashHash, it will find the flash still populated, even though
108
- # the subsequent controller action won't see it.
109
- #
110
- # In addition, if no changes are made to flash in subsequent requests, the
111
- # flash is persisted forever. But if subsequent controller actions add to
112
- # flash, the older flash messages eventually disappear.
113
- #
114
- # As a result, the flash-related tests now make two requests after the
115
- # set_flash, each of these requests is also modifying flash. flash is
116
- # inspected after the second request returns.
117
- #
118
- # This feels a little hacky, so if anyone can improve it, please do so!
119
-
120
- class SslRequirementTest < ActionController::TestCase
95
+ class SslRequirementTest < Test::Unit::TestCase
121
96
  def setup
122
97
  @controller = SslRequirementController.new
123
- @ssl_host_override = 'www.example.com:80443'
124
- @non_ssl_host_override = 'www.example.com:8080'
98
+ @request = ActionController::TestRequest.new
99
+ @response = ActionController::TestResponse.new
125
100
  end
126
-
127
- # flash-related tests
128
101
 
129
102
  def test_redirect_to_https_preserves_flash
130
- assert_not_equal "on", @request.env["HTTPS"]
131
103
  get :set_flash
132
104
  get :b
133
- assert_response :redirect # check redirect happens (flash still set)
134
- get :b # get again to flush flash
135
- assert_response :redirect # make sure it happens again
136
- assert_equal "bar", flash[:foo] # the flash would be gone now if no redirect
105
+ assert_response :redirect
106
+ assert_equal "bar", flash[:foo]
137
107
  end
138
108
 
139
109
  def test_not_redirecting_to_https_does_not_preserve_the_flash
140
- assert_not_equal "on", @request.env["HTTPS"]
141
110
  get :set_flash
142
111
  get :d
143
- assert_response :success # check no redirect (flash still set)
144
- get :d # get again to flush flash
145
- assert_response :success # check no redirect
146
- assert_nil flash[:foo] # the flash should be gone now
112
+ assert_response :success
113
+ assert_nil flash[:foo]
147
114
  end
148
115
 
149
116
  def test_redirect_to_http_preserves_flash
150
117
  get :set_flash
151
118
  @request.env['HTTPS'] = "on"
152
119
  get :d
153
- assert_response :redirect # check redirect happens (flash still set)
154
- get :d # get again to flush flash
155
- assert_response :redirect # make sure redirect happens
156
- assert_equal "bar", flash[:foo] # flash would be gone now if no redirect
120
+ assert_response :redirect
121
+ assert_equal "bar", flash[:foo]
157
122
  end
158
123
 
159
124
  def test_not_redirecting_to_http_does_not_preserve_the_flash
160
125
  get :set_flash
161
126
  @request.env['HTTPS'] = "on"
162
127
  get :a
163
- assert_response :success # no redirect (flash still set)
164
- get :a # get again to flush flash
165
- assert_response :success # no redirect
166
- assert_nil flash[:foo] # flash should be gone now
128
+ assert_response :success
129
+ assert_nil flash[:foo]
167
130
  end
168
-
169
- # ssl required/allowed/exceptions testing
170
131
 
171
132
  def test_required_without_ssl
172
133
  assert_not_equal "on", @request.env["HTTPS"]
@@ -194,12 +155,13 @@ class SslRequirementTest < ActionController::TestCase
194
155
 
195
156
  def test_ssl_exceptions_without_ssl
196
157
  @controller = SslExceptionController.new
197
- assert_not_equal "on", @request.env["HTTPS"]
198
158
  get :a
199
159
  assert_response :redirect
200
160
  assert_match %r{^https://}, @response.headers['Location']
161
+
201
162
  get :b
202
163
  assert_response :success
164
+
203
165
  get :c # c is not explicity in ssl_required, but it is not listed in ssl_exceptions
204
166
  assert_response :redirect
205
167
  assert_match %r{^https://}, @response.headers['Location']
@@ -210,6 +172,8 @@ class SslRequirementTest < ActionController::TestCase
210
172
  @request.env['HTTPS'] = "on"
211
173
  get :a
212
174
  assert_response :success
175
+
176
+ @request.env['HTTPS'] = "on"
213
177
  get :c
214
178
  assert_response :success
215
179
  end
@@ -217,6 +181,7 @@ class SslRequirementTest < ActionController::TestCase
217
181
  def test_ssl_all_actions_without_ssl
218
182
  @controller = SslAllActionsController.new
219
183
  get :a
184
+
220
185
  assert_response :redirect
221
186
  assert_match %r{^https://}, @response.headers['Location']
222
187
  end
@@ -251,50 +216,5 @@ class SslRequirementTest < ActionController::TestCase
251
216
  ensure
252
217
  SslRequirement.disable_ssl_check = false
253
218
  end
254
-
255
- # testing overriding hostnames for ssl, non-ssl
256
-
257
- # test for overriding (or not) the ssl_host and non_ssl_host variables
258
- # using actions a (ssl required) and d (ssl not required or allowed)
259
-
260
- def test_ssl_redirect_with_ssl_host
261
- SslRequirement.ssl_host = @ssl_host_override
262
- assert_not_equal "on", @request.env["HTTPS"]
263
- get :a
264
- assert_response :redirect
265
- assert_match Regexp.new("^https://#{@ssl_host_override}"),
266
- @response.headers['Location']
267
- SslRequirement.ssl_host = nil
268
- end
269
-
270
- def test_ssl_redirect_without_ssl_host
271
- SslRequirement.ssl_host = nil
272
- assert_not_equal "on", @request.env["HTTPS"]
273
- get :a
274
- assert_response :redirect
275
- assert_match Regexp.new("^https://"), @response.headers['Location']
276
- assert_no_match Regexp.new("^https://#{@ssl_host_override}"),
277
- @response.headers['Location']
278
- end
279
-
280
- def test_non_ssl_redirect_with_non_ssl_host
281
- SslRequirement.non_ssl_host = @non_ssl_host_override
282
- @request.env['HTTPS'] = 'on'
283
- get :d
284
- assert_response :redirect
285
- assert_match Regexp.new("^http://#{@non_ssl_host_override}"),
286
- @response.headers['Location']
287
- SslRequirement.non_ssl_host = nil
288
- end
289
-
290
- def test_non_ssl_redirect_without_non_ssl_host
291
- SslRequirement.non_ssl_host = nil
292
- @request.env['HTTPS'] = 'on'
293
- get :d
294
- assert_response :redirect
295
- assert_match Regexp.new("^http://"), @response.headers['Location']
296
- assert_no_match Regexp.new("^http://#{@non_ssl_host_override}"),
297
- @response.headers['Location']
298
- end
299
-
300
- end
219
+
220
+ end
metadata CHANGED
@@ -1,33 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcurren-ssl_requirement
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.200807043
5
5
  platform: ruby
6
6
  authors:
7
7
  - RailsJedi
8
8
  - David Heinemeier Hansson
9
- - jcnetdev
10
- - bcurren
11
- - bmpercy
12
9
  autorequire:
13
10
  bindir: bin
14
11
  cert_chain: []
15
12
 
16
- date: 2009-06-22 00:00:00 -07:00
13
+ date: 2008-07-04 00:00:00 -07:00
17
14
  default_executable:
18
15
  dependencies:
19
16
  - !ruby/object:Gem::Dependency
20
17
  name: rails
21
- type: :runtime
22
18
  version_requirement:
23
19
  version_requirements: !ruby/object:Gem::Requirement
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- version: 2.2.2
23
+ version: "2.1"
28
24
  version:
29
25
  description: SSL requirement adds a declarative way of specifying that certain actions should only be allowed to run under SSL, and if they're accessed without it, they should be redirected.
30
- email: percival@umamibud.com
26
+ email: railsjedi@gmail.com
31
27
  executables: []
32
28
 
33
29
  extensions: []
@@ -42,8 +38,7 @@ files:
42
38
  - rails/init.rb
43
39
  - ssl_requirement.gemspec
44
40
  has_rdoc: true
45
- homepage: http://github.com/bmpercy/ssl_requirement
46
- licenses:
41
+ homepage: http://github.com/jcnetdev/ssl_requirement
47
42
  post_install_message:
48
43
  rdoc_options:
49
44
  - --main
@@ -65,10 +60,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
60
  requirements: []
66
61
 
67
62
  rubyforge_project:
68
- rubygems_version: 1.3.5
63
+ rubygems_version: 1.2.0
69
64
  signing_key:
70
65
  specification_version: 2
71
66
  summary: Allow controller actions to force SSL on specific parts of the site.
72
67
  test_files:
73
68
  - test/ssl_requirement_test.rb
74
- - test/url_rewriter_test.rb
@@ -1,142 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
-
3
- require 'rubygems'
4
- require 'test/unit'
5
- require 'action_controller'
6
- require 'action_controller/test_process'
7
-
8
- require "ssl_requirement"
9
-
10
- # Show backtraces for deprecated behavior for quicker cleanup.
11
- ActiveSupport::Deprecation.debug = true
12
- ActionController::Base.logger = nil
13
- ActionController::Routing::Routes.reload rescue nil
14
-
15
- class UrlRewriterTest < Test::Unit::TestCase
16
- def setup
17
- @request = ActionController::TestRequest.new
18
- @params = {}
19
- @rewriter = ActionController::UrlRewriter.new(@request, @params)
20
-
21
- @ssl_host_override = "www.example.com:80443"
22
- @non_ssl_host_override = "www.example.com:8080"
23
-
24
- SslRequirement.ssl_host = nil
25
- SslRequirement.non_ssl_host = nil
26
-
27
- puts @url_rewriter.to_s
28
- end
29
-
30
- def test_rewrite_secure_false
31
- SslRequirement.disable_ssl_check = false
32
- assert_equal('http://test.host/c/a',
33
- @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => false)
34
- )
35
- assert_equal('/c/a',
36
- @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => false,
37
- :only_path => true)
38
- )
39
-
40
- SslRequirement.disable_ssl_check = true
41
- assert_equal('http://test.host/c/a',
42
- @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => false)
43
- )
44
- assert_equal('/c/a',
45
- @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => false,
46
- :only_path => true)
47
- )
48
- end
49
-
50
- def test_rewrite_secure_true
51
- SslRequirement.disable_ssl_check = false
52
- assert_equal('https://test.host/c/a',
53
- @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => true)
54
- )
55
- assert_equal('https://test.host/c/a',
56
- @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => true, :only_path => true)
57
- )
58
-
59
- SslRequirement.disable_ssl_check = true
60
- assert_equal('http://test.host/c/a',
61
- @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => true)
62
- )
63
- assert_equal('/c/a',
64
- @rewriter.rewrite(:controller => 'c', :action => 'a', :secure => true, :only_path => true)
65
- )
66
- end
67
-
68
- def test_rewrite_secure_not_specified
69
- SslRequirement.disable_ssl_check = false
70
- assert_equal('http://test.host/c/a',
71
- @rewriter.rewrite(:controller => 'c', :action => 'a')
72
- )
73
- assert_equal('/c/a',
74
- @rewriter.rewrite(:controller => 'c', :action => 'a', :only_path => true)
75
- )
76
-
77
- SslRequirement.disable_ssl_check = true
78
- assert_equal('http://test.host/c/a',
79
- @rewriter.rewrite(:controller => 'c', :action => 'a')
80
- )
81
- assert_equal('/c/a',
82
- @rewriter.rewrite(:controller => 'c', :action => 'a', :only_path => true)
83
- )
84
- end
85
-
86
- # tests for ssl_host overriding
87
-
88
- def test_rewrite_secure_with_ssl_host
89
- SslRequirement.disable_ssl_check = false
90
- SslRequirement.ssl_host = @ssl_host_override
91
- assert_equal("https://#{@ssl_host_override}/c/a",
92
- @rewriter.rewrite(:controller => 'c', :action => 'a',
93
- :secure => true))
94
- assert_equal("https://#{@ssl_host_override}/c/a",
95
- @rewriter.rewrite(:controller => 'c', :action => 'a',
96
- :secure => true, :only_path => true))
97
- SslRequirement.ssl_host = nil
98
- end
99
-
100
- def test_rewrite_non_secure_with_non_ssl_host
101
- SslRequirement.disable_ssl_check = false
102
- SslRequirement.non_ssl_host = @non_ssl_host_override
103
-
104
- # with secure option
105
- assert_equal("http://#{@non_ssl_host_override}/c/a",
106
- @rewriter.rewrite(:controller => 'c', :action => 'a',
107
- :secure => false))
108
- assert_equal("/c/a",
109
- @rewriter.rewrite(:controller => 'c', :action => 'a',
110
- :secure => false, :only_path => true))
111
-
112
- # without secure option
113
- assert_equal("http://#{@non_ssl_host_override}/c/a",
114
- @rewriter.rewrite(:controller => 'c', :action => 'a'))
115
- assert_equal("/c/a",
116
- @rewriter.rewrite(:controller => 'c', :action => 'a',
117
- :only_path => true))
118
- SslRequirement.non_ssl_host = nil
119
- end
120
-
121
- def test_rewrite_non_secure_with_non_ssl_host_disable_check
122
- SslRequirement.disable_ssl_check = true
123
- SslRequirement.non_ssl_host = @non_ssl_host_override
124
-
125
- # with secure option
126
- assert_equal("http://#{@non_ssl_host_override}/c/a",
127
- @rewriter.rewrite(:controller => 'c', :action => 'a',
128
- :secure => false))
129
- assert_equal("/c/a",
130
- @rewriter.rewrite(:controller => 'c', :action => 'a',
131
- :secure => false, :only_path => true))
132
-
133
- # without secure option
134
- assert_equal("http://#{@non_ssl_host_override}/c/a",
135
- @rewriter.rewrite(:controller => 'c', :action => 'a'))
136
- assert_equal("/c/a",
137
- @rewriter.rewrite(:controller => 'c', :action => 'a',
138
- :only_path => true))
139
- SslRequirement.non_ssl_host = nil
140
- end
141
-
142
- end