diff options
author | George Koltsov <gkoltsov@gitlab.com> | 2019-07-30 13:53:23 +0300 |
---|---|---|
committer | George Koltsov <gkoltsov@gitlab.com> | 2019-08-02 17:39:18 +0300 |
commit | 8abf920d1f55e9117dd3b05d81ee9ebf7721f2bd (patch) | |
tree | bcdc229c8b9819f0ff6f5dc99095fe40bbeff51c /spec/validators/system_hook_url_validator_spec.rb | |
parent | ac7661924eebd6eb0fa72848e2b4bf4391ebf113 (diff) |
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/system_hook_url_validator_spec.rb')
-rw-r--r-- | spec/validators/system_hook_url_validator_spec.rb | 52 |
1 files changed, 1 insertions, 51 deletions
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 |