2011-06-19 15:26:39 +02:00
|
|
|
require File.expand_path('../spec_helper.rb', __FILE__)
|
|
|
|
|
|
|
|
describe Rack::Protection::JsonCsrf do
|
|
|
|
it_behaves_like "any rack application"
|
2011-06-20 15:47:58 +02:00
|
|
|
|
|
|
|
describe 'json response' do
|
|
|
|
before do
|
|
|
|
mock_app { |e| [200, {'Content-Type' => 'application/json'}, []]}
|
|
|
|
end
|
|
|
|
|
|
|
|
it "denies get requests with json responses with a remote referrer" do
|
|
|
|
get('/', {}, 'HTTP_REFERER' => 'http://evil.com').should_not be_ok
|
|
|
|
end
|
|
|
|
|
2012-09-05 10:08:09 +02:00
|
|
|
it "accepts requests with json responses with a remote referrer when there's an origin header set" do
|
|
|
|
get('/', {}, 'HTTP_REFERER' => 'http://good.com', 'HTTP_ORIGIN' => 'http://good.com').should be_ok
|
|
|
|
end
|
|
|
|
|
|
|
|
it "accepts requests with json responses with a remote referrer when there's an x-origin header set" do
|
|
|
|
get('/', {}, 'HTTP_REFERER' => 'http://good.com', 'HTTP_X_ORIGIN' => 'http://good.com').should be_ok
|
|
|
|
end
|
|
|
|
|
2011-06-20 15:47:58 +02:00
|
|
|
it "accepts get requests with json responses with a local referrer" do
|
|
|
|
get('/', {}, 'HTTP_REFERER' => '/').should be_ok
|
|
|
|
end
|
|
|
|
|
|
|
|
it "accepts get requests with json responses with no referrer" do
|
|
|
|
get('/', {}).should be_ok
|
|
|
|
end
|
2013-03-01 15:43:27 +11:00
|
|
|
|
|
|
|
it "accepts XHR requests" do
|
|
|
|
get('/', {}, 'HTTP_REFERER' => 'http://evil.com', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest').should be_ok
|
|
|
|
end
|
2011-06-20 15:47:58 +02:00
|
|
|
end
|
2011-08-11 09:38:46 -05:00
|
|
|
|
|
|
|
describe 'not json response' do
|
|
|
|
|
|
|
|
it "accepts get requests with 304 headers" do
|
|
|
|
mock_app { |e| [304, {}, []]}
|
|
|
|
get('/', {}).status.should == 304
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-06-19 15:26:39 +02:00
|
|
|
end
|