debian-mirror-gitlab/spec/requests/jira_connect/subscriptions_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

120 lines
5 KiB
Ruby
Raw Permalink Normal View History

2022-08-13 15:12:31 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe JiraConnect::SubscriptionsController, feature_category: :integrations do
2022-08-13 15:12:31 +05:30
describe 'GET /-/jira_connect/subscriptions' do
let_it_be(:installation) { create(:jira_connect_installation, instance_url: 'http://self-managed-gitlab.com') }
let(:qsh) do
Atlassian::Jwt.create_query_string_hash('https://gitlab.test/subscriptions', 'GET', 'https://gitlab.test')
end
let(:jwt) { Atlassian::Jwt.encode({ iss: installation.client_key, qsh: qsh }, installation.shared_secret) }
2023-03-04 22:38:38 +05:30
let(:cors_request_headers) { { 'Origin' => 'https://gitlab.com' } }
2023-01-13 00:05:48 +05:30
let(:path) { '/-/jira_connect/subscriptions' }
let(:params) { { jwt: jwt } }
before do
stub_application_setting(jira_connect_proxy_url: 'https://gitlab.com')
end
2022-08-13 15:12:31 +05:30
2022-10-11 01:57:18 +05:30
subject(:content_security_policy) do
2023-03-04 22:38:38 +05:30
get path, params: params, headers: cors_request_headers
2022-08-13 15:12:31 +05:30
2022-10-11 01:57:18 +05:30
response.headers['Content-Security-Policy']
end
2022-08-13 15:12:31 +05:30
2022-10-11 01:57:18 +05:30
it { is_expected.to include('http://self-managed-gitlab.com/-/jira_connect/') }
it { is_expected.to include('http://self-managed-gitlab.com/api/') }
2023-01-13 00:05:48 +05:30
it { is_expected.to include('http://self-managed-gitlab.com/oauth/') }
2023-03-04 22:38:38 +05:30
it { is_expected.to include('frame-ancestors \'self\' https://*.atlassian.net https://*.jira.com') }
context 'with additional iframe ancestors' do
before do
allow(Gitlab.config.jira_connect).to receive(:additional_iframe_ancestors).and_return(['http://localhost:*', 'http://dev.gitlab.com'])
end
it {
is_expected.to include('frame-ancestors \'self\' https://*.atlassian.net https://*.jira.com http://localhost:* http://dev.gitlab.com')
}
end
2022-08-13 15:12:31 +05:30
context 'with no self-managed instance configured' do
let_it_be(:installation) { create(:jira_connect_installation, instance_url: '') }
2022-10-11 01:57:18 +05:30
it { is_expected.not_to include('http://self-managed-gitlab.com/-/jira_connect/') }
it { is_expected.not_to include('http://self-managed-gitlab.com/api/') }
2023-01-13 00:05:48 +05:30
it { is_expected.not_to include('http://self-managed-gitlab.com/oauth/') }
2022-10-11 01:57:18 +05:30
end
2023-03-04 22:38:38 +05:30
context 'when json format' do
let(:path) { '/-/jira_connect/subscriptions.json' }
it 'allows cross-origin requests', :aggregate_failures do
get path, params: params, headers: cors_request_headers
expect(response.headers['Access-Control-Allow-Origin']).to eq 'https://gitlab.com'
expect(response.headers['Access-Control-Allow-Methods']).to eq 'GET, OPTIONS'
expect(response.headers['Access-Control-Allow-Credentials']).to be_nil
2022-10-11 01:57:18 +05:30
end
2023-03-04 22:38:38 +05:30
end
end
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
describe 'OPTIONS /-/jira_connect/subscriptions' do
let(:cors_request_headers) { { 'Origin' => 'https://gitlab.com', 'access-control-request-method' => 'GET' } }
before do
stub_application_setting(jira_connect_proxy_url: 'https://gitlab.com')
end
it 'allows cross-origin requests', :aggregate_failures do
options '/-/jira_connect/subscriptions.json', headers: cors_request_headers
expect(response.headers['Access-Control-Allow-Origin']).to eq 'https://gitlab.com'
expect(response.headers['Access-Control-Allow-Methods']).to eq 'GET, OPTIONS'
expect(response.headers['Access-Control-Allow-Credentials']).to be_nil
end
end
describe 'OPTIONS /-/jira_connect/subscriptions/:id' do
let(:cors_request_headers) { { 'Origin' => 'https://gitlab.com', 'access-control-request-method' => 'DELETE' } }
before do
stub_application_setting(jira_connect_proxy_url: 'https://gitlab.com')
end
it 'allows cross-origin requests', :aggregate_failures do
options '/-/jira_connect/subscriptions/1', headers: cors_request_headers
expect(response.headers['Access-Control-Allow-Origin']).to eq 'https://gitlab.com'
expect(response.headers['Access-Control-Allow-Methods']).to eq 'DELETE, OPTIONS'
expect(response.headers['Access-Control-Allow-Credentials']).to be_nil
2023-01-13 00:05:48 +05:30
end
end
describe 'DELETE /-/jira_connect/subscriptions/:id' do
let_it_be(:installation) { create(:jira_connect_installation, instance_url: 'http://self-managed-gitlab.com') }
let_it_be(:subscription) { create(:jira_connect_subscription, installation: installation) }
let(:qsh) do
Atlassian::Jwt.create_query_string_hash('https://gitlab.test/subscriptions', 'GET', 'https://gitlab.test')
end
let(:jwt) { Atlassian::Jwt.encode({ iss: installation.client_key, qsh: qsh }, installation.shared_secret) }
2023-03-04 22:38:38 +05:30
let(:cors_request_headers) { { 'Origin' => 'https://gitlab.com' } }
2023-01-13 00:05:48 +05:30
let(:params) { { jwt: jwt, format: :json } }
before do
stub_application_setting(jira_connect_proxy_url: 'https://gitlab.com')
end
it 'allows cross-origin requests', :aggregate_failures do
delete "/-/jira_connect/subscriptions/#{subscription.id}", params: params, headers: cors_request_headers
expect(response.headers['Access-Control-Allow-Origin']).to eq 'https://gitlab.com'
expect(response.headers['Access-Control-Allow-Methods']).to eq 'DELETE, OPTIONS'
expect(response.headers['Access-Control-Allow-Credentials']).to be_nil
2022-08-13 15:12:31 +05:30
end
end
end