summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-11 09:09:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-11 09:09:11 +0000
commite348fb4c1b9eaf21655001dc4346ceb0c0c3d5b4 (patch)
treec11afe15edfe85d809ab0be78a6f52a539d28bec /spec/models
parentce567e98da6118031576d9084d3e05473746e4c6 (diff)
downloadgitlab-ce-e348fb4c1b9eaf21655001dc4346ceb0c0c3d5b4.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/environment_spec.rb11
-rw-r--r--spec/models/integrations/jira_spec.rb78
2 files changed, 80 insertions, 9 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 87beba680d8..d62d7162497 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -2009,9 +2009,10 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching, feature_categ
end
end
- describe '#deploy_freezes' do
+ describe '#deploy_freezes', :request_store do
let(:environment) { create(:environment, project: project, name: 'staging') }
let(:freeze_period) { create(:ci_freeze_period, project: project) }
+ let(:cache_key) { "project:#{project.id}:freeze_periods_for_environments" }
subject { environment.deploy_freezes }
@@ -2020,11 +2021,9 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching, feature_categ
end
it 'caches the freeze periods' do
- expect(Gitlab::SafeRequestStore).to receive(:fetch)
- .at_least(:once)
- .and_return([freeze_period])
-
- subject
+ expect { subject }.to(
+ change { Gitlab::SafeRequestStore[cache_key] }.from(nil).to([freeze_period])
+ )
end
end
diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb
index ccea8748d13..d3cb386e8e0 100644
--- a/spec/models/integrations/jira_spec.rb
+++ b/spec/models/integrations/jira_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Integrations::Jira do
+RSpec.describe Integrations::Jira, feature_category: :integrations do
include AssetsHelpers
let_it_be(:project) { create(:project, :repository) }
@@ -11,6 +11,7 @@ RSpec.describe Integrations::Jira do
let(:url) { 'http://jira.example.com' }
let(:api_url) { 'http://api-jira.example.com' }
let(:username) { 'jira-username' }
+ let(:jira_auth_type) { 0 }
let(:jira_issue_prefix) { '' }
let(:jira_issue_regex) { '' }
let(:password) { 'jira-password' }
@@ -50,11 +51,39 @@ RSpec.describe Integrations::Jira do
it { is_expected.to validate_presence_of(:url) }
it { is_expected.to validate_presence_of(:username) }
it { is_expected.to validate_presence_of(:password) }
+ it { is_expected.to validate_presence_of(:jira_auth_type) }
it { is_expected.to validate_length_of(:jira_issue_regex).is_at_most(255) }
it { is_expected.to validate_length_of(:jira_issue_prefix).is_at_most(255) }
+ it { is_expected.to validate_inclusion_of(:jira_auth_type).in_array([0, 1]) }
it_behaves_like 'issue tracker integration URL attribute', :url
it_behaves_like 'issue tracker integration URL attribute', :api_url
+
+ context 'with personal_access_token_authorization' do
+ before do
+ jira_integration.jira_auth_type = 1
+ end
+
+ it { is_expected.not_to validate_presence_of(:username) }
+ end
+
+ context 'when URL is for Jira Cloud' do
+ before do
+ jira_integration.url = 'https://test.atlassian.net'
+ end
+
+ it 'is valid when jira_auth_type is basic' do
+ jira_integration.jira_auth_type = 0
+
+ expect(jira_integration).to be_valid
+ end
+
+ it 'is invalid when jira_auth_type is PAT' do
+ jira_integration.jira_auth_type = 1
+
+ expect(jira_integration).not_to be_valid
+ end
+ end
end
context 'when integration is inactive' do
@@ -66,8 +95,10 @@ RSpec.describe Integrations::Jira do
it { is_expected.not_to validate_presence_of(:url) }
it { is_expected.not_to validate_presence_of(:username) }
it { is_expected.not_to validate_presence_of(:password) }
+ it { is_expected.not_to validate_presence_of(:jira_auth_type) }
it { is_expected.not_to validate_length_of(:jira_issue_regex).is_at_most(255) }
it { is_expected.not_to validate_length_of(:jira_issue_prefix).is_at_most(255) }
+ it { is_expected.not_to validate_inclusion_of(:jira_auth_type).in_array([0, 1]) }
end
describe 'jira_issue_transition_id' do
@@ -173,7 +204,7 @@ RSpec.describe Integrations::Jira do
subject(:fields) { integration.fields }
it 'returns custom fields' do
- expect(fields.pluck(:name)).to eq(%w[url api_url username password jira_issue_regex jira_issue_prefix jira_issue_transition_id])
+ expect(fields.pluck(:name)).to eq(%w[url api_url jira_auth_type username password jira_issue_regex jira_issue_prefix jira_issue_transition_id])
end
end
@@ -323,6 +354,7 @@ RSpec.describe Integrations::Jira do
project: project,
url: url,
api_url: api_url,
+ jira_auth_type: jira_auth_type,
username: username, password: password,
jira_issue_regex: jira_issue_regex,
jira_issue_prefix: jira_issue_prefix,
@@ -339,6 +371,7 @@ RSpec.describe Integrations::Jira do
it 'stores data in data_fields correctly' do
expect(integration.jira_tracker_data.url).to eq(url)
expect(integration.jira_tracker_data.api_url).to eq(api_url)
+ expect(integration.jira_tracker_data.jira_auth_type).to eq(jira_auth_type)
expect(integration.jira_tracker_data.username).to eq(username)
expect(integration.jira_tracker_data.password).to eq(password)
expect(integration.jira_tracker_data.jira_issue_regex).to eq(jira_issue_regex)
@@ -545,15 +578,54 @@ RSpec.describe Integrations::Jira do
end
describe '#client' do
+ before do
+ stub_request(:get, 'http://jira.example.com/foo')
+ end
+
it 'uses the default GitLab::HTTP timeouts' do
timeouts = Gitlab::HTTP::DEFAULT_TIMEOUT_OPTIONS
- stub_request(:get, 'http://jira.example.com/foo')
expect(Gitlab::HTTP).to receive(:httparty_perform_request)
.with(Net::HTTP::Get, '/foo', hash_including(timeouts)).and_call_original
jira_integration.client.get('/foo')
end
+
+ context 'with basic auth' do
+ before do
+ jira_integration.jira_auth_type = 0
+ end
+
+ it 'uses correct authorization options' do
+ expect_next_instance_of(JIRA::Client) do |instance|
+ expect(instance.request_client.options).to include(
+ additional_cookies: ['OBBasicAuth=fromDialog'],
+ auth_type: :basic,
+ use_cookies: true,
+ password: jira_integration.password,
+ username: jira_integration.username
+ )
+ end
+
+ jira_integration.client.get('/foo')
+ end
+ end
+
+ context 'with personal access token auth' do
+ before do
+ jira_integration.jira_auth_type = 1
+ end
+
+ it 'uses correct authorization options' do
+ expect_next_instance_of(JIRA::Client) do |instance|
+ expect(instance.request_client.options).to include(
+ default_headers: { "Authorization" => "Bearer #{password}" }
+ )
+ end
+
+ jira_integration.client.get('/foo')
+ end
+ end
end
describe '#find_issue' do