aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorJeremy Friesen <jeremy.n.friesen@gmail.com>2012-05-31 10:06:17 -0400
committerJeremy Friesen <jeremy.n.friesen@gmail.com>2012-05-31 12:39:28 -0400
commit4791822368bf0b1238a096c353cd408c6f1fe8c4 (patch)
tree01cc7c11038ad05b7a62afb8fb75a5d946ccb775 /actionpack/test
parentc51fb024063b5369a8d99b8c6e582feaf6c5a366 (diff)
downloadrails-4791822368bf0b1238a096c353cd408c6f1fe8c4.tar.gz
rails-4791822368bf0b1238a096c353cd408c6f1fe8c4.tar.bz2
rails-4791822368bf0b1238a096c353cd408c6f1fe8c4.zip
Extracted redirect logic from ActionController::Force::ClassMethods.force_ssl
Prior to this patch the existing .force_ssl method handles both defining the filter and handling the logic for performing the redirect. With this patch the logic for redirecting to the HTTPS protocol is separated from the filter logic that determines if a redirect should occur. By separating the two levels of behavior, an instance method for ActionController (i.e. #force_ssl_redirect) is exposed and available for more granular SSL enforcement. Cleaned up indentation.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/force_ssl_test.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/actionpack/test/controller/force_ssl_test.rb b/actionpack/test/controller/force_ssl_test.rb
index 5b423c8151..6758668b7a 100644
--- a/actionpack/test/controller/force_ssl_test.rb
+++ b/actionpack/test/controller/force_ssl_test.rb
@@ -49,6 +49,15 @@ class ForceSSLFlash < ForceSSLController
end
end
+class RedirectToSSL < ForceSSLController
+ def banana
+ force_ssl_redirect || render(:text => 'monkey')
+ end
+ def cheeseburger
+ force_ssl_redirect('secure.cheeseburger.host') || render(:text => 'ihaz')
+ end
+end
+
class ForceSSLControllerLevelTest < ActionController::TestCase
tests ForceSSLControllerLevel
@@ -149,3 +158,25 @@ class ForceSSLFlashTest < ActionController::TestCase
assert_equal "hello", assigns["flashy"]
end
end
+
+class RedirectToSSLTest < ActionController::TestCase
+ tests RedirectToSSL
+ def test_banana_redirects_to_https_if_not_https
+ get :banana
+ assert_response 301
+ assert_equal "https://test.host/redirect_to_ssl/banana", redirect_to_url
+ end
+
+ def test_cheeseburgers_redirects_to_https_with_new_host_if_not_https
+ get :cheeseburger
+ assert_response 301
+ assert_equal "https://secure.cheeseburger.host/redirect_to_ssl/cheeseburger", redirect_to_url
+ end
+
+ def test_banana_does_not_redirect_if_already_https
+ request.env['HTTPS'] = 'on'
+ get :cheeseburger
+ assert_response 200
+ assert_equal 'ihaz', response.body
+ end
+end \ No newline at end of file