2012-01-30 03:57:10 -05:00
|
|
|
describe Rack::Protection::HttpOrigin do
|
|
|
|
it_behaves_like "any rack application"
|
|
|
|
|
2012-05-12 11:23:25 -04:00
|
|
|
before(:each) do
|
|
|
|
mock_app do
|
|
|
|
use Rack::Protection::HttpOrigin
|
|
|
|
run DummyApp
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-30 03:57:10 -05:00
|
|
|
%w(GET HEAD POST PUT DELETE).each do |method|
|
|
|
|
it "accepts #{method} requests with no Origin" do
|
2014-09-02 19:54:36 -04:00
|
|
|
expect(send(method.downcase, '/')).to be_ok
|
2012-01-30 03:57:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(GET HEAD).each do |method|
|
|
|
|
it "accepts #{method} requests with non-whitelisted Origin" do
|
2014-09-02 19:54:36 -04:00
|
|
|
expect(send(method.downcase, '/', {}, 'HTTP_ORIGIN' => 'http://malicious.com')).to be_ok
|
2012-01-30 03:57:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(POST PUT DELETE).each do |method|
|
|
|
|
it "denies #{method} requests with non-whitelisted Origin" do
|
2014-09-02 19:54:36 -04:00
|
|
|
expect(send(method.downcase, '/', {}, 'HTTP_ORIGIN' => 'http://malicious.com')).not_to be_ok
|
2012-01-30 03:57:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "accepts #{method} requests with whitelisted Origin" do
|
|
|
|
mock_app do
|
|
|
|
use Rack::Protection::HttpOrigin, :origin_whitelist => ['http://www.friend.com']
|
|
|
|
run DummyApp
|
|
|
|
end
|
2014-09-02 19:54:36 -04:00
|
|
|
expect(send(method.downcase, '/', {}, 'HTTP_ORIGIN' => 'http://www.friend.com')).to be_ok
|
2012-01-30 03:57:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|