Resolve "WebHookService doesn't handle user info with nil passwords"
This commit is contained in:
parent
7da7af3a22
commit
1345968ea6
|
@ -82,7 +82,7 @@ class WebHookService
|
|||
post_url = hook.url.gsub("#{parsed_url.userinfo}@", '')
|
||||
basic_auth = {
|
||||
username: CGI.unescape(parsed_url.user),
|
||||
password: CGI.unescape(parsed_url.password)
|
||||
password: CGI.unescape(parsed_url.password.presence || '')
|
||||
}
|
||||
make_request(post_url, basic_auth)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix webhook error when password is not present
|
||||
merge_request: 19945
|
||||
author: Jan Beckmann
|
||||
type: fixed
|
|
@ -60,6 +60,36 @@ describe WebHookService do
|
|||
).once
|
||||
end
|
||||
|
||||
context 'when auth credentials are present' do
|
||||
let(:url) {'https://example.org'}
|
||||
let(:project_hook) { create(:project_hook, url: 'https://demo:demo@example.org/') }
|
||||
|
||||
it 'uses the credentials' do
|
||||
WebMock.stub_request(:post, url)
|
||||
|
||||
service_instance.execute
|
||||
|
||||
expect(WebMock).to have_requested(:post, url).with(
|
||||
headers: headers.merge('Authorization' => 'Basic ZGVtbzpkZW1v')
|
||||
).once
|
||||
end
|
||||
end
|
||||
|
||||
context 'when auth credentials are partial present' do
|
||||
let(:url) {'https://example.org'}
|
||||
let(:project_hook) { create(:project_hook, url: 'https://demo@example.org/') }
|
||||
|
||||
it 'uses the credentials anyways' do
|
||||
WebMock.stub_request(:post, url)
|
||||
|
||||
service_instance.execute
|
||||
|
||||
expect(WebMock).to have_requested(:post, url).with(
|
||||
headers: headers.merge('Authorization' => 'Basic ZGVtbzo=')
|
||||
).once
|
||||
end
|
||||
end
|
||||
|
||||
it 'catches exceptions' do
|
||||
WebMock.stub_request(:post, project_hook.url).to_raise(StandardError.new('Some error'))
|
||||
|
||||
|
|
Loading…
Reference in New Issue