diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/models/hooks/web_hook_spec.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) | |
download | gitlab-ce-8c890596f5d0792c467fe12805ab1b39f93bf140.tar.gz |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/models/hooks/web_hook_spec.rb')
-rw-r--r-- | spec/models/hooks/web_hook_spec.rb | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb index 1761b537dc0..c68ad3bf0c4 100644 --- a/spec/models/hooks/web_hook_spec.rb +++ b/spec/models/hooks/web_hook_spec.rb @@ -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! @@ -267,6 +280,15 @@ RSpec.describe WebHook do end end + shared_examples 'is tolerant of invalid records' do + specify do + hook.url = nil + + expect(hook).to be_invalid + run_expectation + end + end + describe '#enable!' do it 'makes a hook executable if it was marked as failed' do hook.recent_failures = 1000 @@ -281,15 +303,17 @@ RSpec.describe WebHook do end it 'does not update hooks unless necessary' do - expect(hook).not_to receive(:update!) + sql_count = ActiveRecord::QueryRecorder.new { hook.enable! }.count - hook.enable! + expect(sql_count).to eq(0) end - it 'is idempotent on executable hooks' do - expect(hook).not_to receive(:update!) + include_examples 'is tolerant of invalid records' do + def run_expectation + hook.recent_failures = 1000 - expect { hook.enable! }.not_to change(hook, :executable?) + expect { hook.enable! }.to change(hook, :executable?).from(false).to(true) + end end end @@ -307,6 +331,12 @@ RSpec.describe WebHook do expect { hook.backoff! }.not_to change(hook, :backoff_count) end + + include_examples 'is tolerant of invalid records' do + def run_expectation + expect { hook.backoff! }.to change(hook, :backoff_count).by(1) + end + end end describe 'failed!' do @@ -314,11 +344,18 @@ RSpec.describe WebHook do expect { hook.failed! }.to change(hook, :recent_failures).by(1) end - it 'does not allow the failure count to exceed the maximum value' do + it 'does not update the hook if the the failure count exceeds the maximum value' do hook.recent_failures = described_class::MAX_FAILURES - expect(hook).not_to receive(:update!) - expect { hook.failed! }.not_to change(hook, :recent_failures) + sql_count = ActiveRecord::QueryRecorder.new { hook.failed! }.count + + expect(sql_count).to eq(0) + end + + include_examples 'is tolerant of invalid records' do + def run_expectation + expect { hook.failed! }.to change(hook, :recent_failures).by(1) + end end end @@ -326,5 +363,11 @@ RSpec.describe WebHook do it 'disables a hook' do expect { hook.disable! }.to change(hook, :executable?).from(true).to(false) end + + include_examples 'is tolerant of invalid records' do + def run_expectation + expect { hook.disable! }.to change(hook, :executable?).from(true).to(false) + end + end end end |