diff options
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/gitlab_script_tag_helper_spec.rb | 7 | ||||
-rw-r--r-- | spec/helpers/webpack_helper_spec.rb | 3 |
2 files changed, 9 insertions, 1 deletions
diff --git a/spec/helpers/gitlab_script_tag_helper_spec.rb b/spec/helpers/gitlab_script_tag_helper_spec.rb index 37413b9b1c2..35f2c0795be 100644 --- a/spec/helpers/gitlab_script_tag_helper_spec.rb +++ b/spec/helpers/gitlab_script_tag_helper_spec.rb @@ -41,4 +41,11 @@ RSpec.describe GitlabScriptTagHelper do expect(helper.javascript_tag( '// ignored', type: 'application/javascript') { 'alert(1)' }.to_s).to eq tag_with_nonce_and_type end end + + describe '#preload_link_tag' do + it 'returns a link tag with a nonce' do + expect(helper.preload_link_tag('https://example.com/script.js').to_s) + .to eq "<link rel=\"preload\" href=\"https://example.com/script.js\" as=\"script\" type=\"text/javascript\" nonce=\"noncevalue\">" + end + end end diff --git a/spec/helpers/webpack_helper_spec.rb b/spec/helpers/webpack_helper_spec.rb index f9386c99dc3..f9e2d265153 100644 --- a/spec/helpers/webpack_helper_spec.rb +++ b/spec/helpers/webpack_helper_spec.rb @@ -15,6 +15,7 @@ RSpec.describe WebpackHelper do describe '#webpack_preload_asset_tag' do before do allow(Gitlab::Webpack::Manifest).to receive(:asset_paths).and_return([asset_path]) + allow(helper).to receive(:content_security_policy_nonce).and_return('noncevalue') end it 'preloads the resource by default' do @@ -22,7 +23,7 @@ RSpec.describe WebpackHelper do output = helper.webpack_preload_asset_tag(source) - expect(output).to eq("<link rel=\"preload\" href=\"#{asset_path}\" as=\"script\" type=\"text/javascript\">") + expect(output).to eq("<link rel=\"preload\" href=\"#{asset_path}\" as=\"script\" type=\"text/javascript\" nonce=\"noncevalue\">") end it 'prefetches the resource if explicitly asked' do |