未验证 提交 9c8f6e0c 编写于 作者: T Thong Kuah 提交者: Douglas Barbosa Alexandre

Stub DNS to return IPv4 address

Otherwise certain machines return IPv6 first, which is non-deterministic
上级 d6a7408f
......@@ -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')
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册