Commit 390582e1 authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@master

parent 1ea1db49
export const severityLevel = {
FATAL: 'fatal',
ERROR: 'error',
WARNING: 'warning',
INFO: 'info',
DEBUG: 'debug',
};
export const severityLevelVariant = {
[severityLevel.FATAL]: 'danger',
[severityLevel.ERROR]: 'dark',
[severityLevel.WARNING]: 'warning',
[severityLevel.INFO]: 'info',
[severityLevel.DEBUG]: 'light',
};
...@@ -11,6 +11,7 @@ import Stacktrace from './stacktrace.vue'; ...@@ -11,6 +11,7 @@ import Stacktrace from './stacktrace.vue';
import TrackEventDirective from '~/vue_shared/directives/track_event'; import TrackEventDirective from '~/vue_shared/directives/track_event';
import timeagoMixin from '~/vue_shared/mixins/timeago'; import timeagoMixin from '~/vue_shared/mixins/timeago';
import { trackClickErrorLinkToSentryOptions } from '../utils'; import { trackClickErrorLinkToSentryOptions } from '../utils';
import { severityLevel, severityLevelVariant } from './constants';
import query from '../queries/details.query.graphql'; import query from '../queries/details.query.graphql';
...@@ -147,6 +148,11 @@ export default { ...@@ -147,6 +148,11 @@ export default {
errorLevel() { errorLevel() {
return sprintf(__('level: %{level}'), { level: this.error.tags.level }); return sprintf(__('level: %{level}'), { level: this.error.tags.level });
}, },
errorSeverityVariant() {
return (
severityLevelVariant[this.error.tags.level] || severityLevelVariant[severityLevel.ERROR]
);
},
}, },
mounted() { mounted() {
this.startPollingDetails(this.issueDetailsPath); this.startPollingDetails(this.issueDetailsPath);
...@@ -228,8 +234,12 @@ export default { ...@@ -228,8 +234,12 @@ export default {
<h2 class="text-truncate">{{ GQLerror.title }}</h2> <h2 class="text-truncate">{{ GQLerror.title }}</h2>
</tooltip-on-truncate> </tooltip-on-truncate>
<template v-if="error.tags"> <template v-if="error.tags">
<gl-badge v-if="error.tags.level" variant="danger" class="rounded-pill mr-2" <gl-badge
>{{ errorLevel }} v-if="error.tags.level"
:variant="errorSeverityVariant"
class="rounded-pill mr-2"
>
{{ errorLevel }}
</gl-badge> </gl-badge>
<gl-badge v-if="error.tags.logger" variant="light" class="rounded-pill" <gl-badge v-if="error.tags.logger" variant="light" class="rounded-pill"
>{{ error.tags.logger }} >{{ error.tags.logger }}
......
...@@ -174,7 +174,9 @@ export default { ...@@ -174,7 +174,9 @@ export default {
:label-cols="$options.labelsConfig.cols" :label-cols="$options.labelsConfig.cols"
:label-align="$options.labelsConfig.align" :label-align="$options.labelsConfig.align"
label-for="expiration-policy-name-matching" label-for="expiration-policy-name-matching"
:label="s__('ContainerRegistry|Expire Docker tags that match this regex:')" :label="
s__('ContainerRegistry|Docker tags with names matching this regex pattern will expire:')
"
:state="nameRegexState" :state="nameRegexState"
:invalid-feedback=" :invalid-feedback="
s__('ContainerRegistry|The value of this input should be less than 255 characters') s__('ContainerRegistry|The value of this input should be less than 255 characters')
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Clusters module Clusters
module Applications module Applications
class Ingress < ApplicationRecord class Ingress < ApplicationRecord
VERSION = '1.22.1' VERSION = '1.29.3'
MODSECURITY_LOG_CONTAINER_NAME = 'modsecurity-log' MODSECURITY_LOG_CONTAINER_NAME = 'modsecurity-log'
self.table_name = 'clusters_applications_ingress' self.table_name = 'clusters_applications_ingress'
......
...@@ -194,7 +194,7 @@ class JiraService < IssueTrackerService ...@@ -194,7 +194,7 @@ class JiraService < IssueTrackerService
def test(_) def test(_)
result = test_settings result = test_settings
success = result.present? success = result.present?
result = @error if @error && !success result = @error&.message unless success
{ success: success, result: result } { success: success, result: result }
end end
...@@ -205,6 +205,8 @@ class JiraService < IssueTrackerService ...@@ -205,6 +205,8 @@ class JiraService < IssueTrackerService
nil nil
end end
private
def test_settings def test_settings
return unless client_url.present? return unless client_url.present?
...@@ -212,8 +214,6 @@ class JiraService < IssueTrackerService ...@@ -212,8 +214,6 @@ class JiraService < IssueTrackerService
jira_request { client.ServerInfo.all.attrs } jira_request { client.ServerInfo.all.attrs }
end end
private
def can_cross_reference?(noteable) def can_cross_reference?(noteable)
case noteable case noteable
when Commit then commit_events when Commit then commit_events
...@@ -346,9 +346,17 @@ class JiraService < IssueTrackerService ...@@ -346,9 +346,17 @@ class JiraService < IssueTrackerService
# Handle errors when doing Jira API calls # Handle errors when doing Jira API calls
def jira_request def jira_request
yield yield
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, URI::InvalidURIError, JIRA::HTTPError, OpenSSL::SSL::SSLError => e rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, URI::InvalidURIError, JIRA::HTTPError, OpenSSL::SSL::SSLError => error
@error = e.message @error = error
log_error("Error sending message", client_url: client_url, error: @error) log_error(
"Error sending message",
client_url: client_url,
error: {
exception_class: error.class.name,
exception_message: error.message,
exception_backtrace: error.backtrace.join("\n")
}
)
nil nil
end end
......
---
title: Bump ingress managed app chart to 1.29.3
merge_request: 23461
author:
type: changed
---
title: More verbose JiraService error logs
merge_request: 23688
author:
type: other
---
title: Indicate Sentry error severity in GitLab
merge_request: 23346
author:
type: added
---
title: Add separate classes for project hook, identity, export status
merge_request: 23789
author: Rajendra Kadam
type: added
# rubocop:disable Rails/Output # rubocop:disable Rails/Output
if defined?(Rails::Console) if defined?(Rails::Console) || Rails.env.development?
# note that this will not print out when using `spring` # when using `spring` this will only print out the first time
justify = 15 justify = 15
puts '-' * 80 puts '-' * 80
puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision})" puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision}) #{Gitlab.ee? ? 'EE' : 'FOSS'}"
puts " GitLab Shell:".ljust(justify) + "#{Gitlab::VersionInfo.parse(Gitlab::Shell.new.version)}" puts " GitLab Shell:".ljust(justify) + "#{Gitlab::VersionInfo.parse(Gitlab::Shell.new.version)}"
puts " #{Gitlab::Database.human_adapter_name}:".ljust(justify) + Gitlab::Database.version puts " #{Gitlab::Database.human_adapter_name}:".ljust(justify) + Gitlab::Database.version
......
...@@ -612,6 +612,15 @@ Here are some common pitfalls and how to overcome them: ...@@ -612,6 +612,15 @@ Here are some common pitfalls and how to overcome them:
}' }'
``` ```
- **I'm getting a `health check timeout: no Elasticsearch node available` error in Sidekiq during the indexing process**
```
Gitlab::Elastic::Indexer::Error: time="2020-01-23T09:13:00Z" level=fatal msg="health check timeout: no Elasticsearch node available"
```
You probably have not used either `http://` or `https://` as part of your value in the **"URL"** field of the Elasticseach Integration Menu. Please make sure you are using either `http://` or `https://` in this field as the [Elasticsearch client for Go](https://github.com/olivere/elastic) that we are using [needs the prefix for the URL to be acceped as valid](https://github.com/olivere/elastic/commit/a80af35aa41856dc2c986204e2b64eab81ccac3a).
Once you have corrected the formatting of the URL please delete the index (via the [dedicated rake task](#gitlab-elasticsearch-rake-tasks)) and [index the content of your intance](#adding-gitlabs-data-to-the-elasticsearch-index) once more.
### Reverting to basic search ### Reverting to basic search
Sometimes there may be issues with your Elasticsearch index data and as such Sometimes there may be issues with your Elasticsearch index data and as such
......
...@@ -179,9 +179,10 @@ If you still need to run tests during `mvn install`, add `-DskipTests=false` to ...@@ -179,9 +179,10 @@ If you still need to run tests during `mvn install`, add `-DskipTests=false` to
### Selecting the version of Python ### Selecting the version of Python
> - [Introduced](https://gitlab.com/gitlab-org/security-products/license-management/merge_requests/36) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 12.0. > - [Introduced](https://gitlab.com/gitlab-org/security-products/license-management/merge_requests/36) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 12.0.
> - In GitLab 12.2, Python 3.5 became the default. > - In [GitLab 12.2](https://gitlab.com/gitlab-org/gitlab/issues/12032), Python 3.5 became the default.
> - In [GitLab 12.7](https://gitlab.com/gitlab-org/security-products/license-management/merge_requests/101), Python 3.8 became the default.
License Compliance uses Python 3.5 and pip 19.1 by default. License Compliance uses Python 3.8 and pip 19.1 by default.
If your project requires Python 2, you can switch to Python 2.7 and pip 10.0 If your project requires Python 2, you can switch to Python 2.7 and pip 10.0
by setting the `LM_PYTHON_VERSION` environment variable to `2`. by setting the `LM_PYTHON_VERSION` environment variable to `2`.
......
...@@ -177,7 +177,7 @@ The UI allows you to configure the following: ...@@ -177,7 +177,7 @@ The UI allows you to configure the following:
- **Expiration interval:** how long tags are exempt from being deleted. - **Expiration interval:** how long tags are exempt from being deleted.
- **Expiration schedule:** how often the cron job checking the tags should run. - **Expiration schedule:** how often the cron job checking the tags should run.
- **Expiration latest:** how many tags to _always_ keep for each image. - **Expiration latest:** how many tags to _always_ keep for each image.
- **Expire Docker tags with regex matching:** the regex used to determine what tags should be expired. To qualify all tags for expiration, use the default value of `.*`. - **Docker tags with names matching this regex pattern will expire:** the regex used to determine what tags should be expired. To qualify all tags for expiration, use the default value of `.*`.
## Troubleshooting the GitLab Container Registry ## Troubleshooting the GitLab Container Registry
......
...@@ -2,52 +2,6 @@ ...@@ -2,52 +2,6 @@
module API module API
module Entities module Entities
class Hook < Grape::Entity
expose :id, :url, :created_at, :push_events, :tag_push_events, :merge_requests_events, :repository_update_events
expose :enable_ssl_verification
end
class ProjectHook < Hook
expose :project_id, :issues_events, :confidential_issues_events
expose :note_events, :confidential_note_events, :pipeline_events, :wiki_page_events
expose :job_events
expose :push_events_branch_filter
end
class SharedGroup < Grape::Entity
expose :group_id
expose :group_name do |group_link, options|
group_link.group.name
end
expose :group_full_path do |group_link, options|
group_link.group.full_path
end
expose :group_access, as: :group_access_level
expose :expires_at
end
class ProjectIdentity < Grape::Entity
expose :id, :description
expose :name, :name_with_namespace
expose :path, :path_with_namespace
expose :created_at
end
class ProjectExportStatus < ProjectIdentity
include ::API::Helpers::RelatedResourcesHelpers
expose :export_status
expose :_links, if: lambda { |project, _options| project.export_status == :finished } do
expose :api_url do |project|
expose_url(api_v4_projects_export_download_path(id: project.id))
end
expose :web_url do |project|
Gitlab::Routing.url_helpers.download_export_project_url(project)
end
end
end
class RemoteMirror < Grape::Entity class RemoteMirror < Grape::Entity
expose :id expose :id
expose :enabled expose :enabled
......
# frozen_string_literal: true
module API
module Entities
class Hook < Grape::Entity
expose :id, :url, :created_at, :push_events, :tag_push_events, :merge_requests_events, :repository_update_events
expose :enable_ssl_verification
end
end
end
# frozen_string_literal: true
module API
module Entities
class ProjectExportStatus < ProjectIdentity
include ::API::Helpers::RelatedResourcesHelpers
expose :export_status
expose :_links, if: lambda { |project, _options| project.export_status == :finished } do
expose :api_url do |project|
expose_url(api_v4_projects_export_download_path(id: project.id))
end
expose :web_url do |project|
Gitlab::Routing.url_helpers.download_export_project_url(project)
end
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class ProjectHook < Hook
expose :project_id, :issues_events, :confidential_issues_events
expose :note_events, :confidential_note_events, :pipeline_events, :wiki_page_events
expose :job_events
expose :push_events_branch_filter
end
end
end
# frozen_string_literal: true
module API
module Entities
class ProjectIdentity < Grape::Entity
expose :id, :description
expose :name, :name_with_namespace
expose :path, :path_with_namespace
expose :created_at
end
end
end
# frozen_string_literal: true
module API
module Entities
class SharedGroup < Grape::Entity
expose :group_id
expose :group_name do |group_link, options|
group_link.group.name
end
expose :group_full_path do |group_link, options|
group_link.group.full_path
end
expose :group_access, as: :group_access_level
expose :expires_at
end
end
end
...@@ -16,7 +16,9 @@ module Gitlab ...@@ -16,7 +16,9 @@ module Gitlab
end end
def running_puma_with_multiple_threads? def running_puma_with_multiple_threads?
Gitlab::Runtime.puma? && ::Puma.cli_config.options[:max_threads] > 1 return false unless Gitlab::Runtime.puma?
::Puma.respond_to?(:cli_config) && ::Puma.cli_config.options[:max_threads] > 1
end end
def execute_rugged_call(method_name, *args) def execute_rugged_call(method_name, *args)
......
...@@ -5065,6 +5065,9 @@ msgstr "" ...@@ -5065,6 +5065,9 @@ msgstr ""
msgid "ContainerRegistry|Docker tag expiration policy is %{toggleStatus}" msgid "ContainerRegistry|Docker tag expiration policy is %{toggleStatus}"
msgstr "" msgstr ""
msgid "ContainerRegistry|Docker tags with names matching this regex pattern will expire:"
msgstr ""
msgid "ContainerRegistry|Expiration interval:" msgid "ContainerRegistry|Expiration interval:"
msgstr "" msgstr ""
...@@ -5077,9 +5080,6 @@ msgstr "" ...@@ -5077,9 +5080,6 @@ msgstr ""
msgid "ContainerRegistry|Expiration schedule:" msgid "ContainerRegistry|Expiration schedule:"
msgstr "" msgstr ""
msgid "ContainerRegistry|Expire Docker tags that match this regex:"
msgstr ""
msgid "ContainerRegistry|If you are not already logged in, you need to authenticate to the Container Registry by using your GitLab username and password. If you have %{twofaDocLinkStart}Two-Factor Authentication%{twofaDocLinkEnd} enabled, use a %{personalAccessTokensDocLinkStart}Personal Access Token%{personalAccessTokensDocLinkEnd} instead of a password." msgid "ContainerRegistry|If you are not already logged in, you need to authenticate to the Container Registry by using your GitLab username and password. If you have %{twofaDocLinkStart}Two-Factor Authentication%{twofaDocLinkEnd} enabled, use a %{personalAccessTokensDocLinkStart}Personal Access Token%{personalAccessTokensDocLinkEnd} instead of a password."
msgstr "" msgstr ""
......
...@@ -35,14 +35,17 @@ module QA ...@@ -35,14 +35,17 @@ module QA
end end
def email def email
@email ||= "#{username}@example.com" @email ||= begin
api_email = api_resource&.dig(:email)
api_email && !api_email.empty? ? api_email : "#{username}@example.com"
end
end end
def public_email def public_email
@public_email ||= begin @public_email ||= begin
api_public_email = api_resource&.dig(:public_email) api_public_email = api_resource&.dig(:public_email)
api_public_email && api_public_email != '' ? api_public_email : Runtime::User.default_email api_public_email && !api_public_email.empty? ? api_public_email : Runtime::User.default_email
end end
end end
...@@ -87,6 +90,8 @@ module QA ...@@ -87,6 +90,8 @@ module QA
end end
def api_get_path def api_get_path
return "/user" if fetching_own_data?
"/users/#{fetch_id(username)}" "/users/#{fetch_id(username)}"
end end
...@@ -136,6 +141,10 @@ module QA ...@@ -136,6 +141,10 @@ module QA
users.first[:id] users.first[:id]
end end
def fetching_own_data?
user&.username == username || Runtime::User.username == username
end
end end
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
module QA module QA
# BUG_IN_CODE context 'Manage', :github, quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/issues/26952', type: :bug } do
context 'Manage', :github, quarantine: 'https://gitlab.com/gitlab-org/gitlab/issues/26952' do
describe 'Project import from GitHub' do describe 'Project import from GitHub' do
let(:imported_project) do let(:imported_project) do
Resource::ProjectImportedFromGithub.fabricate! do |project| Resource::ProjectImportedFromGithub.fabricate! do |project|
......
# frozen_string_literal: true # frozen_string_literal: true
module QA module QA
# BUG_IN_CODE context 'Create', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/issues/36817', type: :bug } do
context 'Create', quarantine: 'https://gitlab.com/gitlab-org/gitlab/issues/36817' do
describe 'Merge request rebasing' do describe 'Merge request rebasing' do
it 'user rebases source branch of merge request' do it 'user rebases source branch of merge request' do
Flow::Login.sign_in Flow::Login.sign_in
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
module QA module QA
# Git protocol v2 is temporarily disabled # Git protocol v2 is temporarily disabled
# BUG_IN_CODE context 'Create', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/issues/27828', type: :bug } do
context 'Create', quarantine: 'https://gitlab.com/gitlab-org/gitlab/issues/27828' do
describe 'Push over HTTP using Git protocol version 2', :requires_git_protocol_v2 do describe 'Push over HTTP using Git protocol version 2', :requires_git_protocol_v2 do
it 'user pushes to the repository' do it 'user pushes to the repository' do
Flow::Login.sign_in Flow::Login.sign_in
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
module QA module QA
# Git protocol v2 is temporarily disabled # Git protocol v2 is temporarily disabled
# BUG_IN_CODE context 'Create', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/issues/27828', type: :bug } do
context 'Create', quarantine: 'https://gitlab.com/gitlab-org/gitlab/issues/27828' do
describe 'Push over SSH using Git protocol version 2', :requires_git_protocol_v2 do describe 'Push over SSH using Git protocol version 2', :requires_git_protocol_v2 do
# Note: If you run this test against GDK make sure you've enabled sshd and # Note: If you run this test against GDK make sure you've enabled sshd and
# enabled setting the Git protocol by adding `AcceptEnv GIT_PROTOCOL` to # enabled setting the Git protocol by adding `AcceptEnv GIT_PROTOCOL` to
......
...@@ -4,6 +4,7 @@ import { GlLoadingIcon, GlLink, GlBadge, GlFormInput } from '@gitlab/ui'; ...@@ -4,6 +4,7 @@ import { GlLoadingIcon, GlLink, GlBadge, GlFormInput } from '@gitlab/ui';
import LoadingButton from '~/vue_shared/components/loading_button.vue'; import LoadingButton from '~/vue_shared/components/loading_button.vue';
import Stacktrace from '~/error_tracking/components/stacktrace.vue'; import Stacktrace from '~/error_tracking/components/stacktrace.vue';
import ErrorDetails from '~/error_tracking/components/error_details.vue'; import ErrorDetails from '~/error_tracking/components/error_details.vue';
import { severityLevel, severityLevelVariant } from '~/error_tracking/components/constants';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -144,6 +145,29 @@ describe('ErrorDetails', () => { ...@@ -144,6 +145,29 @@ describe('ErrorDetails', () => {
expect(wrapper.findAll(GlBadge).length).toBe(1); expect(wrapper.findAll(GlBadge).length).toBe(1);
}); });
}); });
it.each(Object.keys(severityLevel))(
'should set correct severity level variant for %s badge',
level => {
store.state.details.error.tags = { level: severityLevel[level] };
mountComponent();
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find(GlBadge).attributes('variant')).toEqual(
severityLevelVariant[severityLevel[level]],
);
});
},
);
it('should fallback for ERROR severityLevelVariant when severityLevel is unknown', () => {
store.state.details.error.tags = { level: 'someNewErrorLevel' };
mountComponent();
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find(GlBadge).attributes('variant')).toEqual(
severityLevelVariant[severityLevel.ERROR],
);
});
});
}); });
describe('Stacktrace', () => { describe('Stacktrace', () => {
......
...@@ -136,7 +136,7 @@ exports[`Settings Form renders 1`] = ` ...@@ -136,7 +136,7 @@ exports[`Settings Form renders 1`] = `
<glformgroup-stub <glformgroup-stub
id="expiration-policy-name-matching-group" id="expiration-policy-name-matching-group"
invalid-feedback="The value of this input should be less than 255 characters" invalid-feedback="The value of this input should be less than 255 characters"
label="Expire Docker tags that match this regex:" label="Docker tags with names matching this regex pattern will expire:"
label-align="right" label-align="right"
label-cols="3" label-cols="3"
label-for="expiration-policy-name-matching" label-for="expiration-policy-name-matching"
......
...@@ -122,6 +122,12 @@ describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do ...@@ -122,6 +122,12 @@ describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do
allow(Gitlab::Runtime).to receive(:puma?).and_return(true) allow(Gitlab::Runtime).to receive(:puma?).and_return(true)
end end
it "returns false when Puma doesn't support the cli_config method" do
allow(::Puma).to receive(:respond_to?).with(:cli_config).and_return(false)
expect(subject.running_puma_with_multiple_threads?).to be_falsey
end
it 'returns false for single thread Puma' do it 'returns false for single thread Puma' do
allow(::Puma).to receive_message_chain(:cli_config, :options).and_return(max_threads: 1) allow(::Puma).to receive_message_chain(:cli_config, :options).and_return(max_threads: 1)
......
...@@ -102,7 +102,7 @@ describe Clusters::Applications::Ingress do ...@@ -102,7 +102,7 @@ describe Clusters::Applications::Ingress do
it 'is initialized with ingress arguments' do it 'is initialized with ingress arguments' do
expect(subject.name).to eq('ingress') expect(subject.name).to eq('ingress')
expect(subject.chart).to eq('stable/nginx-ingress') expect(subject.chart).to eq('stable/nginx-ingress')
expect(subject.version).to eq('1.22.1') expect(subject.version).to eq('1.29.3')
expect(subject).to be_rbac expect(subject).to be_rbac
expect(subject.files).to eq(ingress.files) expect(subject.files).to eq(ingress.files)
end end
...@@ -119,7 +119,7 @@ describe Clusters::Applications::Ingress do ...@@ -119,7 +119,7 @@ describe Clusters::Applications::Ingress do
let(:ingress) { create(:clusters_applications_ingress, :errored, version: 'nginx') } let(:ingress) { create(:clusters_applications_ingress, :errored, version: 'nginx') }
it 'is initialized with the locked version' do it 'is initialized with the locked version' do
expect(subject.version).to eq('1.22.1') expect(subject.version).to eq('1.29.3')
end end
end end
end end
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
require 'spec_helper' require 'spec_helper'
describe JiraService do describe JiraService do
include Gitlab::Routing
include AssetsHelpers include AssetsHelpers
let(:title) { 'custom title' } let(:title) { 'custom title' }
...@@ -543,47 +542,55 @@ describe JiraService do ...@@ -543,47 +542,55 @@ describe JiraService do
end end
end end
describe '#test_settings' do describe '#test' do
let(:jira_service) do let(:jira_service) do
described_class.new( described_class.new(
project: create(:project), url: url,
url: 'http://jira.example.com', username: username,
username: 'jira_username', password: password
password: 'jira_password'
) )
end end
def test_settings(api_url = nil) def test_settings(url = 'jira.example.com')
api_url ||= 'jira.example.com' test_url = "http://#{url}/rest/api/2/serverInfo"
test_url = "http://#{api_url}/rest/api/2/serverInfo"
WebMock.stub_request(:get, test_url).with(basic_auth: %w(jira_username jira_password)).to_return(body: { url: 'http://url' }.to_json ) WebMock.stub_request(:get, test_url).with(basic_auth: [username, password])
.to_return(body: { url: 'http://url' }.to_json )
jira_service.test(nil) jira_service.test(nil)
end end
context 'when the test succeeds' do context 'when the test succeeds' do
it 'tries to get Jira project with URL when API URL not set' do it 'gets Jira project with URL when API URL not set' do
test_settings('jira.example.com') expect(test_settings).to eq(success: true, result: { 'url' => 'http://url' })
end end
it 'returns correct result' do it 'gets Jira project with API URL if set' do
expect(test_settings).to eq( { success: true, result: { 'url' => 'http://url' } })
end
it 'tries to get Jira project with API URL if set' do
jira_service.update(api_url: 'http://jira.api.com') jira_service.update(api_url: 'http://jira.api.com')
test_settings('jira.api.com')
expect(test_settings('jira.api.com')).to eq(success: true, result: { 'url' => 'http://url' })
end end
end end
context 'when the test fails' do context 'when the test fails' do
it 'returns result with the error' do it 'returns result with the error' do
test_url = 'http://jira.example.com/rest/api/2/serverInfo' test_url = 'http://jira.example.com/rest/api/2/serverInfo'
WebMock.stub_request(:get, test_url).with(basic_auth: %w(jira_username jira_password))
WebMock.stub_request(:get, test_url).with(basic_auth: [username, password])
.to_raise(JIRA::HTTPError.new(double(message: 'Some specific failure.'))) .to_raise(JIRA::HTTPError.new(double(message: 'Some specific failure.')))
expect(jira_service.test(nil)).to eq( { success: false, result: 'Some specific failure.' }) expect(jira_service).to receive(:log_error).with(
"Error sending message",
hash_including(
client_url: url,
error: hash_including(
exception_class: 'JIRA::HTTPError',
exception_message: 'Some specific failure.'
)
)
)
expect(jira_service.test(nil)).to eq(success: false, result: 'Some specific failure.')
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment