2018-06-01 07:43:53 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PublicUrlValidator do
|
2019-04-11 02:29:07 -04:00
|
|
|
include_examples 'url validator examples', AddressableUrlValidator::DEFAULT_OPTIONS[:schemes]
|
2018-06-01 07:43:53 -04:00
|
|
|
|
|
|
|
context 'by default' do
|
|
|
|
let(:validator) { described_class.new(attributes: [:link_url]) }
|
|
|
|
let!(:badge) { build(:badge, link_url: 'http://www.example.com') }
|
|
|
|
|
2019-04-11 02:29:07 -04:00
|
|
|
subject { validator.validate(badge) }
|
2018-06-01 07:43:53 -04:00
|
|
|
|
|
|
|
it 'blocks urls pointing to localhost' do
|
|
|
|
badge.link_url = 'https://127.0.0.1'
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
2019-04-11 02:29:07 -04:00
|
|
|
expect(badge.errors).to be_present
|
2018-06-01 07:43:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'blocks urls pointing to the local network' do
|
|
|
|
badge.link_url = 'https://192.168.1.1'
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
2019-04-11 02:29:07 -04:00
|
|
|
expect(badge.errors).to be_present
|
2018-06-01 07:43:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|