2011-05-23 11:36:16 -04:00
|
|
|
require File.expand_path('../spec_helper.rb', __FILE__)
|
|
|
|
|
|
|
|
describe Rack::Protection::XSSHeader do
|
|
|
|
it_behaves_like "any rack application"
|
2011-05-24 05:04:49 -04:00
|
|
|
|
|
|
|
it 'should set the X-XSS-Protection' do
|
2012-12-10 10:42:48 -05:00
|
|
|
get('/', {}, 'wants' => 'text/html;charset=utf-8').headers["X-XSS-Protection"].should == "1; mode=block"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should set the X-XSS-Protection for XHTML' do
|
|
|
|
get('/', {}, 'wants' => 'application/xhtml+xml').headers["X-XSS-Protection"].should == "1; mode=block"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not set the X-XSS-Protection for other content types' do
|
|
|
|
get('/', {}, 'wants' => 'application/foo').headers["X-XSS-Protection"].should be_nil
|
2011-05-24 05:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should allow changing the protection mode' do
|
|
|
|
# I have no clue what other modes are available
|
|
|
|
mock_app do
|
|
|
|
use Rack::Protection::XSSHeader, :xss_mode => :foo
|
|
|
|
run DummyApp
|
|
|
|
end
|
|
|
|
|
2012-12-10 10:42:48 -05:00
|
|
|
get('/', {}, 'wants' => 'application/xhtml').headers["X-XSS-Protection"].should == "1; mode=foo"
|
2011-05-24 05:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not override the header if already set' do
|
|
|
|
mock_app with_headers("X-XSS-Protection" => "0")
|
2012-12-10 10:42:48 -05:00
|
|
|
get('/', {}, 'wants' => 'text/html').headers["X-XSS-Protection"].should == "0"
|
2011-05-24 05:04:49 -04:00
|
|
|
end
|
2012-06-28 07:33:09 -04:00
|
|
|
|
|
|
|
it 'should set the X-Content-Type-Options' do
|
2012-12-10 10:42:48 -05:00
|
|
|
get('/', {}, 'wants' => 'text/html').header["X-Content-Type-Options"].should == "nosniff"
|
2012-06-28 07:33:09 -04:00
|
|
|
end
|
|
|
|
|
2013-02-28 23:36:05 -05:00
|
|
|
|
|
|
|
it 'should set the X-Content-Type-Options for other content types' do
|
|
|
|
get('/', {}, 'wants' => 'application/foo').header["X-Content-Type-Options"].should == "nosniff"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-06-28 07:33:09 -04:00
|
|
|
it 'should allow changing the nosniff-mode off' do
|
|
|
|
mock_app do
|
|
|
|
use Rack::Protection::XSSHeader, :nosniff => false
|
|
|
|
run DummyApp
|
|
|
|
end
|
|
|
|
|
|
|
|
get('/').headers["X-Content-Type-Options"].should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not override the header if already set X-Content-Type-Options' do
|
|
|
|
mock_app with_headers("X-Content-Type-Options" => "sniff")
|
2012-12-10 10:42:48 -05:00
|
|
|
get('/', {}, 'wants' => 'text/html').headers["X-Content-Type-Options"].should == "sniff"
|
2012-06-28 07:33:09 -04:00
|
|
|
end
|
2011-05-23 11:36:16 -04:00
|
|
|
end
|