secure_headers 6.3.1 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/Gemfile +3 -1
  4. data/README.md +22 -17
  5. data/lib/secure_headers/configuration.rb +11 -7
  6. data/lib/secure_headers/headers/clear_site_data.rb +4 -4
  7. data/lib/secure_headers/headers/content_security_policy.rb +25 -38
  8. data/lib/secure_headers/headers/content_security_policy_config.rb +17 -54
  9. data/lib/secure_headers/headers/cookie.rb +2 -2
  10. data/lib/secure_headers/headers/expect_certificate_transparency.rb +2 -2
  11. data/lib/secure_headers/headers/policy_management.rb +54 -12
  12. data/lib/secure_headers/headers/referrer_policy.rb +1 -1
  13. data/lib/secure_headers/headers/strict_transport_security.rb +1 -1
  14. data/lib/secure_headers/headers/x_content_type_options.rb +1 -1
  15. data/lib/secure_headers/headers/x_download_options.rb +2 -2
  16. data/lib/secure_headers/headers/x_frame_options.rb +1 -1
  17. data/lib/secure_headers/headers/x_permitted_cross_domain_policies.rb +2 -2
  18. data/lib/secure_headers/headers/x_xss_protection.rb +2 -2
  19. data/lib/secure_headers/railtie.rb +5 -5
  20. data/lib/secure_headers/version.rb +1 -1
  21. data/lib/secure_headers/view_helper.rb +7 -6
  22. data/lib/tasks/tasks.rake +6 -7
  23. data/secure_headers.gemspec +17 -7
  24. metadata +22 -67
  25. data/.github/ISSUE_TEMPLATE.md +0 -41
  26. data/.github/PULL_REQUEST_TEMPLATE.md +0 -20
  27. data/.github/workflows/build.yml +0 -24
  28. data/.github/workflows/sync.yml +0 -20
  29. data/.gitignore +0 -13
  30. data/.rspec +0 -3
  31. data/.rubocop.yml +0 -4
  32. data/.ruby-gemset +0 -1
  33. data/.ruby-version +0 -1
  34. data/CODE_OF_CONDUCT.md +0 -46
  35. data/CONTRIBUTING.md +0 -41
  36. data/Guardfile +0 -13
  37. data/Rakefile +0 -32
  38. data/docs/cookies.md +0 -65
  39. data/docs/hashes.md +0 -64
  40. data/docs/named_overrides_and_appends.md +0 -104
  41. data/docs/per_action_configuration.md +0 -141
  42. data/docs/sinatra.md +0 -25
  43. data/docs/upgrading-to-3-0.md +0 -42
  44. data/docs/upgrading-to-4-0.md +0 -35
  45. data/docs/upgrading-to-5-0.md +0 -15
  46. data/docs/upgrading-to-6-0.md +0 -50
  47. data/spec/lib/secure_headers/configuration_spec.rb +0 -121
  48. data/spec/lib/secure_headers/headers/clear_site_data_spec.rb +0 -87
  49. data/spec/lib/secure_headers/headers/content_security_policy_spec.rb +0 -165
  50. data/spec/lib/secure_headers/headers/cookie_spec.rb +0 -179
  51. data/spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb +0 -42
  52. data/spec/lib/secure_headers/headers/policy_management_spec.rb +0 -260
  53. data/spec/lib/secure_headers/headers/referrer_policy_spec.rb +0 -91
  54. data/spec/lib/secure_headers/headers/strict_transport_security_spec.rb +0 -33
  55. data/spec/lib/secure_headers/headers/x_content_type_options_spec.rb +0 -31
  56. data/spec/lib/secure_headers/headers/x_download_options_spec.rb +0 -29
  57. data/spec/lib/secure_headers/headers/x_frame_options_spec.rb +0 -36
  58. data/spec/lib/secure_headers/headers/x_permitted_cross_domain_policies_spec.rb +0 -48
  59. data/spec/lib/secure_headers/headers/x_xss_protection_spec.rb +0 -47
  60. data/spec/lib/secure_headers/middleware_spec.rb +0 -117
  61. data/spec/lib/secure_headers/view_helpers_spec.rb +0 -191
  62. data/spec/lib/secure_headers_spec.rb +0 -516
  63. data/spec/spec_helper.rb +0 -64
@@ -1,260 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- module SecureHeaders
5
- describe PolicyManagement do
6
- before(:each) do
7
- reset_config
8
- Configuration.default
9
- end
10
-
11
- let (:default_opts) do
12
- {
13
- default_src: %w(https:),
14
- img_src: %w(https: data:),
15
- script_src: %w('unsafe-inline' 'unsafe-eval' https: data:),
16
- style_src: %w('unsafe-inline' https: about:),
17
- report_uri: %w(/csp_report)
18
- }
19
- end
20
-
21
- describe "#validate_config!" do
22
- it "accepts all keys" do
23
- # (pulled from README)
24
- config = {
25
- # "meta" values. these will shape the header, but the values are not included in the header.
26
- report_only: false,
27
- preserve_schemes: true, # default: false. Schemes are removed from host sources to save bytes and discourage mixed content.
28
-
29
- # directive values: these values will directly translate into source directives
30
- default_src: %w(https: 'self'),
31
-
32
- base_uri: %w('self'),
33
- block_all_mixed_content: true, # see [http://www.w3.org/TR/mixed-content/](http://www.w3.org/TR/mixed-content/)
34
- connect_src: %w(wss:),
35
- child_src: %w('self' *.twimg.com itunes.apple.com),
36
- font_src: %w('self' data:),
37
- form_action: %w('self' github.com),
38
- frame_ancestors: %w('none'),
39
- frame_src: %w('self' *.twimg.com itunes.apple.com),
40
- img_src: %w(mycdn.com data:),
41
- manifest_src: %w(manifest.com),
42
- media_src: %w(utoob.com),
43
- navigate_to: %w(netscape.com),
44
- object_src: %w('self'),
45
- plugin_types: %w(application/x-shockwave-flash),
46
- prefetch_src: %w(fetch.com),
47
- require_sri_for: %w(script style),
48
- script_src: %w('self'),
49
- style_src: %w('unsafe-inline'),
50
- upgrade_insecure_requests: true, # see https://www.w3.org/TR/upgrade-insecure-requests/
51
- worker_src: %w(worker.com),
52
-
53
- report_uri: %w(https://example.com/uri-directive),
54
- }
55
-
56
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(config))
57
- end
58
-
59
- it "requires a :default_src value" do
60
- expect do
61
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(script_src: %w('self')))
62
- end.to raise_error(ContentSecurityPolicyConfigError)
63
- end
64
-
65
- it "requires a :script_src value" do
66
- expect do
67
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_src: %w('self')))
68
- end.to raise_error(ContentSecurityPolicyConfigError)
69
- end
70
-
71
- it "accepts OPT_OUT as a script-src value" do
72
- expect do
73
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_src: %w('self'), script_src: OPT_OUT))
74
- end.to_not raise_error
75
- end
76
-
77
- it "requires :report_only to be a truthy value" do
78
- expect do
79
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_opts.merge(report_only: "steve")))
80
- end.to raise_error(ContentSecurityPolicyConfigError)
81
- end
82
-
83
- it "requires :preserve_schemes to be a truthy value" do
84
- expect do
85
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_opts.merge(preserve_schemes: "steve")))
86
- end.to raise_error(ContentSecurityPolicyConfigError)
87
- end
88
-
89
- it "requires :block_all_mixed_content to be a boolean value" do
90
- expect do
91
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_opts.merge(block_all_mixed_content: "steve")))
92
- end.to raise_error(ContentSecurityPolicyConfigError)
93
- end
94
-
95
- it "requires :upgrade_insecure_requests to be a boolean value" do
96
- expect do
97
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_opts.merge(upgrade_insecure_requests: "steve")))
98
- end.to raise_error(ContentSecurityPolicyConfigError)
99
- end
100
-
101
- it "requires all source lists to be an array of strings" do
102
- expect do
103
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_src: "steve"))
104
- end.to raise_error(ContentSecurityPolicyConfigError)
105
- end
106
-
107
- it "allows nil values" do
108
- expect do
109
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_src: %w('self'), script_src: ["https:", nil]))
110
- end.to_not raise_error
111
- end
112
-
113
- it "rejects unknown directives / config" do
114
- expect do
115
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_src: %w('self'), default_src_totally_mispelled: "steve"))
116
- end.to raise_error(ContentSecurityPolicyConfigError)
117
- end
118
-
119
- # this is mostly to ensure people don't use the antiquated shorthands common in other configs
120
- it "performs light validation on source lists" do
121
- expect do
122
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_src: %w(self none inline eval), script_src: %w('self')))
123
- end.to raise_error(ContentSecurityPolicyConfigError)
124
- end
125
-
126
- it "rejects anything not of the form allow-* as a sandbox value" do
127
- expect do
128
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_opts.merge(sandbox: ["steve"])))
129
- end.to raise_error(ContentSecurityPolicyConfigError)
130
- end
131
-
132
- it "accepts anything of the form allow-* as a sandbox value " do
133
- expect do
134
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_opts.merge(sandbox: ["allow-foo"])))
135
- end.to_not raise_error
136
- end
137
-
138
- it "accepts true as a sandbox policy" do
139
- expect do
140
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_opts.merge(sandbox: true)))
141
- end.to_not raise_error
142
- end
143
-
144
- it "rejects anything not of the form type/subtype as a plugin-type value" do
145
- expect do
146
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_opts.merge(plugin_types: ["steve"])))
147
- end.to raise_error(ContentSecurityPolicyConfigError)
148
- end
149
-
150
- it "accepts anything of the form type/subtype as a plugin-type value " do
151
- expect do
152
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_opts.merge(plugin_types: ["application/pdf"])))
153
- end.to_not raise_error
154
- end
155
-
156
- it "doesn't allow report_only to be set in a non-report-only config" do
157
- expect do
158
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyConfig.new(default_opts.merge(report_only: true)))
159
- end.to raise_error(ContentSecurityPolicyConfigError)
160
- end
161
-
162
- it "allows report_only to be set in a report-only config" do
163
- expect do
164
- ContentSecurityPolicy.validate_config!(ContentSecurityPolicyReportOnlyConfig.new(default_opts.merge(report_only: true)))
165
- end.to_not raise_error
166
- end
167
- end
168
-
169
- describe "#combine_policies" do
170
- before(:each) do
171
- reset_config
172
- end
173
- it "combines the default-src value with the override if the directive was unconfigured" do
174
- Configuration.default do |config|
175
- config.csp = {
176
- default_src: %w(https:),
177
- script_src: %w('self'),
178
- }
179
- end
180
- default_policy = Configuration.dup
181
- combined_config = ContentSecurityPolicy.combine_policies(default_policy.csp.to_h, style_src: %w(anothercdn.com))
182
- csp = ContentSecurityPolicy.new(combined_config)
183
- expect(csp.name).to eq(ContentSecurityPolicyConfig::HEADER_NAME)
184
- expect(csp.value).to eq("default-src https:; script-src 'self'; style-src https: anothercdn.com")
185
- end
186
-
187
- it "combines directives where the original value is nil and the hash is frozen" do
188
- Configuration.default do |config|
189
- config.csp = {
190
- default_src: %w('self'),
191
- script_src: %w('self'),
192
- report_only: false
193
- }.freeze
194
- end
195
- report_uri = "https://report-uri.io/asdf"
196
- default_policy = Configuration.dup
197
- combined_config = ContentSecurityPolicy.combine_policies(default_policy.csp.to_h, report_uri: [report_uri])
198
- csp = ContentSecurityPolicy.new(combined_config)
199
- expect(csp.value).to include("report-uri #{report_uri}")
200
- end
201
-
202
- it "does not combine the default-src value for directives that don't fall back to default sources" do
203
- Configuration.default do |config|
204
- config.csp = {
205
- default_src: %w('self'),
206
- script_src: %w('self'),
207
- report_only: false
208
- }.freeze
209
- end
210
- non_default_source_additions = ContentSecurityPolicy::NON_FETCH_SOURCES.each_with_object({}) do |directive, hash|
211
- hash[directive] = %w("http://example.org)
212
- end
213
- default_policy = Configuration.dup
214
- combined_config = ContentSecurityPolicy.combine_policies(default_policy.csp.to_h, non_default_source_additions)
215
-
216
- ContentSecurityPolicy::NON_FETCH_SOURCES.each do |directive|
217
- expect(combined_config[directive]).to eq(%w("http://example.org))
218
- end
219
- end
220
-
221
- it "overrides the report_only flag" do
222
- Configuration.default do |config|
223
- config.csp = {
224
- default_src: %w('self'),
225
- script_src: %w('self'),
226
- report_only: false
227
- }
228
- end
229
- default_policy = Configuration.dup
230
- combined_config = ContentSecurityPolicy.combine_policies(default_policy.csp.to_h, report_only: true)
231
- csp = ContentSecurityPolicy.new(combined_config)
232
- expect(csp.name).to eq(ContentSecurityPolicyReportOnlyConfig::HEADER_NAME)
233
- end
234
-
235
- it "overrides the :block_all_mixed_content flag" do
236
- Configuration.default do |config|
237
- config.csp = {
238
- default_src: %w(https:),
239
- script_src: %w('self'),
240
- block_all_mixed_content: false
241
- }
242
- end
243
- default_policy = Configuration.dup
244
- combined_config = ContentSecurityPolicy.combine_policies(default_policy.csp.to_h, block_all_mixed_content: true)
245
- csp = ContentSecurityPolicy.new(combined_config)
246
- expect(csp.value).to eq("default-src https:; block-all-mixed-content; script-src 'self'")
247
- end
248
-
249
- it "raises an error if appending to a OPT_OUT policy" do
250
- Configuration.default do |config|
251
- config.csp = OPT_OUT
252
- end
253
- default_policy = Configuration.dup
254
- expect do
255
- ContentSecurityPolicy.combine_policies(default_policy.csp.to_h, script_src: %w(anothercdn.com))
256
- end.to raise_error(ContentSecurityPolicyConfigError)
257
- end
258
- end
259
- end
260
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- module SecureHeaders
5
- describe ReferrerPolicy do
6
- specify { expect(ReferrerPolicy.make_header).to eq([ReferrerPolicy::HEADER_NAME, "origin-when-cross-origin"]) }
7
- specify { expect(ReferrerPolicy.make_header("no-referrer")).to eq([ReferrerPolicy::HEADER_NAME, "no-referrer"]) }
8
- specify { expect(ReferrerPolicy.make_header(%w(origin-when-cross-origin strict-origin-when-cross-origin))).to eq([ReferrerPolicy::HEADER_NAME, "origin-when-cross-origin, strict-origin-when-cross-origin"]) }
9
-
10
- context "valid configuration values" do
11
- it "accepts 'no-referrer'" do
12
- expect do
13
- ReferrerPolicy.validate_config!("no-referrer")
14
- end.not_to raise_error
15
- end
16
-
17
- it "accepts 'no-referrer-when-downgrade'" do
18
- expect do
19
- ReferrerPolicy.validate_config!("no-referrer-when-downgrade")
20
- end.not_to raise_error
21
- end
22
-
23
- it "accepts 'same-origin'" do
24
- expect do
25
- ReferrerPolicy.validate_config!("same-origin")
26
- end.not_to raise_error
27
- end
28
-
29
- it "accepts 'strict-origin'" do
30
- expect do
31
- ReferrerPolicy.validate_config!("strict-origin")
32
- end.not_to raise_error
33
- end
34
-
35
- it "accepts 'strict-origin-when-cross-origin'" do
36
- expect do
37
- ReferrerPolicy.validate_config!("strict-origin-when-cross-origin")
38
- end.not_to raise_error
39
- end
40
-
41
- it "accepts 'origin'" do
42
- expect do
43
- ReferrerPolicy.validate_config!("origin")
44
- end.not_to raise_error
45
- end
46
-
47
- it "accepts 'origin-when-cross-origin'" do
48
- expect do
49
- ReferrerPolicy.validate_config!("origin-when-cross-origin")
50
- end.not_to raise_error
51
- end
52
-
53
- it "accepts 'unsafe-url'" do
54
- expect do
55
- ReferrerPolicy.validate_config!("unsafe-url")
56
- end.not_to raise_error
57
- end
58
-
59
- it "accepts nil" do
60
- expect do
61
- ReferrerPolicy.validate_config!(nil)
62
- end.not_to raise_error
63
- end
64
-
65
- it "accepts array of policy values" do
66
- expect do
67
- ReferrerPolicy.validate_config!(
68
- %w(
69
- origin-when-cross-origin
70
- strict-origin-when-cross-origin
71
- )
72
- )
73
- end.not_to raise_error
74
- end
75
- end
76
-
77
- context "invalid configuration values" do
78
- it "doesn't accept invalid values" do
79
- expect do
80
- ReferrerPolicy.validate_config!("open")
81
- end.to raise_error(ReferrerPolicyConfigError)
82
- end
83
-
84
- it "doesn't accept invalid types" do
85
- expect do
86
- ReferrerPolicy.validate_config!({})
87
- end.to raise_error(TypeError)
88
- end
89
- end
90
- end
91
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- module SecureHeaders
5
- describe StrictTransportSecurity do
6
- describe "#value" do
7
- specify { expect(StrictTransportSecurity.make_header).to eq([StrictTransportSecurity::HEADER_NAME, StrictTransportSecurity::DEFAULT_VALUE]) }
8
- specify { expect(StrictTransportSecurity.make_header("max-age=1234; includeSubdomains; preload")).to eq([StrictTransportSecurity::HEADER_NAME, "max-age=1234; includeSubdomains; preload"]) }
9
-
10
- context "with an invalid configuration" do
11
- context "with a string argument" do
12
- it "raises an exception with an invalid max-age" do
13
- expect do
14
- StrictTransportSecurity.validate_config!("max-age=abc123")
15
- end.to raise_error(STSConfigError)
16
- end
17
-
18
- it "raises an exception if max-age is not supplied" do
19
- expect do
20
- StrictTransportSecurity.validate_config!("includeSubdomains")
21
- end.to raise_error(STSConfigError)
22
- end
23
-
24
- it "raises an exception with an invalid format" do
25
- expect do
26
- StrictTransportSecurity.validate_config!("max-age=123includeSubdomains")
27
- end.to raise_error(STSConfigError)
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- module SecureHeaders
5
- describe XContentTypeOptions do
6
- describe "#value" do
7
- specify { expect(XContentTypeOptions.make_header).to eq([XContentTypeOptions::HEADER_NAME, XContentTypeOptions::DEFAULT_VALUE]) }
8
- specify { expect(XContentTypeOptions.make_header("nosniff")).to eq([XContentTypeOptions::HEADER_NAME, "nosniff"]) }
9
-
10
- context "invalid configuration values" do
11
- it "accepts nosniff" do
12
- expect do
13
- XContentTypeOptions.validate_config!("nosniff")
14
- end.not_to raise_error
15
- end
16
-
17
- it "accepts nil" do
18
- expect do
19
- XContentTypeOptions.validate_config!(nil)
20
- end.not_to raise_error
21
- end
22
-
23
- it "doesn't accept anything besides no-sniff" do
24
- expect do
25
- XContentTypeOptions.validate_config!("donkey")
26
- end.to raise_error(XContentTypeOptionsConfigError)
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- module SecureHeaders
5
- describe XDownloadOptions do
6
- specify { expect(XDownloadOptions.make_header).to eq([XDownloadOptions::HEADER_NAME, XDownloadOptions::DEFAULT_VALUE]) }
7
- specify { expect(XDownloadOptions.make_header("noopen")).to eq([XDownloadOptions::HEADER_NAME, "noopen"]) }
8
-
9
- context "invalid configuration values" do
10
- it "accepts noopen" do
11
- expect do
12
- XDownloadOptions.validate_config!("noopen")
13
- end.not_to raise_error
14
- end
15
-
16
- it "accepts nil" do
17
- expect do
18
- XDownloadOptions.validate_config!(nil)
19
- end.not_to raise_error
20
- end
21
-
22
- it "doesn't accept anything besides noopen" do
23
- expect do
24
- XDownloadOptions.validate_config!("open")
25
- end.to raise_error(XDOConfigError)
26
- end
27
- end
28
- end
29
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- module SecureHeaders
5
- describe XFrameOptions do
6
- describe "#value" do
7
- specify { expect(XFrameOptions.make_header).to eq([XFrameOptions::HEADER_NAME, XFrameOptions::DEFAULT_VALUE]) }
8
- specify { expect(XFrameOptions.make_header("DENY")).to eq([XFrameOptions::HEADER_NAME, "DENY"]) }
9
-
10
- context "with invalid configuration" do
11
- it "allows SAMEORIGIN" do
12
- expect do
13
- XFrameOptions.validate_config!("SAMEORIGIN")
14
- end.not_to raise_error
15
- end
16
-
17
- it "allows DENY" do
18
- expect do
19
- XFrameOptions.validate_config!("DENY")
20
- end.not_to raise_error
21
- end
22
-
23
- it "allows ALLOW-FROM*" do
24
- expect do
25
- XFrameOptions.validate_config!("ALLOW-FROM: example.com")
26
- end.not_to raise_error
27
- end
28
- it "does not allow garbage" do
29
- expect do
30
- XFrameOptions.validate_config!("I like turtles")
31
- end.to raise_error(XFOConfigError)
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- module SecureHeaders
5
- describe XPermittedCrossDomainPolicies do
6
- specify { expect(XPermittedCrossDomainPolicies.make_header).to eq([XPermittedCrossDomainPolicies::HEADER_NAME, "none"]) }
7
- specify { expect(XPermittedCrossDomainPolicies.make_header("master-only")).to eq([XPermittedCrossDomainPolicies::HEADER_NAME, "master-only"]) }
8
-
9
- context "valid configuration values" do
10
- it "accepts 'all'" do
11
- expect do
12
- XPermittedCrossDomainPolicies.validate_config!("all")
13
- end.not_to raise_error
14
- end
15
-
16
- it "accepts 'by-ftp-filename'" do
17
- expect do
18
- XPermittedCrossDomainPolicies.validate_config!("by-ftp-filename")
19
- end.not_to raise_error
20
- end
21
-
22
- it "accepts 'by-content-type'" do
23
- expect do
24
- XPermittedCrossDomainPolicies.validate_config!("by-content-type")
25
- end.not_to raise_error
26
- end
27
- it "accepts 'master-only'" do
28
- expect do
29
- XPermittedCrossDomainPolicies.validate_config!("master-only")
30
- end.not_to raise_error
31
- end
32
-
33
- it "accepts nil" do
34
- expect do
35
- XPermittedCrossDomainPolicies.validate_config!(nil)
36
- end.not_to raise_error
37
- end
38
- end
39
-
40
- context "invlaid configuration values" do
41
- it "doesn't accept invalid values" do
42
- expect do
43
- XPermittedCrossDomainPolicies.validate_config!("open")
44
- end.to raise_error(XPCDPConfigError)
45
- end
46
- end
47
- end
48
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- module SecureHeaders
5
- describe XXssProtection do
6
- specify { expect(XXssProtection.make_header).to eq([XXssProtection::HEADER_NAME, XXssProtection::DEFAULT_VALUE]) }
7
- specify { expect(XXssProtection.make_header("1; mode=block; report=https://www.secure.com/reports")).to eq([XXssProtection::HEADER_NAME, "1; mode=block; report=https://www.secure.com/reports"]) }
8
-
9
- context "with invalid configuration" do
10
- it "should raise an error when providing a string that is not valid" do
11
- expect do
12
- XXssProtection.validate_config!("asdf")
13
- end.to raise_error(XXssProtectionConfigError)
14
-
15
- expect do
16
- XXssProtection.validate_config!("asdf; mode=donkey")
17
- end.to raise_error(XXssProtectionConfigError)
18
- end
19
-
20
- context "when using a hash value" do
21
- it "should allow string values ('1' or '0' are the only valid strings)" do
22
- expect do
23
- XXssProtection.validate_config!("1")
24
- end.not_to raise_error
25
- end
26
-
27
- it "should raise an error if no value key is supplied" do
28
- expect do
29
- XXssProtection.validate_config!("mode=block")
30
- end.to raise_error(XXssProtectionConfigError)
31
- end
32
-
33
- it "should raise an error if an invalid key is supplied" do
34
- expect do
35
- XXssProtection.validate_config!("123")
36
- end.to raise_error(XXssProtectionConfigError)
37
- end
38
-
39
- it "should raise an error if mode != block" do
40
- expect do
41
- XXssProtection.validate_config!("1; mode=donkey")
42
- end.to raise_error(XXssProtectionConfigError)
43
- end
44
- end
45
- end
46
- end
47
- end