File tree Expand file tree Collapse file tree
app/controllers/rails_admin Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ class ActionNotAllowed < ::StandardError
1111 end
1212
1313 class ApplicationController < Config . parent_controller . constantize
14+ protect_from_forgery with : :exception
15+
1416 before_action :_authenticate!
1517 before_action :_authorize!
1618 before_action :_audit!
Original file line number Diff line number Diff line change 148148 is_expected . to have_selector ( '.label-danger' )
149149 end
150150 end
151+
152+ describe 'CSRF protection' do
153+ before do
154+ allow_any_instance_of ( ActionController ::Base ) . to receive ( :protect_against_forgery? ) . and_return ( true )
155+ end
156+
157+ it 'is enforced' do
158+ visit new_path ( model_name : 'league' )
159+ fill_in 'league[name]' , with : 'National league'
160+ find ( 'input[name="authenticity_token"]' , visible : false ) . set ( "invalid token" )
161+ expect { click_button 'Save' } . to raise_error ActionController ::InvalidAuthenticityToken
162+ end
163+ end
151164end
You can’t perform that action at this time.
0 commit comments