Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ If a majority (or all) of your actions require SSL, then use `ssl_exceptions` in
You can list out the actions that you do NOT want to be SSL protected. Calling `ssl_exceptions` without
any actions listed will make ALL actions SSL protected.

To allow SSL for any action `use ssl_allowed` and pass in `:all`
To allow or require SSL for all actions, pass `:all` to their respective methods.

Example:

# This will enable SSL for any action in your application.
# This will enable SSL for all actions in your application.
class ApplicationController < ActionController::Base
include ::SslRequirement

Expand Down
2 changes: 1 addition & 1 deletion lib/ssl_requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def ssl_required?
except = self.class.ssl_required_except_actions

unless except
required.include?(action_name.to_sym)
required == [:all] || required.include?(action_name.to_sym)
else
!except.include?(action_name.to_sym)
end
Expand Down
63 changes: 63 additions & 0 deletions test/ssl_requirement_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,29 @@ class SslAllowAllAndRequireController < SslAllowAllActionsController
ssl_required :a, :b
end

class SslRequireAllActionsController < ActionController::Base
include SslRequirement
include ROUTES.url_helpers

ssl_required :all

def a
render :nothing => true
end

def b
render :nothing => true
end

def self._routes
ROUTES
end
end

class SslRequireAllActionsWithExceptionController < SslRequireAllActionsController
ssl_exceptions :b
end

# NOTE: The only way I could get the flash tests to work under Rails 2.3.2
# (without resorting to IntegrationTest with some artificial session
# store) was to use TestCase. In TestCases, it appears that flash
Expand Down Expand Up @@ -438,4 +461,44 @@ def test_required_without_ssl_and_allowed_all
assert_match %r{^https://}, @response.headers['Location']
end

# test requiring ssl on any action by the :all symbol
def test_require_all
@controller = SslRequireAllActionsController.new

assert_not_equal "on", @request.env["HTTPS"]

get :a
assert_response :redirect

get :b
assert_response :redirect

@request.env["HTTPS"] = "on"

get :a
assert_response :success

get :b
assert_response :success
end

def test_require_all_with_exceptions
@controller = SslRequireAllActionsWithExceptionController.new

assert_not_equal "on", @request.env["HTTPS"]

get :a
assert_response :redirect

get :b
assert_response :success

@request.env["HTTPS"] = "on"

get :a
assert_response :success

get :b
assert_response :redirect
end
end