Merge branch 'determinstic_dns_specs' into 'master'
Have deterministic DNS for specs See merge request gitlab-org/gitlab-ce!31086
This commit is contained in:
commit
534f8fc797
1
Gemfile
1
Gemfile
|
@ -388,7 +388,6 @@ group :test do
|
|||
gem 'json-schema', '~> 2.8.0'
|
||||
gem 'webmock', '~> 3.5.1'
|
||||
gem 'rails-controller-testing'
|
||||
gem 'sham_rack', '~> 1.3.6'
|
||||
gem 'concurrent-ruby', '~> 1.1'
|
||||
gem 'test-prof', '~> 0.2.5'
|
||||
gem 'rspec_junit_formatter'
|
||||
|
|
|
@ -884,8 +884,6 @@ GEM
|
|||
faraday (>= 0.7.6, < 1.0)
|
||||
settingslogic (2.0.9)
|
||||
sexp_processor (4.12.0)
|
||||
sham_rack (1.3.6)
|
||||
rack
|
||||
shoulda-matchers (4.0.1)
|
||||
activesupport (>= 4.2.0)
|
||||
sidekiq (5.2.7)
|
||||
|
@ -1232,7 +1230,6 @@ DEPENDENCIES
|
|||
selenium-webdriver (~> 3.141)
|
||||
sentry-raven (~> 2.9)
|
||||
settingslogic (~> 2.0.9)
|
||||
sham_rack (~> 1.3.6)
|
||||
shoulda-matchers (~> 4.0.1)
|
||||
sidekiq (~> 5.2.7)
|
||||
sidekiq-cron (~> 1.0)
|
||||
|
|
|
@ -82,7 +82,10 @@ module ContainerRegistry
|
|||
def redirect_response(location)
|
||||
return unless location
|
||||
|
||||
faraday_redirect.get(location)
|
||||
uri = URI(@base_uri).merge(location)
|
||||
raise ArgumentError, "Invalid scheme for #{location}" unless %w[http https].include?(uri.scheme)
|
||||
|
||||
faraday_redirect.get(uri)
|
||||
end
|
||||
|
||||
def faraday
|
||||
|
|
|
@ -112,11 +112,28 @@ describe ContainerRegistry::Blob do
|
|||
end
|
||||
end
|
||||
|
||||
context 'for a relative address' do
|
||||
before do
|
||||
stub_request(:get, 'http://registry.gitlab/relative')
|
||||
.with { |request| !request.headers.include?('Authorization') }
|
||||
.to_return(
|
||||
status: 200,
|
||||
headers: { 'Content-Type' => 'application/json' },
|
||||
body: '{"key":"value"}')
|
||||
end
|
||||
|
||||
let(:location) { '/relative' }
|
||||
|
||||
it 'returns correct data' do
|
||||
expect(blob.data).to eq '{"key":"value"}'
|
||||
end
|
||||
end
|
||||
|
||||
context 'for invalid file' do
|
||||
let(:location) { 'file:///etc/passwd' }
|
||||
|
||||
it 'raises an error' do
|
||||
expect { blob.data }.to raise_error(ArgumentError, 'invalid address')
|
||||
expect { blob.data }.to raise_error(ArgumentError, 'Invalid scheme for file:///etc/passwd')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::HTTPConnectionAdapter do
|
||||
include StubRequests
|
||||
|
||||
describe '#connection' do
|
||||
before do
|
||||
stub_all_dns('https://example.org', ip_address: '93.184.216.34')
|
||||
end
|
||||
|
||||
context 'when local requests are not allowed' do
|
||||
it 'sets up the connection' do
|
||||
uri = URI('https://example.org')
|
||||
|
|
|
@ -20,13 +20,8 @@ describe Projects::DownloadService do
|
|||
|
||||
context 'for URLs that are on the whitelist' do
|
||||
before do
|
||||
sham_rack_app = ShamRack.at('mycompany.fogbugz.com').stub
|
||||
sham_rack_app.register_resource('/rails_sample.jpg', File.read(Rails.root + 'spec/fixtures/rails_sample.jpg'), 'image/jpg')
|
||||
sham_rack_app.register_resource('/doc_sample.txt', File.read(Rails.root + 'spec/fixtures/doc_sample.txt'), 'text/plain')
|
||||
end
|
||||
|
||||
after do
|
||||
ShamRack.unmount_all
|
||||
stub_request(:get, 'http://mycompany.fogbugz.com/rails_sample.jpg').to_return(body: File.read(Rails.root + 'spec/fixtures/rails_sample.jpg'))
|
||||
stub_request(:get, 'http://mycompany.fogbugz.com/doc_sample.txt').to_return(body: File.read(Rails.root + 'spec/fixtures/doc_sample.txt'))
|
||||
end
|
||||
|
||||
context 'an image file' do
|
||||
|
|
|
@ -28,6 +28,19 @@ module StubRequests
|
|||
.and_return([addr])
|
||||
end
|
||||
|
||||
def stub_all_dns(url, ip_address:)
|
||||
url = URI(url)
|
||||
port = 80 # arbitarily chosen, does not matter as we are not going to connect
|
||||
socket = Socket.sockaddr_in(port, ip_address)
|
||||
addr = Addrinfo.new(socket)
|
||||
|
||||
# See Gitlab::UrlBlocker
|
||||
allow(Addrinfo).to receive(:getaddrinfo).and_call_original
|
||||
allow(Addrinfo).to receive(:getaddrinfo)
|
||||
.with(url.hostname, anything, nil, :STREAM)
|
||||
.and_return([addr])
|
||||
end
|
||||
|
||||
def stubbed_hostname(url, hostname: IP_ADDRESS_STUB)
|
||||
url = parse_url(url)
|
||||
url.hostname = hostname
|
||||
|
|
Loading…
Reference in New Issue