diff options
author | George Koltsov <gkoltsov@gitlab.com> | 2019-07-26 16:03:06 +0300 |
---|---|---|
committer | George Koltsov <gkoltsov@gitlab.com> | 2019-08-02 17:39:18 +0300 |
commit | ac7661924eebd6eb0fa72848e2b4bf4391ebf113 (patch) | |
tree | c38ea5f92cbd54f0c4d4d085ec68bd8347804d8e /spec/services | |
parent | 5a19a43a13031de83af2d241498465a882421270 (diff) |
Update security/webhooks.md doc page & specs
Updating security/webhooks.md to match new behaviour
as well as drying up few specs to extract shared
examples
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/web_hook_service_spec.rb | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/spec/services/web_hook_service_spec.rb b/spec/services/web_hook_service_spec.rb index 8353fade5ea..115599bd1a4 100644 --- a/spec/services/web_hook_service_spec.rb +++ b/spec/services/web_hook_service_spec.rb @@ -19,44 +19,36 @@ describe WebHookService do let(:service_instance) { described_class.new(project_hook, data, :push_hooks) } describe '#initialize' do - context 'when SystemHook' do - context 'when allow_local_requests_from_system_hooks application setting is true' do - it 'allows local requests' do - stub_application_setting(allow_local_requests_from_system_hooks: true) - instance = described_class.new(build(:system_hook), data, :system_hook) + before do + stub_application_setting(setting_name => setting) + end - expect(instance.request_options[:allow_local_requests]).to be_truthy - end + shared_examples_for 'respecting outbound network setting' do + context 'local requests are allowed' do + let(:setting) { true } + + it { expect(hook.request_options[:allow_local_requests]).to be_truthy } end - context 'when allow_local_requests_from_system_hooks application setting is false' do - it 'denies local requests' do - stub_application_setting(allow_local_requests_from_system_hooks: false) - instance = described_class.new(build(:system_hook), data, :system_hook) + context 'local requests are not allowed' do + let(:setting) { false } - expect(instance.request_options[:allow_local_requests]).to be_falsey - end + it { expect(hook.request_options[:allow_local_requests]).to be_falsey } end + end - context 'when ProjectHook' do - context 'when allow_local_requests_from_web_hooks_and_services application setting is true' do - it 'allows local requests' do - stub_application_setting(allow_local_requests_from_web_hooks_and_services: true) - instance = described_class.new(build(:project_hook), data, :project_hook) + context 'when SystemHook' do + let(:setting_name) { :allow_local_requests_from_system_hooks } + let(:hook) { described_class.new(build(:system_hook), data, :system_hook) } - expect(instance.request_options[:allow_local_requests]).to be_truthy - end - end + include_examples 'respecting outbound network setting' + end - context 'when allow_local_requests_from_system_hooks application setting is false' do - it 'denies local requests' do - stub_application_setting(allow_local_requests_from_web_hooks_and_services: false) - instance = described_class.new(build(:project_hook), data, :project_hook) + context 'when ProjectHook' do + let(:setting_name) { :allow_local_requests_from_web_hooks_and_services } + let(:hook) { described_class.new(build(:project_hook), data, :project_hook) } - expect(instance.request_options[:allow_local_requests]).to be_falsey - end - end - end + include_examples 'respecting outbound network setting' end end |