summaryrefslogtreecommitdiff
path: root/spec/services/web_hook_service_spec.rb
diff options
context:
space:
mode:
authorGeorge Koltsov <gkoltsov@gitlab.com>2019-07-26 11:21:52 +0100
committerGeorge Koltsov <gkoltsov@gitlab.com>2019-08-02 15:39:18 +0100
commite5e1c907c01b53194f77e8d8de53554ba1824e7c (patch)
tree5f9602f3abf48056d4258a749cd9c756981d5abd /spec/services/web_hook_service_spec.rb
parenteb2d4adf38726da62f62e850d181cedf12c64c5e (diff)
downloadgitlab-ce-e5e1c907c01b53194f77e8d8de53554ba1824e7c.tar.gz
Add outbound requests setting for system hooks
This MR adds new application setting to network section `allow_local_requests_from_system_hooks`. Prior to this change system hooks were allowed to do local network requests by default and we are adding an ability for admins to control it.
Diffstat (limited to 'spec/services/web_hook_service_spec.rb')
-rw-r--r--spec/services/web_hook_service_spec.rb44
1 files changed, 36 insertions, 8 deletions
diff --git a/spec/services/web_hook_service_spec.rb b/spec/services/web_hook_service_spec.rb
index 37bafc0c002..8353fade5ea 100644
--- a/spec/services/web_hook_service_spec.rb
+++ b/spec/services/web_hook_service_spec.rb
@@ -19,15 +19,43 @@ describe WebHookService do
let(:service_instance) { described_class.new(project_hook, data, :push_hooks) }
describe '#initialize' do
- it 'allow_local_requests is true if hook is a SystemHook' do
- instance = described_class.new(build(:system_hook), data, :system_hook)
- expect(instance.request_options[:allow_local_requests]).to be_truthy
- end
+ 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)
+
+ expect(instance.request_options[:allow_local_requests]).to be_truthy
+ end
+ end
- it 'allow_local_requests is false if hook is not a SystemHook' do
- %i(project_hook service_hook web_hook_log).each do |hook|
- instance = described_class.new(build(hook), data, hook)
- expect(instance.request_options[:allow_local_requests]).to be_falsey
+ 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)
+
+ expect(instance.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)
+
+ expect(instance.request_options[:allow_local_requests]).to be_truthy
+ end
+ 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)
+
+ expect(instance.request_options[:allow_local_requests]).to be_falsey
+ end
+ end
end
end
end