diff options
author | George Koltsov <gkoltsov@gitlab.com> | 2019-07-26 12:23:38 +0100 |
---|---|---|
committer | George Koltsov <gkoltsov@gitlab.com> | 2019-08-02 15:39:18 +0100 |
commit | 7fe145b1b5854a0918d0c04e8f79d8aacd81561e (patch) | |
tree | f9df6d2d259172142234616c5107ea016d9995ff /spec/validators | |
parent | 6c42088fe2fb1970550d9b418dab785af26fcbf5 (diff) | |
download | gitlab-ce-7fe145b1b5854a0918d0c04e8f79d8aacd81561e.tar.gz |
Add SystemHookUrlValidator spec
Diffstat (limited to 'spec/validators')
-rw-r--r-- | spec/validators/system_hook_url_validator_spec.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/validators/system_hook_url_validator_spec.rb b/spec/validators/system_hook_url_validator_spec.rb new file mode 100644 index 00000000000..0862a67df9f --- /dev/null +++ b/spec/validators/system_hook_url_validator_spec.rb @@ -0,0 +1,51 @@ +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 '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 + + context 'when local requests are not allowed' do + let(:validator) { described_class.new(attributes: [:link_url], allow_localhost: false, allow_local_network: false) } + 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 +end |