Commit 10e02e58 authored by Arturo Herrero's avatar Arturo Herrero Committed by Mayra Cabrera

JIRA Integration: Fix API URL with trailing slash

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