summaryrefslogtreecommitdiff
path: root/spec/validators
diff options
context:
space:
mode:
authorGeorge Koltsov <gkoltsov@gitlab.com>2019-07-30 11:53:23 +0100
committerGeorge Koltsov <gkoltsov@gitlab.com>2019-08-02 15:39:18 +0100
commit8abf920d1f55e9117dd3b05d81ee9ebf7721f2bd (patch)
treebcdc229c8b9819f0ff6f5dc99095fe40bbeff51c /spec/validators
parentac7661924eebd6eb0fa72848e2b4bf4391ebf113 (diff)
downloadgitlab-ce-8abf920d1f55e9117dd3b05d81ee9ebf7721f2bd.tar.gz
Refactor SystemHookUrlValidator and specs
Simplify SystemHookUrlValidator to inherit from PublicUrlValidator Refactor specs to move out shared examples to be used in both system hooks and public url validators.
Diffstat (limited to 'spec/validators')
-rw-r--r--spec/validators/public_url_validator_spec.rb24
-rw-r--r--spec/validators/system_hook_url_validator_spec.rb52
2 files changed, 2 insertions, 74 deletions
diff --git a/spec/validators/public_url_validator_spec.rb b/spec/validators/public_url_validator_spec.rb
index f6364fb1dd5..3cbf1002730 100644
--- a/spec/validators/public_url_validator_spec.rb
+++ b/spec/validators/public_url_validator_spec.rb
@@ -2,27 +2,5 @@ require 'spec_helper'
describe PublicUrlValidator do
include_examples 'url validator examples', AddressableUrlValidator::DEFAULT_OPTIONS[:schemes]
-
- context 'by default' do
- let(:validator) { described_class.new(attributes: [:link_url]) }
- let!(:badge) { build(:badge, link_url: 'http://www.example.com') }
-
- subject { validator.validate(badge) }
-
- it 'blocks urls pointing to localhost' do
- badge.link_url = 'https://127.0.0.1'
-
- subject
-
- expect(badge.errors).to be_present
- end
-
- it 'blocks urls pointing to the local network' do
- badge.link_url = 'https://192.168.1.1'
-
- subject
-
- expect(badge.errors).to be_present
- end
- end
+ include_examples 'public url validator examples', allow_local_requests_from_web_hooks_and_services: true
end
diff --git a/spec/validators/system_hook_url_validator_spec.rb b/spec/validators/system_hook_url_validator_spec.rb
index 78e95db2b47..02384bbd1ce 100644
--- a/spec/validators/system_hook_url_validator_spec.rb
+++ b/spec/validators/system_hook_url_validator_spec.rb
@@ -4,55 +4,5 @@ require 'spec_helper'
describe SystemHookUrlValidator do
include_examples 'url validator examples', AddressableUrlValidator::DEFAULT_OPTIONS[:schemes]
-
- context 'by default' do
- let(:validator) { described_class.new(attributes: [:link_url]) }
- let!(:badge) { build(:badge, link_url: 'http://www.example.com') }
-
- subject { validator.validate(badge) }
-
- it 'blocks urls pointing to localhost' do
- badge.link_url = 'https://127.0.0.1'
-
- subject
-
- expect(badge.errors).to be_present
- end
-
- it 'blocks urls pointing to the local network' do
- badge.link_url = 'https://192.168.1.1'
-
- subject
-
- expect(badge.errors).to be_present
- end
- end
-
- context 'when local requests are allowed' do
- let(:validator) { described_class.new(attributes: [:link_url]) }
- let!(:badge) { build(:badge, link_url: 'http://www.example.com') }
- let!(:settings) { create(:application_setting) }
-
- subject { validator.validate(badge) }
-
- before do
- stub_application_setting(allow_local_requests_from_system_hooks: true)
- end
-
- it 'does not block urls pointing to localhost' do
- badge.link_url = 'https://127.0.0.1'
-
- subject
-
- expect(badge.errors).not_to be_present
- end
-
- it 'does not block urls pointing to the local network' do
- badge.link_url = 'https://192.168.1.1'
-
- subject
-
- expect(badge.errors).not_to be_present
- end
- end
+ include_examples 'public url validator examples', allow_local_requests_from_system_hooks: true
end