diff options
Diffstat (limited to 'spec/requests/jira_connect/subscriptions_controller_spec.rb')
-rw-r--r-- | spec/requests/jira_connect/subscriptions_controller_spec.rb | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/spec/requests/jira_connect/subscriptions_controller_spec.rb b/spec/requests/jira_connect/subscriptions_controller_spec.rb index f407ea09250..b5f3ab916a4 100644 --- a/spec/requests/jira_connect/subscriptions_controller_spec.rb +++ b/spec/requests/jira_connect/subscriptions_controller_spec.rb @@ -5,36 +5,70 @@ require 'spec_helper' RSpec.describe JiraConnect::SubscriptionsController do 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) } + let(:cors_request_headers) { { 'Origin' => 'http://notgitlab.com' } } + let(:path) { '/-/jira_connect/subscriptions' } + let(:params) { { jwt: jwt } } + + before do + stub_application_setting(jira_connect_proxy_url: 'https://gitlab.com') + end subject(:content_security_policy) do - get '/-/jira_connect/subscriptions', params: { jwt: jwt } + get path, params: params response.headers['Content-Security-Policy'] end it { is_expected.to include('http://self-managed-gitlab.com/-/jira_connect/') } it { is_expected.to include('http://self-managed-gitlab.com/api/') } + it { is_expected.to include('http://self-managed-gitlab.com/oauth/') } context 'with no self-managed instance configured' do let_it_be(:installation) { create(:jira_connect_installation, instance_url: '') } 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/') } + it { is_expected.not_to include('http://self-managed-gitlab.com/oauth/') } end - context 'with jira_connect_oauth_self_managed feature disabled' do + context 'with jira_connect_oauth_self_managed_setting feature disabled' do before do - stub_feature_flags(jira_connect_oauth_self_managed: false) + stub_feature_flags(jira_connect_oauth_self_managed_setting: false) end 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/') } + it { is_expected.not_to include('http://self-managed-gitlab.com/oauth/') } + 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) } + let(:cors_request_headers) { { 'Origin' => 'http://notgitlab.com' } } + 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 end end end |