Skip to content

Commit 865ff8b

Browse files
committed
add tests for secure_headers_options_for
1 parent cdc74c5 commit 865ff8b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

fixtures/rails_3_2_12_no_init/app/controllers/other_things_controller.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,18 @@ class OtherThingsController < ApplicationController
33
def index
44

55
end
6+
7+
def other_action
8+
render :text => 'yooooo'
9+
end
10+
11+
def secure_header_options_for(header, options)
12+
if params[:action] == "other_action"
13+
if header == :csp
14+
options.merge(:style_src => 'self')
15+
end
16+
else
17+
options
18+
end
19+
end
620
end

fixtures/rails_3_2_12_no_init/spec/controllers/other_things_controller_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
expect(response.headers['X-Frame-Options']).to eq(SecureHeaders::XFrameOptions::Constants::DEFAULT_VALUE)
1313
end
1414

15-
it "sets the X-WebKit-CSP header" do
15+
it "sets the CSP header" do
1616
get :index
1717
expect(response.headers['Content-Security-Policy-Report-Only']).to eq("default-src 'self'; img-src 'self' data:;")
1818
end
1919

20+
it "sets per-action values based on secure_header_options_for" do
21+
# munges :style_src => self into policy
22+
get :other_action
23+
expect(response.headers['Content-Security-Policy-Report-Only']).to eq("default-src 'self'; img-src 'self' data:; style-src 'self';")
24+
end
25+
2026
#mock ssl
2127
it "sets the Strict-Transport-Security header" do
2228
request.env['HTTPS'] = 'on'

fixtures/rails_4_1_8/app/controllers/other_things_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ class OtherThingsController < ApplicationController
22
def index
33

44
end
5-
end
5+
end

0 commit comments

Comments
 (0)