From 7fe145b1b5854a0918d0c04e8f79d8aacd81561e Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Fri, 26 Jul 2019 12:23:38 +0100 Subject: Add SystemHookUrlValidator spec --- spec/validators/system_hook_url_validator_spec.rb | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 spec/validators/system_hook_url_validator_spec.rb (limited to 'spec/validators') 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 -- cgit v1.2.3