0
@@ -5,13 +5,6 @@ ActionController::Routing::Routes.draw do |map|
0
map.connect ':controller/:action/:id'
0
-# simulates cookie session store
0
- def self.generate_digest(data)
0
- Digest::SHA1.hexdigest("secure")
0
# common controller actions
0
module RequestForgeryProtectionActions
0
class RequestForgeryProtectionController < ActionController::Base
0
include RequestForgeryProtectionActions
0
- protect_from_forgery :only => :index, :secret => 'abc'
0
-class RequestForgeryProtectionWithoutSecretController < ActionController::Base
0
- include RequestForgeryProtectionActions
0
-# no token is given, assume the cookie store is used
0
-class CsrfCookieMonsterController < ActionController::Base
0
- include RequestForgeryProtectionActions
0
protect_from_forgery :only => :index
0
-# sessions are turned off
0
-class SessionOffController < ActionController::Base
0
- protect_from_forgery :secret => 'foobar'
0
- def rescue_action(e) raise e end
0
- include RequestForgeryProtectionActions
0
-class FreeCookieController < CsrfCookieMonsterController
0
+class FreeCookieController < RequestForgeryProtectionController
0
self.allow_forgery_protection = false
0
@@ -237,45 +211,9 @@ class RequestForgeryProtectionControllerTest < ActionController::TestCase
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
- @token = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), 'abc', '123')
0
- ActionController::Base.request_forgery_protection_token = :authenticity_token
0
+ @token = "cf50faa3fe97702ca1ae"
0
-class RequestForgeryProtectionWithoutSecretControllerTest < ActionController::TestCase
0
- @controller = RequestForgeryProtectionWithoutSecretController.new
0
- @request = ActionController::TestRequest.new
0
- @response = ActionController::TestResponse.new
0
- class << @request.session
0
- def session_id() '123' end
0
- @token = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), 'abc', '123')
0
- ActionController::Base.request_forgery_protection_token = :authenticity_token
0
- # def test_should_raise_error_without_secret
0
- # assert_raises ActionController::InvalidAuthenticityToken do
0
-class CsrfCookieMonsterControllerTest < ActionController::TestCase
0
- include RequestForgeryProtectionTests
0
- @controller = CsrfCookieMonsterController.new
0
- @request = ActionController::TestRequest.new
0
- @response = ActionController::TestResponse.new
0
- class << @request.session
0
- # simulate a cookie session store
0
- @request.session.dbman = FakeSessionDbMan
0
- @token = Digest::SHA1.hexdigest("secure")
0
+ ActiveSupport::SecureRandom.stubs(:base64).returns(@token)
0
ActionController::Base.request_forgery_protection_token = :authenticity_token
0
@@ -285,7 +223,9 @@ class FreeCookieControllerTest < ActionController::TestCase
0
@controller = FreeCookieController.new
0
@request = ActionController::TestRequest.new
0
@response = ActionController::TestResponse.new
0
- @token = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), 'abc', '123')
0
+ @token = "cf50faa3fe97702ca1ae"
0
+ ActiveSupport::SecureRandom.stubs(:base64).returns(@token)
0
def test_should_not_render_form_with_token_tag
0
@@ -304,24 +244,3 @@ class FreeCookieControllerTest < ActionController::TestCase
0
-class SessionOffControllerTest < ActionController::TestCase
0
- @controller = SessionOffController.new
0
- @request = ActionController::TestRequest.new
0
- @response = ActionController::TestResponse.new
0
- @token = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), 'abc', '123')
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