Commit a7e0f4de authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '14945-fix-jira-api-url-parsing' into 'master'

JIRA Integration: Fix API URL with trailing slash

See merge request gitlab-org/gitlab!18526
parents d1068ca1 10e02e58
......@@ -122,9 +122,13 @@ class JiraService < IssueTrackerService
end
alias_method :original_url, :url
def url
original_url&.chomp('/')
original_url&.delete_suffix('/')
end
alias_method :original_api_url, :api_url
def api_url
original_api_url&.delete_suffix('/')
end
def execute(push)
......
---
title: 'JIRA Integration API URL works having a trailing slash'
merge_request: 18526
author:
type: fixed
......@@ -15,20 +15,22 @@ describe JiraService do
let(:transition_id) { 'test27' }
describe '#options' do
let(:service) do
described_class.create(
let(:options) do
{
project: create(:project),
active: true,
username: 'username ',
username: 'username',
password: 'test',
jira_issue_transition_id: 24,
url: 'http://jira.test.com/path/'
)
}
end
let(:service) { described_class.create(options) }
it 'sets the URL properly' do
# jira-ruby gem parses the URI and handles trailing slashes
# fine: https://github.com/sumoheavy/jira-ruby/blob/v1.4.1/lib/jira/http_client.rb#L59
# jira-ruby gem parses the URI and handles trailing slashes fine:
# https://github.com/sumoheavy/jira-ruby/blob/v1.7.0/lib/jira/http_client.rb#L62
expect(service.options[:site]).to eq('http://jira.test.com/')
end
......@@ -36,14 +38,30 @@ describe JiraService do
expect(service.options[:context_path]).to eq('/path')
end
context 'username with trailing whitespaces' do
before do
options.merge!(username: 'username ')
end
it 'leaves out trailing whitespaces in username' do
expect(service.options[:username]).to eq('username')
end
end
it 'provides additional cookies to allow basic auth with oracle webgate' do
expect(service.options[:use_cookies]).to eq(true)
expect(service.options[:additional_cookies]).to eq(['OBBasicAuth=fromDialog'])
end
context 'using api URL' do
before do
options.merge!(api_url: 'http://jira.test.com/api_path/')
end
it 'leaves out trailing slashes in context' do
expect(service.options[:context_path]).to eq('/api_path')
end
end
end
describe 'Associations' do
......
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