Skip to content

Commit 9bfc3a7

Browse files
Add tests for subresource integrity (#506)
1 parent d468de4 commit 9bfc3a7

File tree

6 files changed

+919
-293
lines changed

6 files changed

+919
-293
lines changed

spec/shakapacker/configuration_spec.rb

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,54 @@
181181
is_expected.to be true
182182
end
183183
end
184+
185+
describe "#integrity" do
186+
it "contains the key :enabled" do
187+
expect(config.integrity).to have_key(:enabled)
188+
end
189+
190+
it "contains the key :hash_functions" do
191+
expect(config.integrity).to have_key(:hash_functions)
192+
end
193+
194+
it "contains the key :cross_origin" do
195+
expect(config.integrity).to have_key(:cross_origin)
196+
end
197+
198+
it "is by default disabled" do
199+
expect(config.integrity[:enabled]).to be false
200+
end
201+
202+
it "returns default cross_origin configuration" do
203+
expect(config.integrity[:cross_origin]).to eq "anonymous"
204+
end
205+
206+
it "returns default hash_functions" do
207+
expect(config.integrity[:hash_functions]).to eq ["sha384"]
208+
end
209+
end
210+
end
211+
212+
context "with shakapacker config file containing integrity" do
213+
let(:config) do
214+
Shakapacker::Configuration.new(
215+
root_path: ROOT_PATH,
216+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_integrity.yml", __dir__)),
217+
env: "production"
218+
)
219+
end
220+
221+
it "has integrity enabled" do
222+
expect(config.integrity[:enabled]).to be true
223+
end
224+
225+
it "has all hash functions set" do
226+
expect(config.integrity[:hash_functions]).to eq ["sha256", "sha384", "sha512"]
227+
end
228+
229+
it "has cross_origin set to use-credentials" do
230+
expect(config.integrity[:cross_origin]).to eq "use-credentials"
231+
end
184232
end
185233

186234
context "with shakapacker config file containing public_output_path entry" do
@@ -373,5 +421,4 @@
373421
end
374422
end
375423
end
376-
377424
end

0 commit comments

Comments
 (0)