2020-01-08 06:08:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.describe 'Sourcegraph Content Security Policy' do
|
2020-01-08 06:08:13 +00:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :repository, namespace: user.namespace) }
|
|
|
|
|
2020-02-23 00:09:14 +00:00
|
|
|
shared_context 'disable feature' do
|
2020-01-08 06:08:13 +00:00
|
|
|
before do
|
2020-02-23 00:09:14 +00:00
|
|
|
allow(Gitlab::CurrentSettings).to receive(:sourcegraph_enabled).and_return(false)
|
2020-01-08 06:08:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-12 21:09:45 +00:00
|
|
|
it_behaves_like 'setting CSP', 'connect-src' do
|
2021-11-30 21:10:33 +00:00
|
|
|
let_it_be(:sourcegraph_url) { 'https://sourcegraph.test' }
|
|
|
|
let_it_be(:allowlisted_url) { "#{sourcegraph_url}/.api/" }
|
2020-02-23 00:09:14 +00:00
|
|
|
let_it_be(:extended_controller_class) { Projects::BlobController }
|
2020-01-08 06:08:13 +00:00
|
|
|
|
2020-02-23 00:09:14 +00:00
|
|
|
subject do
|
|
|
|
visit project_blob_path(project, File.join('master', 'README.md'))
|
2020-01-08 06:08:13 +00:00
|
|
|
|
2020-02-23 00:09:14 +00:00
|
|
|
response_headers['Content-Security-Policy']
|
2020-01-08 06:08:13 +00:00
|
|
|
end
|
|
|
|
|
2020-02-23 00:09:14 +00:00
|
|
|
before do
|
2021-11-30 21:10:33 +00:00
|
|
|
allow(Gitlab::CurrentSettings).to receive(:sourcegraph_url).and_return(sourcegraph_url)
|
2020-02-23 00:09:14 +00:00
|
|
|
allow(Gitlab::CurrentSettings).to receive(:sourcegraph_enabled).and_return(true)
|
2020-01-08 06:08:13 +00:00
|
|
|
|
2020-02-23 00:09:14 +00:00
|
|
|
sign_in(user)
|
2020-01-08 06:08:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|