diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-13 16:26:31 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-13 16:26:31 +0300 |
commit | b7dfe2ae4054aa40e15182fd3c6cb7dd39f131db (patch) | |
tree | 5ab080ca9cadeb6cd9578bf301e4e9e8810bed9e /spec/lib/gitlab/url_blockers | |
parent | 25cb337cf12438169f1b14bc5dace8a06a7356e3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/url_blockers')
-rw-r--r-- | spec/lib/gitlab/url_blockers/url_whitelist_spec.rb | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/spec/lib/gitlab/url_blockers/url_whitelist_spec.rb b/spec/lib/gitlab/url_blockers/url_whitelist_spec.rb new file mode 100644 index 00000000000..906e0f0ba3d --- /dev/null +++ b/spec/lib/gitlab/url_blockers/url_whitelist_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::UrlBlockers::UrlWhitelist do + include StubRequests + + let(:whitelist) { [] } + + before do + allow(ApplicationSetting).to receive(:current).and_return(ApplicationSetting.new) + stub_application_setting(outbound_local_requests_whitelist: whitelist) + end + + describe '#domain_whitelisted?' do + let(:whitelist) do + [ + 'www.example.com', + 'example.com' + ] + end + + it 'returns true if domains present in whitelist' do + aggregate_failures do + whitelist.each do |domain| + expect(described_class).to be_domain_whitelisted(domain) + end + + ['subdomain.example.com', 'example.org'].each do |domain| + expect(described_class).not_to be_domain_whitelisted(domain) + end + end + end + + it 'returns false when domain is blank' do + expect(described_class).not_to be_domain_whitelisted(nil) + end + end + + describe '#ip_whitelisted?' do + let(:whitelist) do + [ + '0.0.0.0', + '127.0.0.1', + '192.168.1.1', + '0:0:0:0:0:ffff:192.168.1.2', + '::ffff:c0a8:102', + 'fc00:bf8b:e62c:abcd:abcd:aaaa:aaaa:aaaa', + '0:0:0:0:0:ffff:169.254.169.254', + '::ffff:a9fe:a9fe', + '::ffff:a9fe:a864', + 'fe80::c800:eff:fe74:8' + ] + end + + it 'returns true if ips present in whitelist' do + aggregate_failures do + whitelist.each do |ip_address| + expect(described_class).to be_ip_whitelisted(ip_address) + end + + ['172.16.2.2', '127.0.0.2', 'fe80::c800:eff:fe74:9'].each do |ip_address| + expect(described_class).not_to be_ip_whitelisted(ip_address) + end + end + end + + it 'returns false when ip is blank' do + expect(described_class).not_to be_ip_whitelisted(nil) + end + end +end |