Skip to content

Commit

Permalink
nw/desi - Added hook for disabling SSL checks globally
Browse files Browse the repository at this point in the history
  • Loading branch information
pivotal committed Jun 26, 2008
1 parent 2477a0f commit 4504a9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/ssl_requirement.rb
Expand Up @@ -24,6 +24,14 @@ def self.included(controller)
controller.before_filter(:ensure_proper_protocol)
end

def self.disable_ssl_check?
@@disable_ssl_check ||= false
end

def self.disable_ssl_check=(value)
@@disable_ssl_check = value
end

module ClassMethods
# Specifies that the named actions requires an SSL connection to be performed (which is enforced by ensure_proper_protocol).
def ssl_required(*actions)
Expand Down Expand Up @@ -58,6 +66,7 @@ def ssl_allowed?

private
def ensure_proper_protocol
return true if SslRequirement.disable_ssl_check?
return true if ssl_allowed?

if ssl_required? && !request.ssl?
Expand Down
12 changes: 12 additions & 0 deletions test/ssl_requirement_test.rb
Expand Up @@ -204,5 +204,17 @@ def test_allowed_with_ssl
get :c
assert_response :success
end

def test_disable_ssl_check
SslRequirement.disable_ssl_check = true

assert_not_equal "on", @request.env["HTTPS"]
get :a
assert_response :success
get :b
assert_response :success
ensure
SslRequirement.disable_ssl_check = false
end

end

0 comments on commit 4504a9d

Please sign in to comment.