Commit bc6ff6b3 authored by Nikola Milojevic's avatar Nikola Milojevic

Merge branch 'ld-improve-webhook-url-tests' into 'master'

Add validation specs for WebHook and SystemHook url for local requests

See merge request gitlab-org/gitlab!67199
parents ffe48ac4 b4abccf9
......@@ -16,6 +16,21 @@ RSpec.describe SystemHook do
end
end
describe 'validations' do
describe 'url' do
let(:url) { 'http://localhost:9000' }
it { is_expected.not_to allow_value(url).for(:url) }
it 'is valid if application settings allow local requests from system hooks' do
settings = ApplicationSetting.new(allow_local_requests_from_system_hooks: true)
allow(ApplicationSetting).to receive(:current).and_return(settings)
is_expected.to allow_value(url).for(:url)
end
end
end
describe "execute", :sidekiq_might_not_need_inline do
let(:system_hook) { create(:system_hook) }
let(:user) { create(:user) }
......
......@@ -32,6 +32,19 @@ RSpec.describe WebHook do
it { is_expected.not_to allow_value('ftp://example.com').for(:url) }
it { is_expected.not_to allow_value('herp-and-derp').for(:url) }
context 'when url is local' do
let(:url) { 'http://localhost:9000' }
it { is_expected.not_to allow_value(url).for(:url) }
it 'is valid if application settings allow local requests from web hooks' do
settings = ApplicationSetting.new(allow_local_requests_from_web_hooks_and_services: true)
allow(ApplicationSetting).to receive(:current).and_return(settings)
is_expected.to allow_value(url).for(:url)
end
end
it 'strips :url before saving it' do
hook.url = ' https://example.com '
hook.save!
......
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