diff options
author | George Koltsov <gkoltsov@gitlab.com> | 2019-07-30 11:53:23 +0100 |
---|---|---|
committer | George Koltsov <gkoltsov@gitlab.com> | 2019-08-02 15:39:18 +0100 |
commit | 8abf920d1f55e9117dd3b05d81ee9ebf7721f2bd (patch) | |
tree | bcdc229c8b9819f0ff6f5dc99095fe40bbeff51c /spec/validators | |
parent | ac7661924eebd6eb0fa72848e2b4bf4391ebf113 (diff) | |
download | gitlab-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.rb | 24 | ||||
-rw-r--r-- | spec/validators/system_hook_url_validator_spec.rb | 52 |
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 |