1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Update rspec syntax from #75

This commit is contained in:
Zachary Scott 2016-07-26 15:41:56 +09:00
parent bb118b54d5
commit 4a75394499

View file

@ -4,13 +4,15 @@ describe Rack::Protection::ContentSecurityPolicy do
it_behaves_like "any rack application"
it 'should set the Content Security Policy' do
get('/', {}, 'wants' => 'text/html').headers["Content-Security-Policy"].should == "default-src none; script-src self; connect-src self; style-src self"
expect(
get('/', {}, 'wants' => 'text/html').headers["Content-Security-Policy"]
).to eq("default-src none; script-src self; connect-src self; style-src self")
end
it 'should not set the Content Security Policy for other content types' do
headers = get('/', {}, 'wants' => 'text/foo').headers
headers["Content-Security-Policy"].should be_nil
headers["Content-Security-Policy-Report-Only"].should be_nil
expect(headers["Content-Security-Policy"]).to be_nil
expect(headers["Content-Security-Policy-Report-Only"]).to be_nil
end
it 'should allow changing the protection settings' do
@ -21,8 +23,8 @@ describe Rack::Protection::ContentSecurityPolicy do
end
headers = get('/', {}, 'wants' => 'text/html').headers
headers["Content-Security-Policy"].should == "default-src none; script-src https://cdn.mybank.net; connect-src https://api.mybank.com; font-src https://cdn.mybank.net; frame-src self; media-src https://cdn.mybank.net; style-src https://cdn.mybank.net; object-src https://cdn.mybank.net; report-uri /my_amazing_csp_report_parser; sandbox allow-scripts"
headers["Content-Security-Policy-Report-Only"].should be_nil
expect(headers["Content-Security-Policy"]).to eq("default-src none; script-src https://cdn.mybank.net; connect-src https://api.mybank.com; font-src https://cdn.mybank.net; frame-src self; media-src https://cdn.mybank.net; style-src https://cdn.mybank.net; object-src https://cdn.mybank.net; report-uri /my_amazing_csp_report_parser; sandbox allow-scripts")
expect(headers["Content-Security-Policy-Report-Only"]).to be_nil
end
it 'should allow changing report only' do
@ -33,12 +35,12 @@ describe Rack::Protection::ContentSecurityPolicy do
end
headers = get('/', {}, 'wants' => 'text/html').headers
headers["Content-Security-Policy"].should be_nil
headers["Content-Security-Policy-Report-Only"].should == "default-src none; script-src self; connect-src self; style-src self; report-uri /my_amazing_csp_report_parser"
expect(headers["Content-Security-Policy"]).to be_nil
expect(headers["Content-Security-Policy-Report-Only"]).to eq("default-src none; script-src self; connect-src self; style-src self; report-uri /my_amazing_csp_report_parser")
end
it 'should not override the header if already set' do
mock_app with_headers("Content-Security-Policy" => "default-src: none")
get('/', {}, 'wants' => 'text/html').headers["Content-Security-Policy"].should == "default-src: none"
expect(get('/', {}, 'wants' => 'text/html').headers["Content-Security-Policy"]).to eq("default-src: none")
end
end