Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/integrations/jira_spec.rb')
-rw-r--r--spec/models/integrations/jira_spec.rb192
1 files changed, 46 insertions, 146 deletions
diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb
index d244b1d33d5..061c770a61a 100644
--- a/spec/models/integrations/jira_spec.rb
+++ b/spec/models/integrations/jira_spec.rb
@@ -27,6 +27,10 @@ RSpec.describe Integrations::Jira do
WebMock.stub_request(:get, /serverInfo/).to_return(body: server_info_results.to_json )
end
+ it_behaves_like Integrations::ResetSecretFields do
+ let(:integration) { jira_integration }
+ end
+
describe '#options' do
let(:options) do
{
@@ -122,6 +126,11 @@ RSpec.describe Integrations::Jira do
it 'includes SECTION_TYPE_JIRA_ISSUES' do
expect(sections).to include(described_class::SECTION_TYPE_JIRA_ISSUES)
end
+
+ it 'section SECTION_TYPE_JIRA_ISSUES has `plan` attribute' do
+ jira_issues_section = integration.sections.find { |s| s[:type] == described_class::SECTION_TYPE_JIRA_ISSUES }
+ expect(jira_issues_section[:plan]).to eq('premium')
+ end
end
context 'when project_level? is false' do
@@ -301,7 +310,7 @@ RSpec.describe Integrations::Jira do
let_it_be(:new_url) { 'http://jira-new.example.com' }
before do
- integration.update!(username: new_username, url: new_url)
+ integration.update!(username: new_username, url: new_url, password: password)
end
it 'stores updated data in jira_tracker_data table' do
@@ -318,7 +327,7 @@ RSpec.describe Integrations::Jira do
context 'when updating the url, api_url, username, or password' do
context 'when updating the integration' do
it 'updates deployment type' do
- integration.update!(url: 'http://first.url')
+ integration.update!(url: 'http://first.url', password: password)
integration.jira_tracker_data.update!(deployment_type: 'server')
expect(integration.jira_tracker_data.deployment_server?).to be_truthy
@@ -376,135 +385,6 @@ RSpec.describe Integrations::Jira do
expect(WebMock).not_to have_requested(:get, /serverInfo/)
end
end
-
- context 'stored password invalidation' do
- context 'when a password was previously set' do
- context 'when only web url present' do
- let(:data_params) do
- {
- url: url, api_url: nil,
- username: username, password: password,
- jira_issue_transition_id: transition_id
- }
- end
-
- it 'resets password if url changed' do
- integration
- integration.url = 'http://jira_edited.example.com'
-
- expect(integration).not_to be_valid
- expect(integration.url).to eq('http://jira_edited.example.com')
- expect(integration.password).to be_nil
- end
-
- it 'does not reset password if url "changed" to the same url as before' do
- integration.url = 'http://jira.example.com'
-
- expect(integration).to be_valid
- expect(integration.url).to eq('http://jira.example.com')
- expect(integration.password).not_to be_nil
- end
-
- it 'resets password if url not changed but api url added' do
- integration.api_url = 'http://jira_edited.example.com/rest/api/2'
-
- expect(integration).not_to be_valid
- expect(integration.api_url).to eq('http://jira_edited.example.com/rest/api/2')
- expect(integration.password).to be_nil
- end
-
- it 'does not reset password if new url is set together with password, even if it\'s the same password' do
- integration.url = 'http://jira_edited.example.com'
- integration.password = password
-
- expect(integration).to be_valid
- expect(integration.password).to eq(password)
- expect(integration.url).to eq('http://jira_edited.example.com')
- end
-
- it 'resets password if url changed, even if setter called multiple times' do
- integration.url = 'http://jira1.example.com/rest/api/2'
- integration.url = 'http://jira1.example.com/rest/api/2'
-
- expect(integration).not_to be_valid
- expect(integration.password).to be_nil
- end
-
- it 'does not reset password if username changed' do
- integration.username = 'some_name'
-
- expect(integration).to be_valid
- expect(integration.password).to eq(password)
- end
-
- it 'does not reset password if password changed' do
- integration.url = 'http://jira_edited.example.com'
- integration.password = 'new_password'
-
- expect(integration).to be_valid
- expect(integration.password).to eq('new_password')
- end
-
- it 'does not reset password if the password is touched and same as before' do
- integration.url = 'http://jira_edited.example.com'
- integration.password = password
-
- expect(integration).to be_valid
- expect(integration.password).to eq(password)
- end
- end
-
- context 'when both web and api url present' do
- let(:data_params) do
- {
- url: url, api_url: 'http://jira.example.com/rest/api/2',
- username: username, password: password,
- jira_issue_transition_id: transition_id
- }
- end
-
- it 'resets password if api url changed' do
- integration.api_url = 'http://jira_edited.example.com/rest/api/2'
-
- expect(integration).not_to be_valid
- expect(integration.password).to be_nil
- end
-
- it 'does not reset password if url changed' do
- integration.url = 'http://jira_edited.example.com'
-
- expect(integration).to be_valid
- expect(integration.password).to eq(password)
- end
-
- it 'resets password if api url set to empty' do
- integration.api_url = ''
-
- expect(integration).not_to be_valid
- expect(integration.password).to be_nil
- end
- end
- end
-
- context 'when no password was previously set' do
- let(:data_params) do
- {
- url: url, username: username
- }
- end
-
- it 'saves password if new url is set together with password' do
- integration.url = 'http://jira_edited.example.com/rest/api/2'
- integration.password = 'password'
- integration.save!
-
- expect(integration.reload).to have_attributes(
- url: 'http://jira_edited.example.com/rest/api/2',
- password: 'password'
- )
- end
- end
- end
end
end
@@ -539,8 +419,7 @@ RSpec.describe Integrations::Jira do
end
describe '#client' do
- it 'uses the default GitLab::HTTP timeouts' do
- timeouts = Gitlab::HTTP::DEFAULT_TIMEOUT_OPTIONS
+ subject do
stub_request(:get, 'http://jira.example.com/foo')
expect(Gitlab::HTTP).to receive(:httparty_perform_request)
@@ -548,6 +427,32 @@ RSpec.describe Integrations::Jira do
jira_integration.client.get('/foo')
end
+
+ context 'when the FF :jira_raise_timeouts is enabled' do
+ let(:timeouts) do
+ {
+ open_timeout: 2.minutes,
+ read_timeout: 2.minutes,
+ write_timeout: 2.minutes
+ }
+ end
+
+ it 'uses custom timeouts' do
+ subject
+ end
+ end
+
+ context 'when the FF :jira_raise_timeouts is disabled' do
+ before do
+ stub_feature_flags(jira_raise_timeouts: false)
+ end
+
+ let(:timeouts) { Gitlab::HTTP::DEFAULT_TIMEOUT_OPTIONS }
+
+ it 'uses the default GitLab::HTTP timeouts' do
+ subject
+ end
+ end
end
describe '#find_issue' do
@@ -746,17 +651,14 @@ RSpec.describe Integrations::Jira do
end
it 'logs exception when transition id is not valid' do
- allow(jira_integration).to receive(:log_error)
+ allow(jira_integration).to receive(:log_exception)
WebMock.stub_request(:post, transitions_url).with(basic_auth: %w(jira-username jira-password)).and_raise("Bad Request")
close_issue
- expect(jira_integration).to have_received(:log_error).with(
- "Issue transition failed",
- error: hash_including(
- exception_class: 'StandardError',
- exception_message: "Bad Request"
- ),
+ expect(jira_integration).to have_received(:log_exception).with(
+ kind_of(StandardError),
+ message: 'Issue transition failed',
client_url: "http://jira.example.com"
)
end
@@ -1054,12 +956,10 @@ RSpec.describe Integrations::Jira do
WebMock.stub_request(:get, test_url).with(basic_auth: [username, password])
.to_raise(JIRA::HTTPError.new(double(message: error_message)))
- expect(jira_integration).to receive(:log_error).with(
- 'Error sending message',
- client_url: 'http://jira.example.com',
- 'exception.class' => anything,
- 'exception.message' => error_message,
- 'exception.backtrace' => anything
+ expect(jira_integration).to receive(:log_exception).with(
+ kind_of(JIRA::HTTPError),
+ message: 'Error sending message',
+ client_url: 'http://jira.example.com'
)
expect(jira_integration.test(nil)).to eq(success: false, result: error_message)