Commit b4abccf9 authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Nikola Milojevic

Add specs web hook url validations

parent 9ff18ecc
...@@ -16,6 +16,21 @@ RSpec.describe SystemHook do ...@@ -16,6 +16,21 @@ RSpec.describe SystemHook do
end end
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 describe "execute", :sidekiq_might_not_need_inline do
let(:system_hook) { create(:system_hook) } let(:system_hook) { create(:system_hook) }
let(:user) { create(:user) } let(:user) { create(:user) }
......
...@@ -32,6 +32,19 @@ RSpec.describe WebHook do ...@@ -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('ftp://example.com').for(:url) }
it { is_expected.not_to allow_value('herp-and-derp').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 it 'strips :url before saving it' do
hook.url = ' https://example.com ' hook.url = ' https://example.com '
hook.save! 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