0
@@ -77,57 +77,61 @@ module RequestForgeryProtectionTests
0
ActionController::Base.request_forgery_protection_token = nil
0
def test_should_render_form_with_token_tag
0
- assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token
0
+ assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token
0
+ def test_should_render_button_to_with_token_tag
0
+ assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token
0
+ def test_should_render_remote_form_with_only_one_token_parameter
0
+ assert_equal 1, @response.body.scan(@token).size
0
+ def test_should_allow_get
0
+ assert_response :success
0
+ def test_should_allow_post_without_token_on_unsafe_action
0
+ assert_response :success
0
+ def test_should_not_allow_html_post_without_token
0
+ @request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
0
+ assert_raises(ActionController::InvalidAuthenticityToken) { post :index, :format => :html }
0
- def test_should_render_button_to_with_token_tag
0
- assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token
0
- def test_should_render_remote_form_with_only_one_token_parameter
0
- assert_equal 1, @response.body.scan(@token).size
0
- def test_should_allow_get
0
- assert_response :success
0
+ def test_should_not_allow_html_put_without_token
0
+ @request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
0
+ assert_raises(ActionController::InvalidAuthenticityToken) { put :index, :format => :html }
0
- def test_should_allow_post_without_token_on_unsafe_action
0
- assert_response :success
0
+ def test_should_not_allow_html_delete_without_token
0
+ @request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
0
+ assert_raises(ActionController::InvalidAuthenticityToken) { delete :index, :format => :html }
0
- def test_should_not_allow_post_without_token
0
- assert_raises(ActionController::InvalidAuthenticityToken) { post :index }
0
- def test_should_not_allow_put_without_token
0
- assert_raises(ActionController::InvalidAuthenticityToken) { put :index }
0
- def test_should_not_allow_delete_without_token
0
- assert_raises(ActionController::InvalidAuthenticityToken) { delete :index }
0
- def test_should_not_allow_api_formatted_post_without_token
0
- assert_raises(ActionController::InvalidAuthenticityToken) do
0
+ def test_should_allow_api_formatted_post_without_token
0
+ assert_nothing_raised do
0
post :index, :format => 'xml'
0
def test_should_not_allow_api_formatted_put_without_token
0
- assert_
raises(ActionController::InvalidAuthenticityToken) do
0
+ assert_
nothing_raised do
0
put :index, :format => 'xml'
0
- def test_should_not_allow_api_formatted_delete_without_token
0
- assert_raises(ActionController::InvalidAuthenticityToken) do
0
+ def test_should_allow_api_formatted_delete_without_token
0
+ assert_nothing_raised do
0
delete :index, :format => 'xml'
0
@@ -174,16 +178,20 @@ module RequestForgeryProtectionTests
0
- def test_should_not_allow_xhr_post_without_token
0
- assert_raises(ActionController::InvalidAuthenticityToken) { xhr :post, :index }
0
+ def test_should_allow_xhr_post_without_token
0
+ assert_nothing_raised { xhr :post, :index }
0
+ def test_should_not_allow_xhr_post_with_html_without_token
0
+ @request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
0
+ assert_raise(ActionController::InvalidAuthenticityToken) { xhr :post, :index }
0
- def test_should_not_allow_xhr_put_without_token
0
- assert_raises(ActionController::InvalidAuthenticityToken) { xhr :put, :index }
0
+ def test_should_allow_xhr_put_without_token
0
+ assert_nothing_raised { xhr :put, :index }
0
- def test_should_not_allow_xhr_delete_without_token
0
- assert_raises(ActionController::InvalidAuthenticityToken) { xhr :delete, :index }
0
+ def test_should_allow_xhr_delete_without_token
0
+ assert_nothing_raised { xhr :delete, :index }
0
def test_should_allow_post_with_token
0
@@ -227,6 +235,7 @@ class RequestForgeryProtectionControllerTest < Test::Unit::TestCase
0
@controller = RequestForgeryProtectionController.new
0
@request = ActionController::TestRequest.new
0
+ @request.format = :html
0
@response = ActionController::TestResponse.new
0
class << @request.session
0
def session_id() '123' end
0
@@ -248,11 +257,11 @@ class RequestForgeryProtectionWithoutSecretControllerTest < Test::Unit::TestCase
0
ActionController::Base.request_forgery_protection_token = :authenticity_token
0
- def test_should_raise_error_without_secret
0
- assert_raises ActionController::InvalidAuthenticityToken do
0
+ # def test_should_raise_error_without_secret
0
+ # assert_raises ActionController::InvalidAuthenticityToken do
0
class CsrfCookieMonsterControllerTest < Test::Unit::TestCase
0
@@ -304,10 +313,15 @@ class SessionOffControllerTest < Test::Unit::TestCase
0
@token = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), 'abc', '123')
0
- def test_should_raise_correct_exception
0
- @request.session = {} # session(:off) doesn't appear to work with controller tests
0
- assert_raises(ActionController::InvalidAuthenticityToken) do
0
- post :index, :authenticity_token => @token
0
+ # TODO: Rewrite this test.
0
+ # This test was passing but for the wrong reason.
0
+ # Sessions aren't really being turned off, so an exception was raised
0
+ # because sessions weren't on - not because the token didn't match.
0
+ # def test_should_raise_correct_exception
0
+ # @request.session = {} # session(:off) doesn't appear to work with controller tests
0
+ # assert_raises(ActionController::InvalidAuthenticityToken) do
0
+ # post :index, :authenticity_token => @token, :format => :html
So…. What does this mean, exactly?
I don’t understand this. I have ajax calls that return json, aren’t they also susceptible to request forgery?
it’s the request content type, not the response content type. i.e. what’s in the client’s Content-Type header.
This is never anything other than the browser_generated_types (see later commit).