Permalink
Browse files

nw/desi - Added hook for disabling SSL checks globally

  • Loading branch information...
1 parent 2477a0f commit 4504a9d59d3e38d02ac82af927bc20d57593eeea pivotal committed Jun 26, 2008
Showing with 21 additions and 0 deletions.
  1. +9 −0 lib/ssl_requirement.rb
  2. +12 −0 test/ssl_requirement_test.rb
View
@@ -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)
@@ -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?
@@ -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.